Permalink
Browse files

Merge pull request #774 from DarrellMozingo/userHostAddressTesting

Ability to set user host address when testing
  • Loading branch information...
2 parents 5de3a7c + f5871bf commit 77946edc652aeac6963d679b41e4ae65a1e314c1 @thecodejunkie thecodejunkie committed Oct 4, 2012
@@ -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"] ?? "";
@@ -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);
}
}
}
@@ -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; }
@@ -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; }
}
}

0 comments on commit 77946ed

Please sign in to comment.