Specification for IsInstanceOfTypeFamily

Sorry for being late…

As I promised in my post IsInstanceOfTypeFamily – Check whether a given type is a member of a “type family” I now deliver a complete VisualStudio 2010 solution along with unit tests for the extension method. SinceI can never resist playing around with things, I used Machine.Specifications as well as Machine.Fakes to write specifications for the IsInstanceOfTypeFamily method. Along with these excellent tools I used FluentAssertions to express expectations in my tests. Together with TestDriven.NET I have an excellent testing infrastructure that can also measure code coverage (which is 100% except for the fallback mechanism that may not even be necessary, but I prefer defensive coding style, so it is there, but not hit…).

To provide a simple example, here is the specification that covers a null instance:

using System;
using System.Collections.Generic;
using Machine.Specifications;
using Machine.Fakes;
using FluentAssertions;

namespace MyCupOfDotnet.InstanceOfTypeFamily.Tests
{
    public class When_null_is_passed_as_instance : WithSubject<object>
    {
        private static Type typeFamily = typeof(List<>);
        private static bool result;

        Establish that = () => Subject = null;
        Because of = () => result = typeFamily.IsInstanceOfTypeFamily(Subject);
        It should_return_false = () => result.Should().BeFalse();
    }
}

Since the 3rd party libraries used add about 10 mb to the total solution I decided to not zip them with the download. I added a readme that describes which components you will need, you can all NuGet them. Have fun with it…

MyCupOfDotnet.IsInstanceOfTypeFamily VS2010 Solution

Leave a Reply

Your email address will not be published. Required fields are marked *