Guest User

Untitled

a guest
Dec 12th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. public class ContentNegotiationFixture
  2. {
  3. private readonly INancyBootstrapper bootstrapper;
  4. private readonly Browser browser;
  5.  
  6. public ContentNegotiationFixture()
  7. {
  8. var module = new ConfigurableNancyModule(with =>{
  9. with.Get("/int", x => 200);
  10. with.Get("/string", x => "hello");
  11. with.Get("/httpstatuscode", x => HttpStatusCode.Accepted);
  12.  
  13. with.Get("/action", x => {
  14. Action<Stream> result = stream =>{
  15. var wrapper = new UnclosableStreamWrapper(stream);
  16. using (var writer = new StreamWriter(wrapper))
  17. {
  18. writer.Write("Hiya Nancy!");
  19. }
  20. };
  21.  
  22. return result;
  23. });
  24. });
  25.  
  26. this.bootstrapper = new ConfigurableBootstrapper(with => {
  27. with.Module(module);
  28. });
  29.  
  30. this.browser = new Browser(this.bootstrapper);
  31. }
  32.  
  33. [Fact]
  34. public void Should_return_int_value_from_get_route_as_response_with_status_code_set_to_value()
  35. {
  36. // Given
  37. // When
  38. var response = this.browser.Get("/int");
  39.  
  40. // Then
  41. Assert.Equal((HttpStatusCode)200, response.StatusCode);
  42. }
  43.  
  44. [Fact]
  45. public void Should_return_string_value_from_get_route_as_response_with_content_set_as_value()
  46. {
  47. // Given
  48. // When
  49. var response = this.browser.Get("/string");
  50.  
  51. // Then
  52. Assert.Equal("hello", response.Body.AsString());
  53. }
  54.  
  55. [Fact]
  56. public void Should_return_httpstatuscode_value_from_get_route_as_response_with_content_set_as_value()
  57. {
  58. // Given
  59. // When
  60. var response = this.browser.Get("/httpstatuscode");
  61.  
  62. // Then
  63. Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
  64. }
  65.  
  66. [Fact]
  67. public void Should_return_action_value_as_response_with_content_set_as_value()
  68. {
  69. // Given
  70. // When
  71. var response = this.browser.Get("/action");
  72.  
  73. // Then
  74. Assert.Equal("Hiya Nancy!", response.Body.AsString());
  75. }
  76. }
Add Comment
Please, Sign In to add comment