mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-28 03:27:43 +01:00
Compare commits
1 Commits
1.6.0
...
bug/973-Ti
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7880bfcc63 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,13 +1,3 @@
|
||||
# 1.6.0 (16 August 2024)
|
||||
- [#1042](https://github.com/WireMock-Net/WireMock.Net/pull/1042) - Update + add fluent builder methods [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1109](https://github.com/WireMock-Net/WireMock.Net/pull/1109) - Add Aspire Extension [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1148](https://github.com/WireMock-Net/WireMock.Net/pull/1148) - Use Guid.TryParseExact with format "D" contributed by [StefH](https://github.com/StefH)
|
||||
- [#1157](https://github.com/WireMock-Net/WireMock.Net/pull/1157) - Fix FormUrlEncodedMatcher (MatchOperator.And) [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1158](https://github.com/WireMock-Net/WireMock.Net/pull/1158) - Allow setting Content-Length header on the response [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#720](https://github.com/WireMock-Net/WireMock.Net/issues/720) - Response Header Content-Length not available when call HEAD Method [feature]
|
||||
- [#1145](https://github.com/WireMock-Net/WireMock.Net/issues/1145) - Response is auto converting string to guid [bug]
|
||||
- [#1156](https://github.com/WireMock-Net/WireMock.Net/issues/1156) - FormUrlEncodedMatcher is not requiring to match all properties when MatchOperator.And [bug]
|
||||
|
||||
# 1.5.62 (27 July 2024)
|
||||
- [#1147](https://github.com/WireMock-Net/WireMock.Net/pull/1147) - Add FormUrlEncodedMatcher [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#1143](https://github.com/WireMock-Net/WireMock.Net/issues/1143) - FormEncoded Request fails (404 Not Found) if key value pairs order in mapping is different from request body order [bug]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.6.0</VersionPrefix>
|
||||
<VersionPrefix>1.5.62</VersionPrefix>
|
||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
rem https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
SET version=1.6.0
|
||||
SET version=1.5.62
|
||||
|
||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%
|
||||
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
# 1.6.0 (16 August 2024)
|
||||
- #1042 Update + add fluent builder methods [feature]
|
||||
- #1109 Add Aspire Extension [feature]
|
||||
- #1148 Use Guid.TryParseExact with format "D"
|
||||
- #1157 Fix FormUrlEncodedMatcher (MatchOperator.And) [bug]
|
||||
- #1158 Allow setting Content-Length header on the response [feature]
|
||||
- #720 Response Header Content-Length not available when call HEAD Method [feature]
|
||||
- #1145 Response is auto converting string to guid [bug]
|
||||
- #1156 FormUrlEncodedMatcher is not requiring to match all properties when MatchOperator.And [bug]
|
||||
# 1.5.62 (27 July 2024)
|
||||
- #1147 Add FormUrlEncodedMatcher [feature]
|
||||
- #1143 FormEncoded Request fails (404 Not Found) if key value pairs order in mapping is different from request body order [bug]
|
||||
|
||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||
@@ -137,6 +137,7 @@ message HelloReply {
|
||||
public static void Run()
|
||||
{
|
||||
RunOnLocal();
|
||||
return;
|
||||
|
||||
var mappingBuilder = new MappingBuilder();
|
||||
mappingBuilder
|
||||
@@ -307,6 +308,17 @@ message HelloReply {
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("GraphQL is ok")
|
||||
);
|
||||
|
||||
//server
|
||||
// .AddGraphQLSchema("my-graphql", TestSchema, customScalars)
|
||||
// .Given(Request.Create()
|
||||
// .WithPath("/graphql2")
|
||||
// .UsingPost()
|
||||
// )
|
||||
// .WithGraphQLSchema("my-graphql")
|
||||
// .RespondWith(Response.Create()
|
||||
// .WithBody("GraphQL is ok")
|
||||
// );
|
||||
#endif
|
||||
|
||||
#if MIMEKIT
|
||||
@@ -365,15 +377,6 @@ message HelloReply {
|
||||
.WithHeader("Content-Type", "text/plain")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingHead()
|
||||
.WithPath("/cl")
|
||||
)
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Content-Length", "42")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace WireMock.Http;
|
||||
/// </summary>
|
||||
internal static class HttpKnownHeaderNames
|
||||
{
|
||||
// - https://docs.microsoft.com/en-us/dotnet/api/system.net.webheadercollection.isrestricted
|
||||
// - ContentLength is allowed per #720
|
||||
// https://docs.microsoft.com/en-us/dotnet/api/system.net.webheadercollection.isrestricted
|
||||
private static readonly string[] RestrictedResponseHeaders =
|
||||
{
|
||||
Accept,
|
||||
Connection,
|
||||
ContentLength,
|
||||
ContentType,
|
||||
Date, // RFC1123Pattern
|
||||
Expect,
|
||||
|
||||
@@ -37,20 +37,13 @@ namespace WireMock.Owin.Mappers
|
||||
private readonly Encoding _utf8NoBom = new UTF8Encoding(false);
|
||||
|
||||
// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
|
||||
private static readonly IDictionary<string, Action<IResponse, bool, WireMockList<string>>> ResponseHeadersToFix =
|
||||
new Dictionary<string, Action<IResponse, bool, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ HttpKnownHeaderNames.ContentType, (r, _, v) => r.ContentType = v.FirstOrDefault() },
|
||||
{ HttpKnownHeaderNames.ContentLength, (r, hasBody, v) =>
|
||||
{
|
||||
// Only set the Content-Length header if the response does not have a body
|
||||
if (!hasBody && long.TryParse(v.FirstOrDefault(), out var contentLength))
|
||||
{
|
||||
r.ContentLength = contentLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#if !USE_ASPNETCORE
|
||||
private static readonly IDictionary<string, Action<IResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<IResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#else
|
||||
private static readonly IDictionary<string, Action<IResponse, WireMockList<string>>> ResponseHeadersToFix = new Dictionary<string, Action<IResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#endif
|
||||
{ HttpKnownHeaderNames.ContentType, (r, v) => r.ContentType = v.FirstOrDefault() }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
@@ -90,21 +83,23 @@ namespace WireMock.Owin.Mappers
|
||||
}
|
||||
|
||||
var statusCodeType = responseMessage.StatusCode?.GetType();
|
||||
if (statusCodeType != null)
|
||||
switch (statusCodeType)
|
||||
{
|
||||
if (statusCodeType == typeof(int) || statusCodeType == typeof(int?) || statusCodeType.GetTypeInfo().IsEnum)
|
||||
{
|
||||
case { } when statusCodeType == typeof(int) || statusCodeType == typeof(int?) || statusCodeType.GetTypeInfo().IsEnum:
|
||||
response.StatusCode = MapStatusCode((int)responseMessage.StatusCode!);
|
||||
}
|
||||
else if (statusCodeType == typeof(string))
|
||||
{
|
||||
// Note: this case will also match on null
|
||||
int.TryParse(responseMessage.StatusCode as string, out var statusCodeTypeAsInt);
|
||||
response.StatusCode = MapStatusCode(statusCodeTypeAsInt);
|
||||
}
|
||||
break;
|
||||
|
||||
case { } when statusCodeType == typeof(string):
|
||||
// Note: this case will also match on null
|
||||
int.TryParse(responseMessage.StatusCode as string, out var result);
|
||||
response.StatusCode = MapStatusCode(result);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SetResponseHeaders(responseMessage, bytes, response);
|
||||
SetResponseHeaders(responseMessage, response);
|
||||
|
||||
if (bytes != null)
|
||||
{
|
||||
@@ -165,7 +160,7 @@ namespace WireMock.Owin.Mappers
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void SetResponseHeaders(IResponseMessage responseMessage, byte[]? bytes, IResponse response)
|
||||
private static void SetResponseHeaders(IResponseMessage responseMessage, IResponse response)
|
||||
{
|
||||
// Force setting the Date header (#577)
|
||||
AppendResponseHeader(
|
||||
@@ -184,11 +179,11 @@ namespace WireMock.Owin.Mappers
|
||||
var value = item.Value;
|
||||
if (ResponseHeadersToFix.TryGetValue(headerName, out var action))
|
||||
{
|
||||
action?.Invoke(response, bytes != null, value);
|
||||
action?.Invoke(response, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if this response header can be added (#148, #227 and #720)
|
||||
// Check if this response header can be added (#148 and #227)
|
||||
if (!HttpKnownHeaderNames.IsRestrictedResponseHeader(headerName))
|
||||
{
|
||||
AppendResponseHeader(response, headerName, value.ToArray());
|
||||
@@ -211,7 +206,7 @@ namespace WireMock.Owin.Mappers
|
||||
var value = item.Value;
|
||||
if (ResponseHeadersToFix.TryGetValue(headerName, out var action))
|
||||
{
|
||||
action?.Invoke(response, false, value);
|
||||
action?.Invoke(response, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,56 +1,24 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using Nelibur.ObjectMapper;
|
||||
using Riok.Mapperly.Abstractions;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Settings;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Util;
|
||||
|
||||
internal sealed class TinyMapperUtils
|
||||
[Mapper]
|
||||
internal static partial class TinyMapperUtils
|
||||
{
|
||||
public static TinyMapperUtils Instance { get; } = new();
|
||||
public static partial ProxyAndRecordSettingsModel? Map(ProxyAndRecordSettings? instance);
|
||||
|
||||
private TinyMapperUtils()
|
||||
{
|
||||
TinyMapper.Bind<ProxyAndRecordSettings, ProxyAndRecordSettingsModel>();
|
||||
TinyMapper.Bind<WebProxySettings, WebProxySettingsModel>();
|
||||
TinyMapper.Bind<WebProxySettings, WebProxyModel>();
|
||||
TinyMapper.Bind<ProxyUrlReplaceSettings, ProxyUrlReplaceSettingsModel>();
|
||||
public static partial ProxyAndRecordSettings? Map(ProxyAndRecordSettingsModel? model);
|
||||
|
||||
TinyMapper.Bind<ProxyAndRecordSettingsModel, ProxyAndRecordSettings>();
|
||||
TinyMapper.Bind<WebProxySettingsModel, WebProxySettings>();
|
||||
TinyMapper.Bind<WebProxyModel, WebProxySettings>();
|
||||
TinyMapper.Bind<ProxyUrlReplaceSettingsModel, ProxyUrlReplaceSettings>();
|
||||
}
|
||||
public static partial ProxyUrlReplaceSettingsModel? Map(ProxyUrlReplaceSettings? instance);
|
||||
|
||||
public ProxyAndRecordSettingsModel? Map(ProxyAndRecordSettings? instance)
|
||||
{
|
||||
return instance == null ? null : TinyMapper.Map<ProxyAndRecordSettingsModel>(instance);
|
||||
}
|
||||
public static partial ProxyUrlReplaceSettings? Map(ProxyUrlReplaceSettingsModel? model);
|
||||
|
||||
public ProxyAndRecordSettings? Map(ProxyAndRecordSettingsModel? model)
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<ProxyAndRecordSettings>(model);
|
||||
}
|
||||
public static partial WebProxyModel? Map(WebProxySettings? instance);
|
||||
|
||||
public ProxyUrlReplaceSettingsModel? Map(ProxyUrlReplaceSettings? instance)
|
||||
{
|
||||
return instance == null ? null : TinyMapper.Map<ProxyUrlReplaceSettingsModel>(instance);
|
||||
}
|
||||
|
||||
public ProxyUrlReplaceSettings? Map(ProxyUrlReplaceSettingsModel? model)
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<ProxyUrlReplaceSettings>(model);
|
||||
}
|
||||
|
||||
public WebProxyModel? Map(WebProxySettings? instance)
|
||||
{
|
||||
return instance == null ? null : TinyMapper.Map<WebProxyModel>(instance);
|
||||
}
|
||||
|
||||
public WebProxySettings? Map(WebProxyModel? model)
|
||||
{
|
||||
return model == null ? null : TinyMapper.Map<WebProxySettings>(model);
|
||||
}
|
||||
public static partial WebProxySettings? Map(WebProxyModel? model);
|
||||
}
|
||||
@@ -63,10 +63,10 @@
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NJsonSchema.Extensions" Version="0.1.0" />
|
||||
<PackageReference Include="NSwag.Core" Version="13.16.1" />
|
||||
<PackageReference Include="Riok.Mapperly" Version="3.6.0" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
||||
<PackageReference Include="AnyOf" Version="0.3.0" />
|
||||
<PackageReference Include="TinyMapper" Version="3.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
||||
|
||||
@@ -25,277 +25,278 @@ using Response = Microsoft.AspNetCore.Http.HttpResponse;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Net.Tests.Owin.Mappers;
|
||||
|
||||
public class OwinResponseMapperTests
|
||||
namespace WireMock.Net.Tests.Owin.Mappers
|
||||
{
|
||||
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()
|
||||
public class 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);
|
||||
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;
|
||||
|
||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
_fileSystemHandlerMock.SetupAllProperties();
|
||||
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);
|
||||
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_optionsMock.SetupGet(o => o.FileSystemHandler).Returns(_fileSystemHandlerMock.Object);
|
||||
_fileSystemHandlerMock = new Mock<IFileSystemHandler>();
|
||||
_fileSystemHandlerMock.SetupAllProperties();
|
||||
|
||||
_headers = new Mock<IHeaderDictionary>();
|
||||
_headers.SetupAllProperties();
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_optionsMock.SetupGet(o => o.FileSystemHandler).Returns(_fileSystemHandlerMock.Object);
|
||||
|
||||
_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()
|
||||
{
|
||||
// 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
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Null()
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
// Act
|
||||
await _sut.MapAsync(null, _responseMock.Object).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// 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
|
||||
[Theory]
|
||||
[InlineData(300, 300)]
|
||||
[InlineData(500, 500)]
|
||||
public async Task OwinResponseMapper_MapAsync_Valid_StatusCode(object code, int expected)
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_Null()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[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)
|
||||
{
|
||||
StatusCode = null
|
||||
};
|
||||
// Arrange
|
||||
_optionsMock.SetupGet(o => o.AllowOnlyDefinedHttpStatusCodeInResponse).Returns(true);
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
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)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_StatusCode_Is_Null()
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
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_NoBody()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[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)
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>()
|
||||
};
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = code
|
||||
};
|
||||
|
||||
// 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
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Body()
|
||||
{
|
||||
// Arrange
|
||||
string body = "abcd";
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_NoBody()
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body }
|
||||
};
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
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
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 97, 98, 99, 100 }, 0, 4, It.IsAny<CancellationToken>()), 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_BodyAsBytes()
|
||||
{
|
||||
// Arrange
|
||||
var bytes = new byte[] { 48, 49 };
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_Body()
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Bytes, BodyAsBytes = bytes }
|
||||
};
|
||||
// Arrange
|
||||
string body = "abcd";
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
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(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
// 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_BodyAsJson()
|
||||
{
|
||||
// Arrange
|
||||
var json = new { t = "x", i = (string?)null };
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsBytes()
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.Json, BodyAsJson = json, BodyAsJsonIndented = false }
|
||||
};
|
||||
// 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 }
|
||||
};
|
||||
|
||||
// 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);
|
||||
}
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_SetResponseHeaders()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_BodyAsJson()
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x", "y") } }
|
||||
};
|
||||
// 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 }
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
// 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
|
||||
#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()
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public void OwinResponseMapper_MapAsync_BodyAsFile_ThrowsException()
|
||||
{
|
||||
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>();
|
||||
// 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>();
|
||||
|
||||
// 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()
|
||||
{
|
||||
// Arrange
|
||||
string body = "abc";
|
||||
var responseMessage = new ResponseMessage
|
||||
[Fact]
|
||||
public async Task OwinResponseMapper_MapAsync_WithFault_EMPTY_RESPONSE()
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = BodyType.String, BodyAsString = body },
|
||||
FaultType = FaultType.EMPTY_RESPONSE
|
||||
};
|
||||
// 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
|
||||
};
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Arrange
|
||||
var responseMessage = new ResponseMessage
|
||||
[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)
|
||||
{
|
||||
Headers = new Dictionary<string, WireMockList<string>>(),
|
||||
BodyData = new BodyData { DetectedBodyType = detected, BodyAsString = body },
|
||||
StatusCode = 100,
|
||||
FaultType = FaultType.MALFORMED_RESPONSE_CHUNK
|
||||
};
|
||||
// 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
|
||||
};
|
||||
|
||||
// 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,7 +14,6 @@ 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;
|
||||
@@ -352,7 +351,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()}";
|
||||
@@ -372,26 +371,6 @@ 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