Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ability to set user host address when testing #774

Merged
merged 1 commit into from

2 participants

@DarrellMozingo

Added a UserHostAddress method to the BrowserContext for testing the Request.UserHostAddress property in an endpoint.

@thecodejunkie thecodejunkie merged commit 77946ed into NancyFx:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 4, 2012
  1. @DarrellMozingo
This page is out of date. Refresh to see the latest.
View
19 src/Nancy.Testing.Tests/BrowserFixture.cs
@@ -47,6 +47,23 @@ public void Should_be_able_to_send_string_in_body()
}
[Fact]
+ public void Should_be_able_to_set_user_host_address()
+ {
+ // Given
+ const string userHostAddress = "127.0.0.1";
+
+ // When
+ var result = browser.Get("/userHostAddress", with =>
+ {
+ with.HttpRequest();
+ with.UserHostAddress(userHostAddress);
+ });
+
+ // Then
+ result.Body.AsString().ShouldEqual(userHostAddress);
+ }
+
+ [Fact]
public void Should_be_able_to_send_stream_in_body()
{
// Given
@@ -340,6 +357,8 @@ public EchoModule()
Get["/nothing"] = ctx => string.Empty;
+ Get["/userHostAddress"] = ctx => Request.UserHostAddress;
+
Get["/session"] = ctx =>
{
var value = Session["moo"] ?? "";
View
2  src/Nancy.Testing/Browser.cs
@@ -202,7 +202,7 @@ private Request CreateRequest(string method, string path, Action<BrowserContext>
var requestStream =
RequestStream.FromStream(contextValues.Body, 0, true);
- return new Request(method, path, contextValues.Headers, requestStream, contextValues.Protocol, contextValues.QueryString);
+ return new Request(method, path, contextValues.Headers, requestStream, contextValues.Protocol, contextValues.QueryString, contextValues.UserHostAddress);
}
}
}
View
13 src/Nancy.Testing/BrowserContext.cs
@@ -39,6 +39,11 @@ public BrowserContext()
string IBrowserContextValues.QueryString { get; set; }
/// <summary>
+ /// Gets or sets the user host address
+ /// </summary>
+ string IBrowserContextValues.UserHostAddress { get; set; }
+
+ /// <summary>
/// Gets or sets the body string
/// </summary>
string IBrowserContextValues.BodyString { get; set; }
@@ -139,6 +144,14 @@ public void Query(string key, string value)
value);
}
+ /// <summary>
+ /// Sets the user host address.
+ /// </summary>
+ public void UserHostAddress(string userHostAddress)
+ {
+ this.Values.UserHostAddress = userHostAddress;
+ }
+
private IBrowserContextValues Values
{
get { return this; }
View
5 src/Nancy.Testing/IBrowserContextValues.cs
@@ -41,5 +41,10 @@ public interface IBrowserContextValues : IHideObjectMembers
/// Gets or sets the querystring
/// </summary>
string QueryString { get; set; }
+
+ /// <summary>
+ /// Gets or sets the user host address
+ /// </summary>
+ string UserHostAddress { get; set; }
}
}
Something went wrong with that request. Please try again.