TwitterFacebookGoogle

Integrating TypeMock with ASP .NET Unit tests

When it comes to writing unit tests for your ASP .NET pages, there isn’t much help out there. I experimented with a few open source testing tools and found some major limitations.

Both NUnitAsp and WaitN, for instance, are “client-side” tools. In other words, you have to write your tests against the actual HTML output. For example, to get the value of a textbox, you have to specify the actual HTML id of the textbox. That’s painful! Especially, since ASP .NET ends up assigning long and complicated ID’s to your controls. Plus NUnitAsp is no longer being maintained or supported.

Unlike NUnitAsp and WaitN, VS Studio ASP .NET Unit testing let’s you examine the actual HttpRequest object. What this means is that you can call methods on your Page and get access to the controls within the page. VS Studio ASP .NET is a pretty decent tool and maybe the answer for you. IF you don’t need to use TypeMock that is. But if you do, then tough luck because VS Studio ASP .NET unit tests don’t work with TypeMock. If you give it try, you’ll get the following exception:

Test method AzAsh.WebApp.Tests.DefaultTest.LoginNotRequiredTest threw exception:  TypeMock.TypeMockException: 
*** Typemock Isolator is not currently enabled. 
To enable do one of the following:

* To run Typemock Isolator as part of an automated process you can:
   - run tests via TMockRunner.exe command line tool
   - use 'TypeMockStart' tasks for MSBuild or NAnt

* To work with Typemock Isolator inside Visual Studio.NET:
        set Tools->Enable Typemock Isolator from within Visual Studio

For more information consult the documentation (see 'Running' topic).

Check the enable property as they have suggested and you’ll notice that Typemock is enabled! So, what gives? I have no idea. But I do know that Ivonna – a ASP .NET testing tool that is being developed in partnership with TypeMock WILL let you work in conjunction with TypeMock. Like VS Studio, it allows you to examine the intrinsic objects, such as the Page object. In addition, it’s got another neat feature that let’s you inject setup code and assertions into your page’s lifecycle event handlers – very handy especially during type mocking. The only drawback is that it’s a little slow. The unit tests take a while to run.

So if you’ve been scratching your head trying to figure how to develop ASP .NET tests that can work with TypeMock, Ivonna is probably the tool you’ve been waiting for!

Twitter Email Linkedin Digg Stumbleupon Subscribe

LINQ : Implementing IN and NOT IN

I got tried of typing

  var result = from s in source
                  where items.Contains(s)
                  select s;

and so I implemented the IN and NOT IN methods as extension methods:

public static IQueryable<T> In<T>(this IQueryable<T> source, 
                            IQueryable<T> checkAgainst)
{
   return from s in source 
            where checkAgainst.Contains(s) 
            select s;
}
 
public static IQueryable<T> NotIn<T>(this IQueryable<T> source, 
                                  IQueryable<T> checkAgainst)
{
   return from s in source 
            where !checkAgainst.Contains(s) 
            select s;
}

Thus, I can now just do the following:

  var result = source.In(items);

What do you think – Good idea, Bad idea, Useless idea?

Twitter Email Linkedin Digg Stumbleupon Subscribe

Update Panels dont play well with Validators in Chrome

If your page uses ASP .NET custom validators and an UpdatePanel, you will notice that your UpdatePanels will not work in Chrome. In order to fix this, you will have disable client script on the custom validators by setting EnableClientScript=false.

Hopefully this tip will save others the headache that I went through!

Happy Coding!

Twitter Email Linkedin Digg Stumbleupon Subscribe
CyberChimps