Last active
          August 29, 2015 14:04 
        
      - 
      
- 
        Save thecodejunkie/204297b492e1ab5b3e2f to your computer and use it in GitHub Desktop. 
    Different ways of passing in querystring parameters using the Browser class
  
        
  
    
      This file contains hidden or 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 class TestFixture | |
| { | |
| private readonly Browser browser; | |
| public TestFixture() | |
| { | |
| this.browser = new Browser(with => with.Module<QueryStringTestModule>()); | |
| } | |
| [Fact] | |
| public void Should_return_querystring_parameter_when_explicitly_declared() | |
| { | |
| // Given | |
| // When | |
| var result = this.browser.Get("/", with => | |
| { | |
| with.Query("foo", "bar"); | |
| }); | |
| // Then | |
| Assert.Equal("bar", result.Body.AsString()); | |
| } | |
| public void Should_return_querystring_parameter_when_passed_in_url() | |
| { | |
| // Given | |
| var url = new Url("http://localhost/?foo=bar2"); | |
| // When | |
| var result = this.browser.Get(url); | |
| // Then | |
| Assert.Equal("bar2", result.Body.AsString()); | |
| } | |
| public void Should_return_querystring_parameter_when_passed_in_with_path() | |
| { | |
| // Given | |
| var url = new Url("/?foo=bar3"); | |
| // When | |
| var result = this.browser.Get(url); | |
| // Then | |
| Assert.Equal("bar3", result.Body.AsString()); | |
| } | |
| public class QueryStringTestModule : NancyModule | |
| { | |
| public QueryStringTestModule() | |
| { | |
| Get["/"] = parameters => { | |
| return this.Request.Query.foo; | |
| }; | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment