Created
November 23, 2016 21:03
-
-
Save tpluscode/b94ddd859c3e929efa5a8a727cae2d6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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