mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-19 07:54:53 +01:00
.
This commit is contained in:
@@ -582,7 +582,7 @@ public class WireMockAdminApiAssertionsTests : IDisposable
|
||||
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage!.ClientIP;
|
||||
|
||||
_adminApi.Should()
|
||||
.HaveReceivedACall()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Moq;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Owin.Mappers;
|
||||
|
||||
@@ -17,20 +18,32 @@ public class GlobalExceptionMiddlewareTests
|
||||
public GlobalExceptionMiddlewareTests()
|
||||
{
|
||||
_optionsMock = new Mock<IWireMockMiddlewareOptions>();
|
||||
_optionsMock.SetupAllProperties();
|
||||
_optionsMock.SetupGet(o => o.Logger).Returns(Mock.Of<IWireMockLogger>());
|
||||
|
||||
_responseMapperMock = new Mock<IOwinResponseMapper>();
|
||||
_responseMapperMock.SetupAllProperties();
|
||||
_responseMapperMock.Setup(m => m.MapAsync(It.IsAny<ResponseMessage?>(), It.IsAny<HttpResponse>())).Returns(Task.FromResult(true));
|
||||
|
||||
_sut = new GlobalExceptionMiddleware(null, _optionsMock.Object, _responseMapperMock.Object);
|
||||
_sut = new GlobalExceptionMiddleware(_ => Task.CompletedTask, _optionsMock.Object, _responseMapperMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GlobalExceptionMiddleware_Invoke_NullAsNext_DoesNotInvokeNextAndDoesNotThrow()
|
||||
public void GlobalExceptionMiddleware_Invoke_ValidNext_ShouldNotThrow()
|
||||
{
|
||||
// Act
|
||||
Action act = () => _sut.Invoke(null);
|
||||
act.Should().NotThrow();
|
||||
_sut.Invoke(Mock.Of<HttpContext>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GlobalExceptionMiddleware_Invoke_InvalidNext_ShouldCallResponseMapperWith500()
|
||||
{
|
||||
// Arrange
|
||||
var sut = new GlobalExceptionMiddleware(_ => throw new ArgumentException(), _optionsMock.Object, _responseMapperMock.Object);
|
||||
|
||||
// Act
|
||||
sut.Invoke(Mock.Of<HttpContext>());
|
||||
|
||||
// Verify
|
||||
_responseMapperMock.Verify(m => m.MapAsync(It.IsAny<ResponseMessage>(), It.IsAny<HttpResponse>()), Times.Once);
|
||||
_responseMapperMock.VerifyNoOtherCalls();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class ResponseWithBodyFromFileTests
|
||||
);
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content", _ct);
|
||||
|
||||
// Assert
|
||||
response.Should().Contain("<hello>world</hello>");
|
||||
|
||||
@@ -796,7 +796,7 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
var proxyUri = new Uri($"{sut.Url}/ws/proxy");
|
||||
await client.ConnectAsync(proxyUri, _ct);
|
||||
|
||||
await Task.Delay(500, _ct);
|
||||
await Task.Delay(250, _ct);
|
||||
|
||||
var testData = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
|
||||
|
||||
@@ -805,6 +805,8 @@ public class WebSocketIntegrationTests(ITestOutputHelper output, ITestContextAcc
|
||||
|
||||
var receivedData = await client.ReceiveAsBytesAsync(cancellationToken: _ct);
|
||||
|
||||
await Task.Delay(250, _ct);
|
||||
|
||||
// Assert
|
||||
receivedData.Should().BeEquivalentTo(testData, "binary data should be proxied and echoed back");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user