mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-25 02:41:53 +01:00
Allow setting Content-Length header on the response (#1158)
* Allow setting Content-Length header on the response * fix?
This commit is contained in:
@@ -25,278 +25,277 @@ using Response = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Net.Tests.Owin.Mappers
|
||||
namespace WireMock.Net.Tests.Owin.Mappers;
|
||||
|
||||
public class OwinResponseMapperTests
|
||||
{
|
||||
public class OwinResponseMapperTests
|
||||
private static readonly Task CompletedTask = Task.FromResult(true);
|
||||
private readonly OwinResponseMapper _sut;
|
||||
private readonly Mock<IResponse> _responseMock;
|
||||
private readonly Mock<Stream> _stream;
|
||||
private readonly Mock<IHeaderDictionary> _headers;
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
||||
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
||||
|
||||
public OwinResponseMapperTests()
|
||||
{
|
||||
private static readonly Task CompletedTask = Task.FromResult(true);
|
||||
private readonly OwinResponseMapper _sut;
|
||||
private readonly Mock<IResponse> _responseMock;
|
||||
private readonly Mock<Stream> _stream;
|
||||
private readonly Mock<IHeaderDictionary> _headers;
|
||||
private readonly Mock<IFileSystemHandler> _fileSystemHandlerMock;
|
||||
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
|
||||
_stream = new Mock<Stream>();
|
||||
_stream.SetupAllProperties();
|
||||
_stream.Setup(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>())).Returns(CompletedTask);
|
||||
|
||||
public OwinResponseMapperTests()
|
||||
{
|
||||
_stream = new Mock<Stream>();
|
||||
_stream.SetupAllProperties();
|
||||
_stream.Setup(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>())).Returns(CompletedTask);
|
||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
_fileSystemHandlerMock.SetupAllProperties();
|
||||
|
||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
_fileSystemHandlerMock.SetupAllProperties();
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_optionsMock.SetupGet(o => o.FileSystemHandler).Returns(_fileSystemHandlerMock.Object);
|
||||
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_optionsMock.SetupGet(o => o.FileSystemHandler).Returns(_fileSystemHandlerMock.Object);
|
||||
|
||||
_headers = new Mock<IHeaderDictionary>();
|
||||
_headers.SetupAllProperties();
|
||||
_headers = new Mock<IHeaderDictionary>();
|
||||
_headers.SetupAllProperties();
|
||||
#if NET452
|
||||
_headers.Setup(h => h.AppendValues(It.IsAny<string>(), It.IsAny<string[]>()));
|
||||
_headers.Setup(h => h.AppendValues(It.IsAny<string>(), It.IsAny<string[]>()));
|
||||
#else
|
||||
_headers.Setup(h => h.Add(It.IsAny<string>(), It.IsAny<StringValues>()));
|
||||
_headers.Setup(h => h.Add(It.IsAny<string>(), It.IsAny<StringValues>()));
|
||||
#endif
|
||||
|
||||
_responseMock = new Mock<IResponse>();
|
||||
_responseMock.SetupAllProperties();
|
||||
_responseMock.SetupGet(r => r.Body).Returns(_stream.Object);
|
||||
_responseMock.SetupGet(r => r.Headers).Returns(_headers.Object);
|
||||
_responseMock = new Mock<IResponse>();
|
||||
_responseMock.SetupAllProperties();
|
||||
_responseMock.SetupGet(r => r.Body).Returns(_stream.Object);
|
||||
_responseMock.SetupGet(r => r.Headers).Returns(_headers.Object);
|
||||
|
||||
_sut = new OwinResponseMapper(_optionsMock.Object);
|
||||
}
|
||||
_sut = new OwinResponseMapper(_optionsMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Null()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Null()
|
||||
{
|
||||
// Act
|
||||
await _sut.MapAsync(null, _responseMock.Object).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(300, 300)]
|
||||
[InlineData(500, 500)]
|
||||
public async Task OwinResponseMapper_MapAsync_Valid_StatusCode(object code, int expected)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Act
|
||||
await _sut.MapAsync(null, _responseMock.Object).ConfigureAwait(false);
|
||||
}
|
||||
StatusCode = code
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(300, 300)]
|
||||
[InlineData(500, 500)]
|
||||
public async Task OwinResponseMapper_MapAsync_Valid_StatusCode(object code, int expected)
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 200)]
|
||||
[InlineData(-1, 200)]
|
||||
[InlineData(10000, 200)]
|
||||
[InlineData(300, 300)]
|
||||
public async Task OwinResponseMapper_MapAsync_Invalid_StatusCode_When_AllowOnlyDefinedHttpStatusCodeInResponseSet_Is_True(object code, int expected)
|
||||
{
|
||||
// Arrange
|
||||
_optionsMock.SetupGet(o => o.AllowOnlyDefinedHttpStatusCodeInResponse).Returns(true);
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
StatusCode = code
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 200)]
|
||||
[InlineData(-1, 200)]
|
||||
[InlineData(10000, 200)]
|
||||
[InlineData(300, 300)]
|
||||
public async Task OwinResponseMapper_MapAsync_Invalid_StatusCode_When_AllowOnlyDefinedHttpStatusCodeInResponseSet_Is_True(object code, int expected)
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_Null()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
_optionsMock.SetupGet(o => o.AllowOnlyDefinedHttpStatusCodeInResponse).Returns(true);
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
StatusCode = null
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = It.IsAny<int>(), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_Null()
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(-1, -1)]
|
||||
[InlineData(10000, 10000)]
|
||||
[InlineData(300, 300)]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_NotInEnumRange(object code, int expected)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = null
|
||||
};
|
||||
StatusCode = code
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = It.IsAny<int>(), Times.Never);
|
||||
}
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, 0)]
|
||||
[InlineData(-1, -1)]
|
||||
[InlineData(10000, 10000)]
|
||||
[InlineData(300, 300)]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_NotInEnumRange(object code, int expected)
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_NoBody()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>()
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_NoBody()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Body()
|
||||
{
|
||||
// Arrange
|
||||
string body = "abcd";
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>()
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 97, 98, 99, 100 }, 0, 4, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Body()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsBytes()
|
||||
{
|
||||
// Arrange
|
||||
var bytes = new byte[] { 48, 49 };
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
string body = "abcd";
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body }
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Bytes, BodyAsBytes = bytes }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 97, 98, 99, 100 }, 0, 4, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsBytes()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsJson()
|
||||
{
|
||||
// Arrange
|
||||
var json = new { t = "x", i = (string?)null };
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var bytes = new byte[] { 48, 49 };
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Bytes, BodyAsBytes = bytes }
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = json, BodyAsJsonIndented = false }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 123, 34, 116, 34, 58, 34, 120, 34, 125 }, 0, 9, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsJson()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_SetResponseHeaders()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var json = new { t = "x", i = (string?)null };
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = json, BodyAsJsonIndented = false }
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x", "y") } }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 123, 34, 116, 34, 58, 34, 120, 34, 125 }, 0, 9, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_SetResponseHeaders()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x", "y") } }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
// Assert
|
||||
#if NET452
|
||||
_headers.Verify(h => h.AppendValues("h", new string[] { "x", "y" }), Times.Once);
|
||||
_headers.Verify(h => h.AppendValues("h", new string[] { "x", "y" }), Times.Once);
|
||||
#else
|
||||
var v = new StringValues();
|
||||
_headers.Verify(h => h.TryGetValue("h", out v), Times.Once);
|
||||
var v = new StringValues();
|
||||
_headers.Verify(h => h.TryGetValue("h", out v), Times.Once);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OwinResponseMapper_MapAsync_BodyAsFile_ThrowsException()
|
||||
[Fact]
|
||||
public void OwinResponseMapper_MapAsync_BodyAsFile_ThrowsException()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.File, BodyAsFile = string.Empty }
|
||||
};
|
||||
_fileSystemHandlerMock.Setup(f => f.ReadResponseBodyAsFile(It.IsAny<string>())).Throws<FileNotFoundException>();
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.File, BodyAsFile = string.Empty }
|
||||
};
|
||||
_fileSystemHandlerMock.Setup(f => f.ReadResponseBodyAsFile(It.IsAny<string>())).Throws<FileNotFoundException>();
|
||||
|
||||
// Act
|
||||
Func<Task> action = () => _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
// Act
|
||||
Func<Task> action = () => _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
|
||||
// Assert
|
||||
action.Should().ThrowAsync<FileNotFoundException>();
|
||||
}
|
||||
// Assert
|
||||
action.Should().ThrowAsync<FileNotFoundException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_EMPTY_RESPONSE()
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_EMPTY_RESPONSE()
|
||||
{
|
||||
// Arrange
|
||||
string body = "abc";
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
string body = "abc";
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body },
|
||||
FaultType = FaultType.EMPTY_RESPONSE
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body },
|
||||
FaultType = FaultType.EMPTY_RESPONSE
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(EmptyArray<byte>.Value, 0, 0, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(EmptyArray<byte>.Value, 0, 0, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("abcd", BodyType.String)]
|
||||
[InlineData("", BodyType.String)]
|
||||
[InlineData(null, BodyType.None)]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_MALFORMED_RESPONSE_CHUNK(string body, BodyType detected)
|
||||
[Theory]
|
||||
[InlineData("abcd", BodyType.String)]
|
||||
[InlineData("", BodyType.String)]
|
||||
[InlineData(null, BodyType.None)]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_MALFORMED_RESPONSE_CHUNK(string body, BodyType detected)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = detected, BodyAsString = body },
|
||||
StatusCode = 100,
|
||||
FaultType = FaultType.MALFORMED_RESPONSE_CHUNK
|
||||
};
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = detected, BodyAsString = body },
|
||||
StatusCode = 100,
|
||||
FaultType = FaultType.MALFORMED_RESPONSE_CHUNK
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = 100, Times.Once);
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), 0, It.Is<int>(count => count >= 0), It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = 100, Times.Once);
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), 0, It.Is<int>(count => count >= 0), It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using NFluent;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Http;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Net.Tests.Serialization;
|
||||
using WireMock.Net.Xunit;
|
||||
@@ -351,7 +352,7 @@ public partial class WireMockServerTests
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public async Task WireMockServer_Should_exclude_restrictedResponseHeader()
|
||||
public async Task WireMockServer_Should_Exclude_RestrictedResponseHeader()
|
||||
{
|
||||
// Assign
|
||||
string path = $"/foo_{Guid.NewGuid()}";
|
||||
@@ -371,6 +372,26 @@ public partial class WireMockServerTests
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
[Fact] // #720
|
||||
public async Task WireMockServer_Should_AllowResponseHeaderContentLength_For_HEAD()
|
||||
{
|
||||
// Assign
|
||||
const string length = "42";
|
||||
var path = $"/cl_{Guid.NewGuid()}";
|
||||
using var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path).UsingHead())
|
||||
.RespondWith(Response.Create().WithHeader(HttpKnownHeaderNames.ContentLength, length));
|
||||
|
||||
// Act
|
||||
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Head, path);
|
||||
var response = await server.CreateClient().SendAsync(httpRequestMessage).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Content.Headers.GetValues(HttpKnownHeaderNames.ContentLength).Should().Contain(length);
|
||||
}
|
||||
|
||||
#if !NET452 && !NET461
|
||||
[Theory]
|
||||
[InlineData("TRACE")]
|
||||
|
||||
Reference in New Issue
Block a user