mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 17:28:55 +02:00
Add WireMockAspNetCoreLogger to log Kestrel warnings/errors (#1432)
* Add WireMockAspNetCoreLogger * fix tests * x * .
This commit is contained in:
@@ -431,8 +431,13 @@ public partial class WireMockServerTests(ITestOutputHelper testOutputHelper)
|
||||
using var server = WireMockServer.Start();
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath(path).UsingHead())
|
||||
.RespondWith(Response.Create().WithHeader(HttpKnownHeaderNames.ContentLength, length));
|
||||
.WhenRequest(r => r
|
||||
.WithPath(path)
|
||||
.UsingHead()
|
||||
)
|
||||
.ThenRespondWith(r => r
|
||||
.WithHeader(HttpKnownHeaderNames.ContentLength, length)
|
||||
);
|
||||
|
||||
// Act
|
||||
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Head, path);
|
||||
@@ -442,6 +447,45 @@ public partial class WireMockServerTests(ITestOutputHelper testOutputHelper)
|
||||
response.Content.Headers.GetValues(HttpKnownHeaderNames.ContentLength).Should().Contain(length);
|
||||
}
|
||||
|
||||
#if NET8_0_OR_GREATER
|
||||
[Theory]
|
||||
[InlineData("DELETE")]
|
||||
[InlineData("GET")]
|
||||
[InlineData("OPTIONS")]
|
||||
[InlineData("PATCH")]
|
||||
[InlineData("POST")]
|
||||
[InlineData("PUT")]
|
||||
[InlineData("TRACE")]
|
||||
public async Task WireMockServer_Should_LogAndThrowExceptionWhenInvalidContentLength(string method)
|
||||
{
|
||||
// Assign
|
||||
const string length = "42";
|
||||
var path = $"/InvalidContentLength_{Guid.NewGuid()}";
|
||||
using var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = new TestOutputHelperWireMockLogger(testOutputHelper)
|
||||
});
|
||||
|
||||
server
|
||||
.WhenRequest(r => r
|
||||
.WithPath(path)
|
||||
.UsingAnyMethod()
|
||||
)
|
||||
.ThenRespondWith(r => r
|
||||
.WithStatusCode(HttpStatusCode.OK)
|
||||
.WithHeader(HttpKnownHeaderNames.ContentLength, length)
|
||||
);
|
||||
|
||||
// Act
|
||||
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Parse(method), path);
|
||||
var response = await server.CreateClient().SendAsync(httpRequestMessage, _ct);
|
||||
|
||||
// Assert
|
||||
response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
|
||||
testOutputHelper.Output.Should().Contain($"Response Content-Length mismatch: too few bytes written (0 of {length}).");
|
||||
}
|
||||
#endif
|
||||
|
||||
[Theory]
|
||||
[InlineData("TRACE")]
|
||||
[InlineData("GET")]
|
||||
|
||||
Reference in New Issue
Block a user