tpluscode
11/23/2016 - 9:03 PM

Test.cs

public sealed class TestModule : NancyModule
{
    public TestModule()
    {
        After += ReturnNotFoundIfNull;

        Get("/", _ => Action());

        // worked with 1.x
        // Get["/"] = _ => Action();
    }

    private static dynamic Action()
    {
        return null;
    }

    private static void ReturnNotFoundIfNull(NancyContext context)
    {
        // with Nancy 2.0 that's not null
        // it's Response OK text/html instead
        if (context.NegotiationContext.DefaultModel == null)
        {
            context.Response = new NotFoundResponse();
        }
    }
}

public class Test
{
    [Fact]
    public async void Should_return_not_found()
    {
        // given
        var browser = new Browser(with => with.Module<TestModule>());

        // when
        var response = await browser.Get("/");

        // then
        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    }
}