Saturday, February 27, 2010

Good Blog Series On Using MSpec

Over on the Elegant Code blog there are some nice articles on MSpec which may be of interested to some of you. For those of you not familiar with MSpec, it’s a great open source BDD (Behaviour Driven Development) framework for .NET. Check it out.

Sunday, February 21, 2010

Time To Embrace The Cloud

You can’t help but notice the big increase in coverage for cloud computing both in IT news sites and developer blogs/forums. With the economic climate having been given a real beating the last couple of years, IT shops are looking into ways to reduce costs (hopefully by avoiding redundancies). Enter cloud computing. It’s a great idea and, frankly, one that is probably going to change the face of IT in the coming years.

As a developer, I accept that it’s only a matter of time before I will need to learn about developing for a cloud architecture. So rather then wait until that moment arrives, I’ve been doing a little bit of reading here and there about Windows Azure, Microsoft’s cloud offering which was made live a few weeks ago. I thought I’d post some links here to help out (both as notes for myself and to aid other people who might land on this blog).

Channel 9
Channel 9 - Cloud Cover Episode 1

PDC09 Videos
Lap Around The Windows Azure Platform
Development Best Practices and Patterns for Using Microsoft SQL Azure Databases
Scaling out Web Applications with Microsoft SQL Azure Databases
Patterns for Building Scalable and Reliable Applications with Windows Azure
Windows Azure Tables and Queues Deep Dive
Microsoft SQL Azure Database: Under the Hood
Windows Azure Present and Future
Windows Azure Blob and Drive Deep Dive
Windows Azure Monitoring, Logging, and Management APIs
Developing Advanced Applications with Windows Azure
Enabling Single Sign-On to Windows Azure Applications
Building Hybrid Cloud Applications with Windows Azure and the Service Bus
Lessons Learned: Migrating Applications to the Windows Azure Platform
Automating the Application Lifecycle with Windows Azure
The Future of Database Development with SQL Azure
Lessons Learned: Building On-Premises and Cloud Applications with the Service Bus and Windows Azure
Lessons Learned: Building Scalable Applications with the Windows Azure Platform
Lessons Learned: Building Multi-Tenant Applications with the Windows Azure Platform
Introduction to Building Applications with Windows Azure
SQL Azure Database: Present and Future
Tips and Tricks for Using Visual Studio 2010 to Build Applications that Run on Windows Azure
The Business of Windows Azure: What you should know about Windows Azure Platform pricing and SLAs

Misc
Windows Azure Tools for Microsoft Visual Studio 1.1 (February 2010)
Windows Azure Platform Training Kit - December Update
Migrating an Existing ASP.NET App to run on Windows Azure
Seven things that may surprise you about the Windows Azure Platform
OakLeaf Systems

Sunday, February 14, 2010

Nice BDD Naming Convention For MSTest

If you like to use Behaviour Driven Development (like me :) then I assume you are using a naming convention for your tests, maybe like this:

- Given an empty shopping cart
- When I add an item
- Then shopping item count should be 1

I really like using the above naming convention due to it expressiveness – I can instantly see what a test is actually testing and the context under which that test is running. I’ve been doing some research into the best practise for using BDD naming for MSTest unit tests and found this blog post. The author has given a very neat example of how to use a base context class which you can then include in your tests. The idea is that you have the following class which sets out the basic structure of a test:

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTest
{
    public abstract class ContextSpecification
    {
        public TestContext TestContext { get; set; }

        [TestInitialize]
        public void TestInitialize()
        {
            Context();
            BecauseOf();
        }

        [TestCleanup]
        public void TestCleanup()
        {
            Cleanup();
        }

        protected virtual void Context()
        {
        }

        protected virtual void BecauseOf()
        {
        }

        protected virtual void Cleanup()
        {
        }
    }
}

Those of you who have used frameworks such as MSpec will find the above very familiar (I’m a big fan of MSpec and use it for some of my projects at work, but none of my colleagues us it, hence my need for finding an MSTest way of BDD’ing my unit tests). You have the usual MSTest related code (TestContext, TestInitialize, etc) declared in this class, but notice the Context, BecauseOf and Cleanup methods. We’ll take a look at how those are used now. Check out the following unit test:

namespace UnitTest
{
    public static class GetPersonNameSpecs
    {
        public class GetPersonNameSpecsContext : ContextSpecification
        {
            protected Person sut;
            protected string actual = String.Empty;
        }

        [TestClass]
        public class when_name_has_not_been_given : GetPersonNameSpecsContext
        {
            protected override void Context()
            {
                sut = new Person();
            }

            protected override void BecauseOf()
            {
                actual = sut.GetFullName();
            }

            [TestMethod]
            public void returned_name_should_be_empty()
            {
                Assert.AreEqual(String.Empty, actual);
            }
        }

        [TestClass]
        public class when_name_has_been_given : GetPersonNameSpecsContext
        {
            protected override void Context()
            {
                sut = new Person("Jim");
            }

            protected override void BecauseOf()
            {
                actual = sut.GetFullName();
            }

            [TestMethod]
            public void returned_name_should_be_Jim()
            {
                Assert.AreEqual("Jim", actual);
            }
        }
    }
}

As per the suggestion of the blog author, I have a static class named GetPersonNameSpecs and inside that class is the real meat and bones – two test classes which contain the unit tests. See how I make use of the Context and BecauseOf methods - with Context I can do my pre-test initialisation (creating class instances, or if I was using a mock framework, creating mock objects), then in the BecauseOf method I invoke the code to be tested. The final phase of the test, the assertion, is what’s declared with a [TestMethod] attribute. Since in ContextSpecification both Context and BecauseOf are called during TestInitialize, there is no need for us to apply any attributes to our version of those methods.

The advantage of this structure is it’s readability, take a look at how the above tests look like in my test viewer window:

image

and in the results window:

image

Now, I don’t know about you, but I know that if I had to return to these tests in 6 months time, I will find it much easier to deal with.

Thursday, February 11, 2010

Fancy Having A Go at .NET 4.0 Exams?

Just spotted this page which has some details about upcoming .NET 4.0 beta exams. You can register for these exams, with the best part being that they're free to take. Here is a list of the available exams:
  • 70-511 TS: Microsoft .NET Framework 4, Windows Application Development
  • 70-513 TS: Microsoft .NET Framework 4, Windows Communication Foundation Development
  • 70-515 TS: Microsoft .NET Framework 4, Web Applications Development
  • 70-516 TS: Microsoft .NET Framework 4, Accessing Data with ADO.NET
  • 70-518 Pro: Designing and Developing Windows Applications Using Microsoft .NET 4
  • 70-519 Pro: Designing and Developing Web Applications Using Microsoft .NET Framework 4
As mentioned here, there is an absence of any workflow based exams. It’s thought that uptake of windows workflow foundation hasn’t been that great (I can count on one hand the number of workflows I’ve written) and, as a result, there are no planned workflow exams.

Tuesday, February 09, 2010

CLR via C#, 3rd Edition Out Now

I’m very happy to see that the newest edition of Jeffrey Richter's awesome book about the internals of the .NET CLR is now available. If you have read the 2nd edition then you will already know what a fantastic resource that book is for improving your understanding of how the CLR works. The new edition targets C# 4.0 and .NET 4.0, which is coming just around the corner. (In fact, the RC for VS2010 is out now for MSDN customers, and will be available to the public on Feb 10. Check out this Channel9 video for more details)