mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-10 11:24:05 +02:00
Allow all headers to be set as Response headers (#142)
* Allow all headers to be set as Response headers * RunTestDifferentPort * Fix Proxy_Should_change_absolute_location_header_in_proxied_response test * Fix OwinResponseMapper * Fix test * 1.0.3.18
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|
||||||
@@ -8,6 +14,9 @@ namespace WireMock.Net.Console.Proxy.NETCoreApp2
|
|||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
RunTestDifferentPort().Wait(20000); // prints "1"
|
||||||
|
RunTestDifferentPort().Wait(20000); // prints "1"
|
||||||
|
|
||||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||||
{
|
{
|
||||||
Urls = new[] { "http://localhost:9091", "https://localhost:9443" },
|
Urls = new[] { "http://localhost:9091", "https://localhost:9443" },
|
||||||
@@ -32,5 +41,22 @@ namespace WireMock.Net.Console.Proxy.NETCoreApp2
|
|||||||
System.Console.ReadKey();
|
System.Console.ReadKey();
|
||||||
server.Stop();
|
server.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task RunTestDifferentPort()
|
||||||
|
{
|
||||||
|
var server = FluentMockServer.Start();
|
||||||
|
|
||||||
|
server.Given(Request.Create().WithPath("/").UsingGet())
|
||||||
|
.RespondWith(Response.Create().WithStatusCode(200).WithBody("Hello"));
|
||||||
|
|
||||||
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
|
var response = await new HttpClient().GetAsync(server.Urls[0]);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
System.Console.WriteLine("RunTestDifferentPort - server.LogEntries.Count() = " + server.LogEntries.Count());
|
||||||
|
|
||||||
|
server.Stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||||
<Version>1.0.3.17</Version>
|
<Version>1.0.3.18</Version>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
|||||||
@@ -94,8 +94,6 @@ namespace WireMock.Owin
|
|||||||
#endif
|
#endif
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
IsStarted = true;
|
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
StartServers();
|
StartServers();
|
||||||
|
|||||||
@@ -24,29 +24,41 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
|
// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
|
||||||
#if !NETSTANDARD
|
#if !NETSTANDARD
|
||||||
private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<IOwinResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<IOwinResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||||
#else
|
#else
|
||||||
private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<HttpResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<HttpResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||||
#endif
|
#endif
|
||||||
{ HttpKnownHeaderNames.Accept, null },
|
{ HttpKnownHeaderNames.ContentType, (r, v) => r.ContentType = v.FirstOrDefault() }
|
||||||
{ HttpKnownHeaderNames.Connection, null },
|
|
||||||
{ HttpKnownHeaderNames.ContentLength, null },
|
|
||||||
{ HttpKnownHeaderNames.ContentType, (r, v) => r.ContentType = v.FirstOrDefault() },
|
|
||||||
{ HttpKnownHeaderNames.Date, null },
|
|
||||||
{ HttpKnownHeaderNames.Expect, null },
|
|
||||||
{ HttpKnownHeaderNames.Host, null },
|
|
||||||
{ HttpKnownHeaderNames.IfModifiedSince, null },
|
|
||||||
{ HttpKnownHeaderNames.KeepAlive, null },
|
|
||||||
{ HttpKnownHeaderNames.Range, null },
|
|
||||||
{ HttpKnownHeaderNames.Referer, null },
|
|
||||||
{ HttpKnownHeaderNames.TransferEncoding, null },
|
|
||||||
{ HttpKnownHeaderNames.UserAgent, null },
|
|
||||||
{ HttpKnownHeaderNames.ProxyConnection, null },
|
|
||||||
{ HttpKnownHeaderNames.WWWAuthenticate, null }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void SetResponseHeaders(ResponseMessage responseMessage
|
||||||
|
#if !NETSTANDARD
|
||||||
|
, IOwinResponse response
|
||||||
|
#else
|
||||||
|
, HttpResponse response
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Set headers
|
||||||
|
foreach (var pair in responseMessage.Headers)
|
||||||
|
{
|
||||||
|
if (ResponseHeadersToFix.ContainsKey(pair.Key))
|
||||||
|
{
|
||||||
|
ResponseHeadersToFix[pair.Key]?.Invoke(response, pair.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if !NETSTANDARD
|
||||||
|
response.Headers.AppendValues(pair.Key, pair.Value.ToArray());
|
||||||
|
#else
|
||||||
|
response.Headers.Append(pair.Key, pair.Value.ToArray());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MapAsync ResponseMessage to OwinResponse
|
/// Map ResponseMessage to OwinResponse/HttpResponse
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="responseMessage"></param>
|
/// <param name="responseMessage"></param>
|
||||||
/// <param name="response"></param>
|
/// <param name="response"></param>
|
||||||
@@ -60,57 +72,31 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
response.StatusCode = responseMessage.StatusCode;
|
response.StatusCode = responseMessage.StatusCode;
|
||||||
|
|
||||||
// Set headers
|
byte[] bytes = null;
|
||||||
foreach (var pair in responseMessage.Headers)
|
|
||||||
{
|
|
||||||
if (RestrictedResponseHeaders.ContainsKey(pair.Key))
|
|
||||||
{
|
|
||||||
RestrictedResponseHeaders[pair.Key]?.Invoke(response, pair.Value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if !NETSTANDARD
|
|
||||||
response.Headers.AppendValues(pair.Key, pair.Value.ToArray());
|
|
||||||
#else
|
|
||||||
response.Headers.Append(pair.Key, pair.Value.ToArray());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null && responseMessage.BodyAsJson == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (responseMessage.BodyAsBytes != null)
|
if (responseMessage.BodyAsBytes != null)
|
||||||
{
|
{
|
||||||
await response.Body.WriteAsync(responseMessage.BodyAsBytes, 0, responseMessage.BodyAsBytes.Length);
|
bytes = responseMessage.BodyAsBytes;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if (responseMessage.BodyAsFile != null)
|
||||||
if (responseMessage.BodyAsFile != null)
|
|
||||||
{
|
{
|
||||||
byte[] bytes = File.ReadAllBytes(responseMessage.BodyAsFile);
|
bytes = File.ReadAllBytes(responseMessage.BodyAsFile);
|
||||||
|
|
||||||
await response.Body.WriteAsync(bytes, 0, bytes.Length);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
else if (responseMessage.BodyAsJson != null)
|
||||||
if (responseMessage.BodyAsJson != null)
|
|
||||||
{
|
{
|
||||||
Formatting formatting = responseMessage.BodyAsJsonIndented == true ? Formatting.Indented : Formatting.None;
|
Formatting formatting = responseMessage.BodyAsJsonIndented == true ? Formatting.Indented : Formatting.None;
|
||||||
string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
|
string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
|
||||||
using (var writer = new StreamWriter(response.Body, responseMessage.BodyEncoding ?? _utf8NoBom))
|
bytes = (responseMessage.BodyEncoding ?? _utf8NoBom).GetBytes(jsonBody);
|
||||||
{
|
}
|
||||||
await writer.WriteAsync(jsonBody);
|
else if (responseMessage.Body != null)
|
||||||
}
|
{
|
||||||
|
bytes = (responseMessage.BodyEncoding ?? _utf8NoBom).GetBytes(responseMessage.Body);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var writer = new StreamWriter(response.Body, responseMessage.BodyEncoding ?? _utf8NoBom))
|
SetResponseHeaders(responseMessage, response);
|
||||||
|
|
||||||
|
if (bytes != null)
|
||||||
{
|
{
|
||||||
await writer.WriteAsync(responseMessage.Body);
|
await response.Body.WriteAsync(bytes, 0, bytes.Length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,11 +195,13 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
throw new Exception($"Service start failed with error: {_httpServer.RunningException.Message}", _httpServer.RunningException);
|
throw new Exception($"Service start failed with error: {_httpServer.RunningException.Message}", _httpServer.RunningException);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Respect start timeout setting by throwing TimeoutException
|
// Respect start timeout setting by throwing TimeoutException
|
||||||
if (ctsStartTimeout.IsCancellationRequested)
|
if (ctsStartTimeout.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
throw new TimeoutException($"Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}");
|
throw new TimeoutException($"Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelay);
|
ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||||
<Version>1.0.3.17</Version>
|
<Version>1.0.3.18</Version>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
@@ -36,10 +36,6 @@
|
|||||||
<Compile Remove="Util\NamedReaderWriterLocker.cs" />
|
<Compile Remove="Util\NamedReaderWriterLocker.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<None Remove="Server\FluentMockServer.cs~RF44936b9f.TMP" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="11.1.0">
|
<PackageReference Include="JetBrains.Annotations" Version="11.1.0">
|
||||||
<PrivateAssets>All</PrivateAssets>
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using System.Net.Http;
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
@@ -190,29 +189,30 @@ namespace WireMock.Net.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task FluentMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response()
|
public async Task FluentMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response()
|
||||||
{
|
{
|
||||||
// given
|
// Assign
|
||||||
_serverForProxyForwarding = FluentMockServer.Start();
|
var settings = new FluentMockServerSettings { AllowPartialMapping = false };
|
||||||
|
_serverForProxyForwarding = FluentMockServer.Start(settings);
|
||||||
_serverForProxyForwarding
|
_serverForProxyForwarding
|
||||||
.Given(Request.Create().WithPath("/*"))
|
.Given(Request.Create().WithPath("/*"))
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithStatusCode(HttpStatusCode.Redirect)
|
.WithStatusCode(HttpStatusCode.Redirect)
|
||||||
.WithHeader("Location", _serverForProxyForwarding.Urls[0] + "testpath"));
|
.WithHeader("Location", _serverForProxyForwarding.Urls[0] + "testpath"));
|
||||||
|
|
||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start(settings);
|
||||||
_server
|
_server
|
||||||
.Given(Request.Create().WithPath("/*"))
|
.Given(Request.Create().WithPath("/prx"))
|
||||||
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0]));
|
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0]));
|
||||||
|
|
||||||
// when
|
// Act
|
||||||
var requestMessage = new HttpRequestMessage
|
var requestMessage = new HttpRequestMessage
|
||||||
{
|
{
|
||||||
Method = HttpMethod.Get,
|
Method = HttpMethod.Get,
|
||||||
RequestUri = new Uri(_server.Urls[0])
|
RequestUri = new Uri(_server.Urls[0] + "/prx")
|
||||||
};
|
};
|
||||||
var httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false };
|
var httpClientHandler = new HttpClientHandler { AllowAutoRedirect = false };
|
||||||
var response = await new HttpClient(httpClientHandler).SendAsync(requestMessage);
|
var response = await new HttpClient(httpClientHandler).SendAsync(requestMessage);
|
||||||
|
|
||||||
// then
|
// Assert
|
||||||
Check.That(response.Headers.Contains("Location")).IsTrue();
|
Check.That(response.Headers.Contains("Location")).IsTrue();
|
||||||
Check.That(response.Headers.GetValues("Location")).ContainsExactly(_server.Urls[0] + "testpath");
|
Check.That(response.Headers.GetValues("Location")).ContainsExactly(_server.Urls[0] + "testpath");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -351,8 +351,11 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(responseAsBytes).ContainsExactly(new byte[] { 48, 49 });
|
Check.That(responseAsBytes).ContainsExactly(new byte[] { 48, 49 });
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<object[]> ValidMatchersForHelloServerJsonMessage =>
|
[Fact]
|
||||||
new List<object[]>
|
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*"), "application/json" },
|
||||||
new object[] { new WildcardMatcher("*Hello server*"), "text/plain" },
|
new object[] { new WildcardMatcher("*Hello server*"), "text/plain" },
|
||||||
@@ -364,24 +367,25 @@ namespace WireMock.Net.Tests
|
|||||||
new object[] { new JsonPathMatcher("$..[?(@.message == 'Hello server')]"), "text/plain" }
|
new object[] { new JsonPathMatcher("$..[?(@.message == 'Hello server')]"), "text/plain" }
|
||||||
};
|
};
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[MemberData(nameof(ValidMatchersForHelloServerJsonMessage))]
|
|
||||||
public async Task FluentMockServer_Should_respond_to_valid_matchers_when_sent_json(IMatcher matcher, string contentType)
|
|
||||||
{
|
|
||||||
// Assign
|
|
||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
foreach (var item in validMatchersForHelloServerJsonMessage)
|
||||||
.Given(Request.Create().WithPath("/foo").WithBody(matcher))
|
{
|
||||||
.RespondWith(Response.Create().WithBody("Hello client"));
|
_server
|
||||||
|
.Given(Request.Create().WithPath("/foo").WithBody((IMatcher)item[0]))
|
||||||
|
.RespondWith(Response.Create().WithBody("Hello client"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var content = new StringContent(jsonRequestMessage, Encoding.UTF8, contentType);
|
var content = new StringContent(jsonRequestMessage, Encoding.UTF8, (string)item[1]);
|
||||||
var response = await new HttpClient().PostAsync("http://localhost:" + _server.Ports[0] + "/foo", content);
|
var response = await new HttpClient().PostAsync("http://localhost:" + _server.Ports[0] + "/foo", content);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
Check.That(responseString).Equals("Hello client");
|
Check.That(responseString).Equals("Hello client");
|
||||||
|
|
||||||
|
_server.ResetMappings();
|
||||||
|
_server.ResetLogEntries();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -581,24 +585,6 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(response).IsEqualTo("/fooBar");
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_server?.Stop();
|
_server?.Stop();
|
||||||
|
|||||||
@@ -9,18 +9,21 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
private const string ClientIp = "::1";
|
private const string ClientIp = "::1";
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public async void Response_Create_WithHeader_ContentLength()
|
[InlineData("Content-Length", "1024")]
|
||||||
|
[InlineData("Transfer-Encoding", "identity")]
|
||||||
|
[InlineData("Location", "http://test")]
|
||||||
|
public async void Response_Create_WithHeader(string headerName, string headerValue)
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var requestMock = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
|
var requestMock = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
|
||||||
IResponseBuilder builder = Response.Create().WithHeader("Content-Length", "1024");
|
IResponseBuilder builder = Response.Create().WithHeader(headerName, headerValue);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var response = await builder.ProvideResponseAsync(requestMock);
|
var response = await builder.ProvideResponseAsync(requestMock);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(response.Headers["Content-Length"].ToString()).Equals("1024");
|
Check.That(response.Headers[headerName].ToString()).Equals(headerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user