an after shot of dispatcher

dispatcher has a fresh new face

The original design for dispatcher was lacking. It used a standard GitHub page theme and the page had been quickly written.

I wasn’t satisfied, so this weekend I changed the design and took the opportunity to use a CSS framework other than Bootstrap. After looking at 3 or 4 alternatives I ended up using Pure. It’s simpler and more basic than Bootstrap but for a static sites like dispatcher this proved beneficial.

Here are some before and after shots of the site:

BEFORE:

a before shot of dispatcher

AFTER:

after shot of dispatcher

an after shot of dispatcher

Go check it out!

New version of reek – 1.3.7

There’s a new version of reek (1.3.7), the code smell detector for Ruby available as of today.

The new version adds colors to the output and corrects a bug with the unused parameter smell and the uncommunicative parameter smell.

I’ve made some contributions to the project (including the output coloring) and it’s been a great experience. It’s a great gem and great project to contribute to.

Some interest for Dispatcher

This took me by surprise but Dispatcher one of my GitHub project has gone in the last 24 hours from being starred 0 times and forked 0 times to being starred 18 times and forked once.

This is surprising since I had not touched the project for weeks and the Dispatcher website has seen little traffic.

I really feel like getting back to working on Dispatcher now. I just have a to finish some work in progress I have on two other open-source projects and then I will get back to it.

Testing that an exception isn’t thrown in C#

In my previous post, Testing for exceptions in C#, I mentioned how to create an Assert Extension class to check that an exception is thrown, much like in NUnit.

You can also create a method to test that an exception isn’t thrown, be it a general or specific exception. NUnit includes such a method and in the interest of completion I will give an example.

Most of the time though, you should only be testing for the correct behavior or testing that a specific exception is being raised.

Almost every case where people are looking to test that a specific exception isn’t thrown can be changed and the changed tests will end up delivering better value.

With that out of the way, here is how you would implement it:

public static void DoesNotThrows<T>(Action expressionUnderTest, string exceptionMessage = "Expected exception was thrown by target of invocation.") where T : Exception
{
    try
    {
        expressionUnderTest();
    }
    catch (T)
    {
        Assert.Fail(exceptionMessage);
    }
    catch (Exception)
    {
        Assert.IsTrue(true);
    }

    Assert.IsTrue(true);
}

Here is how you would use it:

// Testing that no exception is being thrown
[TestMethod]
public void ExampleDoesNotThrows()
{
    int someInteger = 10;
    AssertExtension.DoesNotThrows<Exception>(() => someInteger.ToString());
}

// Testing that correct behavior will not throw an exception
[TestMethod]
public void ExampleDoesNotThrowsNoException()
{
    // Arrange
    var classUnderTest = new StringlyType();
    classUnderTest.Setup();
    int toStringlyfy = 1;

    // Act && Assert
    AssertExtension.DoesNotThrows<NullReferenceException>(() => classUnderTest.Stringlyfy(toStringlyfy));
}

// Testing that another exception than the one we expected isn't thrown
[TestMethod]
public void ExampleDoesNotThrowsWithSpecificType()
{
    // Arrange
    var classUnderTest = new StringlyType();
    int toStringlyfy = 1;

    // Act && Assert
    AssertExtension.DoesNotThrows<IndexOutOfRangeException>(() => classUnderTest.Stringlyfy(toStringlyfy));
}

You can refer to this previous post for more context on the test methods.

A DoesNotThrows method could be used to replace a test that does not have any asserts and whose only way of failing is through raising an exception.

In any case, when you are about to use a DoesNotThrows, stop and really think it through.