Font Size: A A A   Layout: Left | Right

58bits - Tech

Six bits short of sixty four...

# Saturday, May 31, 2008
Saturday, May 31, 2008 6:31:49 PM (SE Asia Standard Time, UTC+07:00) (ASP.Net)

Visual Studio 2008 Professional shipped with the Visual Studio 2008 Team System unit test framework (which in Visual Studio 2005 was not available in the Professional version).

The test system is pretty cool - with excellent test code generating options and wizards. One really interesting feature is the ability to create tests for ASP.Net projects (file based, or application based). The tests created will be decorated as follows:

   1: /// <summary>
   2: ///A test for DemoTest
   3: ///</summary>
   4: [TestMethod()]
   5: [HostType("ASP.NET")]
   6: [UrlToTest("http://localhost/demo")]
   7: public void DemoTest()
   8: {
   9:     string input = "Boo";
  10:     string actual = "Boo1";
  11:     actual = input + "1";
  12:     Assert.AreEqual(input , actual);    
  13: }

 

Previously to the only way to test components in an ASP.Net application - especially one that depended on any custom configuration settings or configuration sections in the Web.config file - was to take a copy of all the required settings - and place them in an App.config file for your Unit Test project. Then using a test running framework like TestDriven.Net or NUnit - run the tests.

With the new Visual Studio 2008 test suite, you can simply use the Test Wizard to create the test, which will detect all the dependencies and create test methods that look like the one above. When run - the tests execute in the same processes as the referenced web application (and so use the same configuration settings).

If you want to debug your tests - you then have to attach the debugger to the either the development web server, or the IIS process that is hosting your local website.

Here's a link to an article that will show you how to do either - How to: Debug while Running a Test in an ASP.NET Solution.

However you have to re-attach the debugger to the process manually for every test run you want to debug, which is a drag. After googling for a while - I wasn't able to find an easy way to get F5 debugging that would automatically attach to the correct process (a command line option in the project maybe?). Still, the essence of the tests are to test assertions against your code and expected results so for a mature application test suite this isn't too big a problem. However for a TDD design approach - having to re-attach the debugger on each run is pretty inconvenient. Am I missing something?


Comments [0] | | #  
# Tuesday, May 27, 2008
Tuesday, May 27, 2008 2:31:26 PM (SE Asia Standard Time, UTC+07:00) (ASP.Net | Utilities)

Wow - Google and searchers were all over the "URI templates and hackable search engine friendly URLs" line in my short WPF post below, which means there's a lot of interest in URI templates.

I found this post on Creating a Template based URI very helpful. You DON'T have to be building a WCF service to use these. You MUST however include a reference to the System.ServiceModel.Web assembly in your project before you can use the System.UriTemplate type.

Scott Hanselman's presentation at MIX08 on MVC was also very helpful as well as it clarified many things (not to mention being hugely entertaining).

The URI Templates of .Net 3.5 don't have anything to do with REST - they're just a utility class that helps to bind and match templates and parameters to and from URIs. When combined with a URL rewriter they make it easy to present hackable URLs the world.  As Scott said in his presentation - the URLs in a browser window are effectively part of the UI - and so should be treated accordingly when possible.

So... mystore.com/clothing/shirts would be cool, as opposed to mystore.com/products.aspx?type=clothing&category=shirts


Comments [0] | | #  
# Saturday, May 24, 2008
Saturday, May 24, 2008 6:33:26 PM (SE Asia Standard Time, UTC+07:00) (Utilities)
While sprucing up my blog - I started looking for a code snippet plugin for Windows Live Writer - and Leo Vildosola's Code Snippet Plugin for WLW still appears to be a good choice. Like a lot of developers I use a 'dark theme' for Visual Studio and so I'm not sure that using the copy as HTML plugin from Colin Coller would work.
 

Here's an example of the WLW Code Snippet Plugin in action...

   1: /// <summary>
   2: /// Hash utility - pass the hash algorithm name as a string i.e. SHA256, SHA1, MD5 etc.
   3: /// </summary>
   4: /// <param name="input"></param>
   5: /// <param name="algorithm"></param>
   6: /// /// <param name="upperCase"></param>
   7: /// <returns>Hashed String</returns>
   8: public static string HashIt(string input, string algorithm, bool upperCase)
   9: {
  10:  
  11:     if (string.IsNullOrEmpty(input))
  12:         throw new ArgumentNullException("input");
  13:     
  14:     if(string.IsNullOrEmpty(algorithm))
  15:         throw new ArgumentNullException("algorithm");                        
  16:     
  17:     byte[] result = ((HashAlgorithm)CryptoConfig.CreateFromName(algorithm)).ComputeHash(Encoding.UTF8.GetBytes(input));
  18:  
  19:     StringBuilder myHexHash = new StringBuilder(64); //Maximum length required for SHA2-256, SHA1 or MD5
  20:  
  21:     string formatter = string.Empty;
  22:  
  23:     if (upperCase)
  24:         formatter = "{0:X2}";
  25:     else
  26:         formatter = "{0:x2}";
  27:  
  28:     for (int i = 0; i < result.Length; i++)
  29:     {
  30:         myHexHash.AppendFormat(formatter, result[i]);
  31:     }
  32:  
  33:     return myHexHash.ToString();
  34: }

Comments [0] | | #  
# Friday, May 23, 2008
Friday, May 23, 2008 7:40:07 PM (SE Asia Standard Time, UTC+07:00) (WPF)

Gallery.BuilderThere just aren't enough hours are there. Have just about managed to cobble together an improved looking skin for dasBlog. Will re-write my image gallery component soon with URI templates and hackable search engine friendly URLs.

The application I use to package up my images for delivery is called Gallery Builder (original) - and it's my WPF learning exercise. A hand-rolled set of control templates produced not a bad looking UI. Would love to write an effects control for generating the gallery cover image. Alas there may not be enough hours...    (click the image on the left to enlarge).


Comments [0] | | #  
# Tuesday, May 20, 2008
Tuesday, May 20, 2008 10:06:41 PM (SE Asia Standard Time, UTC+07:00) (General)

Well that's two out of four exams over with - and the end of the silent period on my blog. Successfully sat 'Information Security Management' and 'Introduction to Cryptography' over the past two days.

Both manageable papers, and the first two of six in what has turned out to be a really excellent programme. Check out the Information Security Group at RHUL for the gory details, or the syllabus posted at the London External Programme - MSc in Information Security.

Now that I have my life back... (at least for the summer), watch this space for a re-designed blog and new photo gallery over the coming weeks.


Comments [0] | | #  

Navigation

Search

Categories

On this page

Debugging Unit Tests in Visual Studio 2008 and ASP.Net
URI Templates and Hackable URLs
Code Snippet Plugin for Windows Live Writer
Enough Hours for WPF
Whew

Archive

Total Posts: 65
This Year: 39
This Month: 0
This Week: 0
Comments: 14

Sign In