-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow all headers to be set as Response headers #142
Changes from all commits
0d59b57
da46d30
c82e037
446194e
a155f51
e4ff8a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,8 +94,6 @@ public Task StartAsync() | |
#endif | ||
.Build(); | ||
|
||
IsStarted = true; | ||
|
||
return Task.Run(() => | ||
{ | ||
StartServers(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
using System.Net.Http.Headers; | ||
using System.Threading.Tasks; | ||
using NFluent; | ||
using WireMock.Matchers.Request; | ||
using WireMock.RequestBuilders; | ||
using WireMock.ResponseBuilders; | ||
using WireMock.Server; | ||
|
@@ -190,29 +189,30 @@ public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxi | |
[Fact] | ||
public async Task FluentMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response() | ||
{ | ||
// given | ||
_serverForProxyForwarding = FluentMockServer.Start(); | ||
// Assign | ||
var settings = new FluentMockServerSettings { AllowPartialMapping = false }; | ||
_serverForProxyForwarding = FluentMockServer.Start(settings); | ||
_serverForProxyForwarding | ||
.Given(Request.Create().WithPath("/*")) | ||
.RespondWith(Response.Create() | ||
.WithStatusCode(HttpStatusCode.Redirect) | ||
.WithHeader("Location", _serverForProxyForwarding.Urls[0] + "testpath")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This creates a server that could redirect indefinitely I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it has to be like this, else test fails. |
||
|
||
_server = FluentMockServer.Start(); | ||
_server = FluentMockServer.Start(settings); | ||
_server | ||
.Given(Request.Create().WithPath("/*")) | ||
.Given(Request.Create().WithPath("/prx")) | ||
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0])); | ||
|
||
// when | ||
// Act | ||
var requestMessage = new HttpRequestMessage | ||
{ | ||
Method = HttpMethod.Get, | ||
RequestUri = new Uri(_server.Urls[0]) | ||
RequestUri = new Uri(_server.Urls[0] + "/prx") | ||
}; | ||
var httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false }; | ||
var response = await new HttpClient(httpClientHandler).SendAsync(requestMessage); | ||
|
||
// then | ||
// Assert | ||
Check.That(response.Headers.Contains("Location")).IsTrue(); | ||
Check.That(response.Headers.GetValues("Location")).ContainsExactly(_server.Urls[0] + "testpath"); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -351,8 +351,11 @@ public async Task FluentMockServer_Should_respond_to_request_bodyAsBytes() | |
Check.That(responseAsBytes).ContainsExactly(new byte[] { 48, 49 }); | ||
} | ||
|
||
public static IEnumerable<object[]> ValidMatchersForHelloServerJsonMessage => | ||
new List<object[]> | ||
[Fact] | ||
public async Task FluentMockServer_Should_respond_to_valid_matchers_when_sent_json() | ||
{ | ||
// Assign | ||
var validMatchersForHelloServerJsonMessage = new List<object[]> | ||
{ | ||
new object[] { new WildcardMatcher("*Hello server*"), "application/json" }, | ||
new object[] { new WildcardMatcher("*Hello server*"), "text/plain" }, | ||
|
@@ -364,24 +367,25 @@ public async Task FluentMockServer_Should_respond_to_request_bodyAsBytes() | |
new object[] { new JsonPathMatcher("$..[?(@.message == 'Hello server')]"), "text/plain" } | ||
}; | ||
|
||
[Theory] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason for not using the parameterised tests? The test cleanup at the end could also be done by making the class IDisposable if preferred. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For some reason the tests failed on my local machine, so I just fixed it this way. |
||
[MemberData(nameof(ValidMatchersForHelloServerJsonMessage))] | ||
public async Task FluentMockServer_Should_respond_to_valid_matchers_when_sent_json(IMatcher matcher, string contentType) | ||
{ | ||
// Assign | ||
_server = FluentMockServer.Start(); | ||
|
||
_server | ||
.Given(Request.Create().WithPath("/foo").WithBody(matcher)) | ||
.RespondWith(Response.Create().WithBody("Hello client")); | ||
foreach (var item in validMatchersForHelloServerJsonMessage) | ||
{ | ||
_server | ||
.Given(Request.Create().WithPath("/foo").WithBody((IMatcher)item[0])) | ||
.RespondWith(Response.Create().WithBody("Hello client")); | ||
|
||
// Act | ||
var content = new StringContent(jsonRequestMessage, Encoding.UTF8, contentType); | ||
var response = await new HttpClient().PostAsync("http://localhost:" + _server.Ports[0] + "/foo", content); | ||
// Act | ||
var content = new StringContent(jsonRequestMessage, Encoding.UTF8, (string)item[1]); | ||
var response = await new HttpClient().PostAsync("http://localhost:" + _server.Ports[0] + "/foo", content); | ||
|
||
// Assert | ||
var responseString = await response.Content.ReadAsStringAsync(); | ||
Check.That(responseString).Equals("Hello client"); | ||
// Assert | ||
var responseString = await response.Content.ReadAsStringAsync(); | ||
Check.That(responseString).Equals("Hello client"); | ||
|
||
_server.ResetMappings(); | ||
_server.ResetLogEntries(); | ||
} | ||
} | ||
|
||
[Fact] | ||
|
@@ -581,24 +585,6 @@ public async Task FluentMockServer_Should_respond_to_request_callback() | |
Check.That(response).IsEqualTo("/fooBar"); | ||
} | ||
|
||
[Fact] | ||
public async Task FluentMockServer_Should_IgnoreRestrictedHeader() | ||
{ | ||
// Assign | ||
_server = FluentMockServer.Start(); | ||
_server | ||
.Given(Request.Create().WithPath("/head").UsingHead()) | ||
.RespondWith(Response.Create().WithHeader("Content-Length", "1024")); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Head, "http://localhost:" + _server.Ports[0] + "/head"); | ||
|
||
// Act | ||
var response = await new HttpClient().SendAsync(request); | ||
|
||
// Assert | ||
Check.That(response.Content.Headers.GetValues("Content-Length")).ContainsExactly("0"); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_server?.Stop(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps names these 2 servers more specifically as it is quite hard to follow. _serverThatReturnsRedirects and serverThatProxies ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your comment, however for me it's clear for now. But I will think about this to see if I want to rename the these variables.