Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodejunkie/204297b492e1ab5b3e2f to your computer and use it in GitHub Desktop.
Save thecodejunkie/204297b492e1ab5b3e2f to your computer and use it in GitHub Desktop.
Different ways of passing in querystring parameters using the Browser class
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