September 2008 - Posts

Further thoughts on mocking out a SMTP Server
Tue, Sep 30 2008 15:31

I posted on the problems I had had mocking out an SMTP server, well I have moved on a bit. As I said in the update note in the last post, I had given up on nDumbster and moved over to LumiSoft's freeware mail server.

The Lumisoft server is a far better starting point as it is a 'real' server that supports all the major mail protocols. As all the source (and binaries if you can't be bothered to build it yourself) are shipped it is easy to create a wrapper class for unit testing purposes that can do whatever you need.

However even with thi much improved server I still had a problem with System.Net.Mail calls. I had four tests

  • Send a single email with System.Web.Mail
  • Send a single email with System.Net.Mail
  • Send a batch of three emails with System.Web.Mail
  • Send a batch of three emails with System.Net.Mail

Before each test a new SMTP server was created, and when the test completed it was disposed of. Each test worked if run by itself.

The problem was that if the tests were run as a batch the final test failed. When the SMTP server was checked it was found to have no messages recorded, not the expected three. However, the logging said three messages had been sent OK. Swapping the order if the tests did not effect the basic issue that the second System.Net.Mail test reported no emails received, whilst the System.Web.Mail tests were fine.

By adding a unique identifier to each created SMTP server it could be seen that the fourth test was sending it mail to the second SMTP server (which should have been disposed of well before the fourth test was started) hence the final test failing.

The problem appears to be that the threading model inside System.Net.Mail holds the TcpClient object in memory for longer than you would expect, so somehow allows the fourth test to reuse the connection (and server) from the second test. Though it is unclear how you are able to have two servers both on port 25 at the same time. I guess this theory could also go some way to explaining the issues I had with the nDumbster implementation.

Though not perfect, the solution I used was to make the Smtp Server instance static for the test class so for all the tests I created just one instance. Before each test I cleared down the received messages store. This far his is working reliably for both single tests and batches of tests.

'Datadude' merged with Team Developer
Tue, Sep 30 2008 7:45

It was announced overnight by Microsoft that the Database Professional SKU for Visual Studio will be made available to all people who have a licensed copy of Team Developer.

This is great news as it addresses the problem of where to put the expensive copy of DataDude (which I think has been a barrier to it's uptake), in most companies there is not the clear distinction between code and DB devs.

So as of tomorrow you can get DataDude via MSDN. You can read more about the recent announcements here: http://msdn.microsoft.com/en-us/vstudio/products/cc948977.aspx

by But it works on my PC!
Filed under: ,
Mocking out an email server
Sat, Sep 27 2008 14:37

I am currently looking at automation of acceptance testing for workflows and a common task is to make sure an email has been sent. To do this in a TDD style I have been using the mock SMTP server nDumbster.

Now this was a port from Java in the the days of .NET 1.1 and does not seem to have had any development since. This can be seen because the following test using the .Net 1.1 System.Web.Mail call works beautifully, returning in a second or so

[TestMethod]
public void CanRecieveSingleWebMail()
{
System.Web.Mail.SmtpMail.SmtpServer = "localhost";
System.Web.Mail.SmtpMail.Send("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}

However the test using the .Net 2.0 System.Net.Mail is not so good

[TestMethod]
public void CanRecieveSingleNetMail()
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("localhost");
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage("somebody@foo.com", "everybody@bar.com", "This is the subject", "This is the body.");
client.Send(msg);
Assert.AreEqual(1, smtpServer.ReceivedEmail.Length);
}

It does work but takes 100 seconds to return, a bit of a pain for TDD!

After a bit of debugging I found the problem was the final input.ReadLine(); in HandleSmtpTranslation which we expect to get a null at the end of a message, for Systsem.Web.Mail this returns instantly, but for System.Net.Mail this takes 100 second, but then is fine.

As a work round I have put in the logic

string line = null;
if (smtpState != SmtpState.QUIT)
{
    line = input.ReadLine();
}
if (line == null)
{
    break;
}

This works fine for single mail messages, using both the old and new API.

There is still a problem, with the System.Web.Mail API you can send multiple emails in a test, but this still fails for System.Net.Mail – the first goes OK, but the second fails saying the server is not present.

By the way I have ruled anti virus and anything specific to port 25 causing the problem. I suspect a threading issue as I believe System.Web.Mail was single threaded wrapper for COM and System.Net.Mail is multi threaded pure .Net logic.

If I get a better solution I will post about it, but I have enough functionality for me at present.

First thoughts on the Dell Mini 9
Wed, Sep 24 2008 13:45

After Alt.net I had thought getting an ultra light notebook was a good idea. At most conference I need to browser, blog and read email; I don’t need to carry around a full development desktop replacement laptop.

Whilst at ReMix I had enough of the old battery in my Acer laptop, so just before it ran out of juice again I ordered a Dell Mini 9, which was actually cheaper than my HTC phone! Today it arrived, a lot sooner than I was expecting, Dell has said it would be next month.

Inspiron Mini 9

My first thoughts? Well the keyboard is small, typing is an interesting experience as I type this post. Also I would like a disk activity light; during the XP setup there a good period when I was not sure what was going on, a flickering led is always reassuring.

Other than these minor gripes it seem very good, it is light, the battery life seem as advertised and it is fast enough for Office 2007 (so I can use it for presentations) and messing around development (I popped on C#  Express but there is disk space left for VS2008 if I needed it).

I will report further when I have lived with it a while.

So what will we need to run 'Rosario'?
Tue, Sep 23 2008 15:10

Brian Harry has published an interesting post on the platform decisions for 'Rosario'.

The most interesting item is it will only support SQL 2008; so get planning a migration for that central enterprise SQL server!

by But it works on my PC!
Filed under:
Post ReMix thoughts
Sat, Sep 20 2008 9:34

So how was ReMix? well a bit like last year not earth shattering, but what can you expect. We have PDC in a month so there is going to be no major announcements, also this is a rerun event from the US MIX conference, again reducing the chances of anything new.

So if you are a developer and been to TechEd or just to local community events (and as Andy Westgarth said we are very lucky at the quality and number of community events and speakers in the UK) you will have heard nothing new about Silverlight etal. Though it is far to say that this may not be true for designers, and I felt the development track was pitched at this level.

It is with design where I think ReMix was different this year; there were noticeably more designers present and I thought the design track a lot stronger. As I had seen most of the developer track elsewhere I spent a good while in designer sessions, and as usual when going beyond your normal bounds it makes you think.

What has been bubbling in my mind is how does the design process fit into agile processes? Bill Buxton in his sessions (and new book) spoke about how it was important for the designer to provide a variety of concepts for the client/project and not invest all their effort in a single design, thus removing choice form the 'client' . It got me think should the same apply to the developers/architect? Is this even possible? At the grossest sense it would mean developers would propose (prototype?) versions of a product in PHP, Java, Flash ASP.NET, Silverlight etc. Now we all know this does not happen, early in a project a hopefully informed choice will made as to the technology to use (often this choice is made in the choice of who gets the business - a PHP house or a Microsoft house), and it is rare a change will be made in base technology once the choice is made. Even though a project is agile there are limits as to how major a change of direction could be,

So is this a difference between design and development, in web design we can ask the client how it should look, you still need to provide quality design with sane user interactions, but the client can have some choice e.g. 'I like  a more cartoon style', 'I want just like that but in red'. You are not going to get the same interaction from the bulk of clients for development and architecture, it is rare you hear 'Just like that but can you use SOAP'. Development constrains tend to be just that, things that must be done to meet a standard, not something open to choice at the non specialist level.

So ReMix was an interesting event, and good to see many friend from the community. And if it opened my mind to something new it must have been worth attending.

Rebuild of GUITester
Sat, Sep 20 2008 8:39

I have eventually got round to rebuilding my GUITester on Codeplex for VS2008. I must get round to looking to see if a similar declarative test markup system has any mileage for XAML. Something was talking about at Alt.net in the spring - how time flies.

Local user groups
Fri, Sep 19 2008 18:13

I have been asked a couple of times whist at the Alt.net and ReMix conferences about the local user groups around Leeds. Well these are the regular free community events I know about:

Black Marble community events - my company runs free community events at a hotel between Leeds and Bradford roughly monthly from autumn to spring. We invite a variety of leading .NET community speakers.

The Yorkshire Extreme Programming and Agile Methods Club (XPClub) - meets the 2nd Wednesday of the month in the centre of Leeds. This is a group of .NET and Java developers interested in agile development bast practice.

BCS West Yorkshire Branch - the local branch of the BCS meet either in the Leeds or York providing a wide range of IT related sessions (they also have links to the events run by the local Institution of Engineering and Technology branches)

Leeds branch of SQL Server User Group - the local branch of the national SQL User groups. As the name suggests is targeted at SQL users.

Geek Up - run monthly events cross the north of England targeted at web designers and web developers (I have not been to this group, but members of the XPClub have and say they enjoyed it)

Now there my be others that I don't know about, if you know of one please let me know.

Not speaking at Vbug next week
Fri, Sep 19 2008 17:13

I have just found out that the session I was doing at Vbug in Coventry next week has been cancelled due to low numbers. Sorry if you were planning to come, but don't worry I will be doing a similar sessions (the the bonus of post PDC Rosario updates) at the VBug conference in November.

Blend and Source control
Thu, Sep 18 2008 6:50

It is all well and good Microsoft saying that a developers and designer can share the same project WPF/Silverlight files in Visual Studio and Expression Blend, but whilst Blend does not have the ability to use a source control repository (TFS, SVN or anything else for that matter) and actually strips out  any source control binding it finds in a project file, this is for me unworkable experience. How has this product got to V2 without this feature?

For any company interested in a quality development process source control must be the most basic safety net, irrespective of how agile their methodology is.

I suppose there is one agile model where it could almost work and that is the designer and developer pair programing on the same PC with Blend and VS installed - but how realistic is that? and certainly does not scale beyond two people.

So as I am at Remix, I just asked Scott Guthrie when we would see source control in Blend - he said next version, some time next year, but on the plus side it should also include TFS work item integration. All good but we need it now, this is such a barrier to adoption of the Blend products.

Remix UK 08 Keynote
Thu, Sep 18 2008 6:27

Just seen the keynote for Remix in Brighton, I must say that Bill Buxton's part was one of the best keynotes I have seen (watch out for the streamed webcast). For me the most important thing for a keynote is to set the tone, the meme, for the conference and his session certainly did. OK it is good to see the demos of products but you can't beat a good bit of thought provoking public speaking. First time I have seen this done well by Microsoft since the last PDC a couple of years ago. Interestingly, setting the tone was something always done very well at the Sun JavaOne conferences I attended in the late 90s.

Bill's concept of strength through bring together excellent people with different skills, but with a common understanding and language, to make strong teams was also a common theme from Alt.net and the post bar drinks from last nights VBug meeting. If the whole team does not buy into a concept whether it be excellence in design or TDD then delivering high quality product is down to luck.

I think I will be doing to Bill's other sessions.

Not enough people locally for a TFS user group?
Tue, Sep 16 2008 12:07

Do you feel alone, nobody nearby who you can talk to about TFS? Well try the new virtual user group meeting in Second Life.

Only issue is the meeting will be 2am UK time by my reckoning.

Alt.net - the day after
Sun, Sep 14 2008 10:16

Back home now after a excellent two days at Alt.Net in London. As with the spring conference this was a thought provoking event. I really like the whole open space format, though there were four 'main sessions' the event started the night before in the planning session and the bar and carried on without a pause, including the train trip home.

The main sessions can be excellent; but it is usually the chat walking to get a coffee or over lunch was where you get a nugget of information that completes a picture for you. It is great to find out you are not alone in the problems you have and refreshing to hear people speak so openly over the challenges and successes they have had.

The main take away for me were ideas on acceptance testing:

  • The gathering of the tests can be improved by using a three pronged attack using the client (or Business Analyst), the developers and the tester/QA team. It is three pronged as each group has their own view of what the product should do. The client want tests that prove a product meets a business need, the developer will test some edge cases around the business tests and the tester will add tests that just try to break the product. Together this group should provide a reasonable test coverage, not perfect but better than the view of any single group.
  • I also got a number of ideas on techniques for writing the acceptance tests. The most immediately interesting was the idea of using log files via a product such as TestTest. My first thought is that this provides an interesting way to tackle automated testing of Sharepoint Workflows - a current issue for me.

At the event I mention that we at Black Marble were considering hosting a similar event, but I had been worried that there would not be the interest as I perceived the attendees of the London event were fairly London based. I am pleased to say that this does not seem to be the case. And true to the principles of an open spaces event we have to recognise that 'whoever comes are the right people'. Keep an eye of for announcements of an event in the new year.

So thanks again to Ian Cooper, Alan Dean and Ben Hall for organising the event, I look forward to the next one.

Technorati Tags:

altdotnet

Signing Powershell scripts with a Thawte code signing certificate
Wed, Sep 10 2008 17:19

I hit a problem today when trying to sign a powershell script as detailed on Scott Hanselman's blog with a Thawte code signing certificate.

The basic issue was that the certificate could be seen in the Personal section of the Certificates MMC snap-in. Also it was listed if I issued the Powershell command

Get-ChildItem cert:\CurrentUser\My

but if I added the flag to only show usable codesigning (Class III) certificates it was not listed.

Get-ChildItem cert:\CurrentUser\My -codesigning

Turns out the issue was the same as you see when trying to sign Office 2000 VBA scripts. You have to have imported the certificate with it's key as detailed on the Thawte site, using the PVKIMPRT.EXE tool. This means you need the MYCERT.P7B and the MYKEY.PVK for the import.

This is made a bit more complex if using the Thawte web site and a Vista client PC as your purchased certificate is installed into you local registry automatically (you don't get a separate key file). So it would work on the PC used to purchase the certificate but you could not export it. Hence the tip here is to purchase the certificate on an XP client PC so you get both the certificate and key files; Ok you have to manually install the certificate and the key but is is easier in the long term.

Once this is done you can sign the powershell script using the command

Set-AuthenticodeSignature file.ps1 @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0]

September XPClub Meeting is this Wednesday
Sun, Sep 7 2008 10:49

The next XPClub meeting is a double bill: Code Quality and Scala + Lift. and is being held at the usual venue the Victoria Hotel Leeds. This is a free event open to all.

As usual drinks and snacks thanks to the club sponsors are free, also there will be a draw for one free personal license for any of the products by JetBrains - the new club sponsor.

Upgrading Team Foundation Server 2008 with SP1
Sat, Sep 6 2008 12:58

Today I got round to upgrading our TFS 2008 (dual server setup) with Team Server 2008 SP1. I tried it first on my demo VPC I use for presentations (reminder I am at VBug Coventry at the end of the talking about TFS, a free event open to all). Anyway, this update went fine and did not take too long, 5 or 10 minutes.

On the main system all seemed to go OK, but it did take around 45 minutes. I assumed the time it takes is dependant on volume of data in the DB, some sort of schema update I guess.

All seemed to go OK, I got no errors and after the upgrade I am able to manage work items, check in and out etc. However, there is one problem, in Team Explorer (I was on the server console) I saw a red cross next to the Reports sections in all team projects.

The interesting part was that if I copied the URL from the properties window for the Reports and pasted it into a browser it works without error and without being prompted for any login details. So I assumed that there is no issue with the Reporting services or authentication (also the links in Team Explorer had worked prior to the update). As another check,  we use eScrum process template  and it's associated web site could accessing the Reporting services without any errors. It all pointed to a problem inside the Team System client.

When I tried to create a new team project there was also a problem. It failed with the error:

TF30224: Failed to retrieve projects from the report server.

I google'd around a bit to no real effect, all the people who had seen this error before turned out to have rights issues in Reporting Services, mine were fine.

I then had a thought, I had not upgraded the VS2008 Team Explorer on the server (the Team Server SP1 update does not include this). I therefore ran the VS2008 SP1 update, rebooted the server and low and behold the error went away.

So the technical tip is - if you put TFS 2008 SP1 on a server make sure you also updated the Team Explorer clients to SP1. If you don't you will probably be OK doing day to days source control and work item editing, but expect problems creating new projects.

Controlling a Ajax Control ModalPopupExtender from Code behind
Tue, Sep 2 2008 5:21

I have had a nightmare getting this going.

Adding the ModalPopupExtender to a form is easy, you drop it on and tell it the two required controls parameters

  • PopupControlID="MyModalPanel"
  • TargetControlID="ButtonToLoadIt"

And it just works fine, but is triggered by a client side click of the Target Control.

If you want to do some server side code behind first you are meant to set the

  • TargetControlID to a fake control that is visible on form e.g. "FakeButtonToLoadIt" IT IS VITAL THIS CONTROL IS VISIBLE AND HENCE RENDERED, but the control  can be effectively hidden via CSS styling with something like Style="display: none"
  • In the code behind after your own processing you are just meant to call this.MPE.Show(); where MPE is the ID of your extender

Well this did not work for me. If I clicked my fake control (when it was not hidden obviously) it all worked by the server side call just displayed my panel where it was in the underlying HTML flow - the extension never kicked in.

After too many hours of fiddling and reading posts I found the answer. IT IS ALSO VITAL that the whole set of panel, extension and all associated controls are inside an UpdatePanel. If any are not it just does not work - this appears not to have been the case in older versions of the Ajax control toolkit and hence web sites give incorrect instructions.

So it should look something like

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register TagPrefix="cc2" TagName="AddressList" Src="~/SelectAddressControl.ascx" %>

<!-- This update panel is vital else the codebehind cannot show the modal dialog -->
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     <asp:Label ID="LabelPostcode" runat="server" Text="Postcode" AssociatedControlID="Postcode"></asp:Label>
     <asp:TextBox ID="Postcode" runat="server" MaxLength="9"></asp:TextBox>

    <!-- The button  with the code behind -->
    <asp:Button ID="FindAddressButton" runat="server" Text="Find Address" CausesValidation="false" OnClick="FindAddress_Click" />
     

   <!-- The modal panel -->
   <asp:Panel ID="ModalPanel" runat="server" CssClass="modalPopup" >
        <!-- Inside we have a user control -->
        <cc2:AddressList ID="AddressList" runat="server" />
   </asp:Panel>

         
  <!-- We have to have a dummy control to hold the start event we handle in code behind -->
            <asp:Button ID="MpeFakeTarget" runat="server" CausesValidation="False" Style="display: none" />

            <!-- We have to use the long name for the cancel button as we have a user control-->
            <cc1:ModalPopupExtender ID="MPE" runat="server" TargetControlID="MpeFakeTarget"
                PopupControlID="ModalPanel" DropShadow="true" CancelControlID="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$AddressList$CancelButton"
                BackgroundCssClass="modalBackground"  />
        </ContentTemplate>
    </asp:UpdatePanel>