mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:24:34 +01:00
Add WireMockAspNetCoreLogger to log Kestrel warnings/errors (#1432)
* Add WireMockAspNetCoreLogger * fix tests * x * .
This commit is contained in:
@@ -27,7 +27,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
message.Headers.GetValues("x").Should().Equal(new[] { "value-1" });
|
||||
message.Headers.GetValues("x").Should().Equal(["value-1"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,7 +101,7 @@ public class HttpRequestMessageHelperTests
|
||||
|
||||
// Assert
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/json" });
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(["application/json"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -121,7 +121,7 @@ public class HttpRequestMessageHelperTests
|
||||
|
||||
// Assert
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/json; charset=utf-8" });
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(["application/json; charset=utf-8"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -142,7 +142,7 @@ public class HttpRequestMessageHelperTests
|
||||
|
||||
// Assert
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be("{\"x\":42}");
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "multipart/form-data" });
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(["multipart/form-data"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml" });
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(["application/xml"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -181,7 +181,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml; charset=UTF-8" });
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(["application/xml; charset=UTF-8"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -200,7 +200,7 @@ public class HttpRequestMessageHelperTests
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(new[] { "application/xml; charset=Ascii" });
|
||||
message.Content!.Headers.GetValues("Content-Type").Should().Equal(["application/xml; charset=Ascii"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -242,7 +242,7 @@ public class HttpRequestMessageHelperTests
|
||||
|
||||
// Assert
|
||||
(await message.Content!.ReadAsStringAsync(_ct)).Should().Be(body);
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(new[] { "multipart/form-data" });
|
||||
message.Content.Headers.GetValues("Content-Type").Should().Equal(["multipart/form-data"]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -269,7 +269,4 @@ public class HttpRequestMessageHelperTests
|
||||
// Assert
|
||||
message.Content?.Headers.ContentLength.Should().Be(resultShouldBe ? value : null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -706,7 +706,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
public async Task WithWebSocketProxy_Should_Proxy_Multiple_TextMessages()
|
||||
{
|
||||
// Arrange - Start target echo server
|
||||
using var exampleEchoServer = WireMockServer.Start(new WireMockServerSettings
|
||||
var exampleEchoServer = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = new TestOutputHelperWireMockLogger(output),
|
||||
Urls = ["ws://localhost:0"]
|
||||
@@ -722,7 +722,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
);
|
||||
|
||||
// Arrange - Start proxy server
|
||||
using var sut = WireMockServer.Start(new WireMockServerSettings
|
||||
var sut = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
Logger = new TestOutputHelperWireMockLogger(output),
|
||||
Urls = ["ws://localhost:0"]
|
||||
@@ -755,6 +755,14 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
}
|
||||
|
||||
await client.CloseAsync(WebSocketCloseStatus.NormalClosure, "Test complete", _ct);
|
||||
|
||||
await Task.Delay(250, _ct);
|
||||
|
||||
sut.Stop();
|
||||
sut.Dispose();
|
||||
|
||||
exampleEchoServer.Stop();
|
||||
exampleEchoServer.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -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