You like good looking code right? Who doesn't!
This bit of code I picked up from the excellent book: Pro ASP.Net MVC2.
When you're unit testing, you might do something like this:
Let's create a little helper method that makes our code a little bit sexier (lord knows I like sexy code):
BEHOLD! GENERICS!
Now, let's spruce up our old unit test. ;)
Now is that nice or what! :)
Added bonus, Visual Studio's intellisense is fully helping you out while coding.

Enjoy!
This bit of code I picked up from the excellent book: Pro ASP.Net MVC2.
When you're unit testing, you might do something like this:
using NUnit.Framework
[Test]
public void Product_Catalog_Should_List_All_Products()
{
var viewModelResult = productsController.List();
var productCount = viewModelResult.Products.Count;
Assert.AreEqual(3, productCount);
}
Let's create a little helper method that makes our code a little bit sexier (lord knows I like sexy code):
public static class UnitTestHelpers
{
public static void ShouldEqual<T>(this T actualValue, T expectedValue)
{
Assert.AreEqual(expectedValue, actualValue);
}
}
BEHOLD! GENERICS!
Now, let's spruce up our old unit test. ;)
using NUnit.Framework
[Test]
public void Product_Catalog_Should_List_All_Products()
{
var viewModelResult = productsController.List();
var productCount = viewModelResult.Products.Count;
productsCount.ShouldEqual(3);
}
Now is that nice or what! :)
Added bonus, Visual Studio's intellisense is fully helping you out while coding.

Enjoy!
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
1 user(s) viewing
1 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
About Me

Bienvenidos! I'm a USA ex-pat living in Bolivia for the past 10 years. Web development is my forte with a heavy lean for usability and optimization. I'm fluent in both English and Spanish. I guest write for the popular Python website Python Central. Visit my website.
My Blog Links
Recent Entries
-
-
-
-
How to create a signature form for iPad and mobile devices using HTML5 and Canvas.
on Nov 27 2012 08:15 AM
-
Recent Comments
-
laytonsdad
on Apr 30 2013 11:30 AM
Dream.In.Code Badge Generator! Share your flair on your site or blog.
-
-
Jstall
on Nov 04 2012 09:18 AM
The Pragmatic Bookshelf mega blowout sale - 40% off select Ruby on Rails books.
-
-
tylrwb
on Jun 26 2012 07:34 PM
C# and MVC3 - Uploading and parsing an Excel document is easier than it seems.
Categories
|
|



Leave Comment








|