Skip to content

Instantly share code, notes, and snippets.

@tpluscode
Created November 23, 2016 21:03
Show Gist options
  • Save tpluscode/b94ddd859c3e929efa5a8a727cae2d6e to your computer and use it in GitHub Desktop.
Save tpluscode/b94ddd859c3e929efa5a8a727cae2d6e to your computer and use it in GitHub Desktop.
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment