This commit is contained in:
Stef Heyenrath
2026-02-21 20:00:08 +01:00
parent d0ed0b852e
commit 6ebf368124
3 changed files with 204 additions and 7 deletions

View File

@@ -207,7 +207,6 @@ internal static class BodyParser
{
return true;
}
;
// 1) Quick binary detection
for (int i = 0; i < data.Length; i++)

View File

@@ -253,6 +253,106 @@ public class WireMockAdminApiAssertionsTests : IDisposable
.WithMessage($"Expected _adminApi to have been called at address matching the absolute path \"/anypath\", but didn't find it among the calls to {{\"/\"}}.");
}
[Fact]
public async Task HaveReceivedNoCalls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("xxx", _ct);
_adminApi.Should()
.HaveReceivedNoCalls()
.AtPath("anypath");
}
[Fact]
public async Task HaveReceived0Calls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("xxx", _ct);
_adminApi.Should()
.HaveReceived(0).Calls()
.AtPath("anypath");
}
[Fact]
public async Task HaveReceived1Call_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_adminApi.Should()
.HaveReceived(1).Calls()
.AtPath("/anypath");
}
[Fact]
public async Task HaveReceived1Call_AtPathUsingPost_WhenAPostCallWasMadeToPath_Should_BeOK()
{
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
_adminApi.Should()
.HaveReceived(1).Calls()
.AtPath("/anypath")
.And
.UsingPost();
}
[Fact]
public async Task HaveReceived2Calls_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
await _httpClient.GetAsync("anypath", _ct);
_adminApi.Should()
.HaveReceived(2).Calls()
.AtPath("/anypath");
}
[Fact]
public async Task HaveReceivedACall_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_adminApi.Should()
.HaveReceivedACall()
.AtPath(new WildcardMatcher("/any*"));
}
[Fact]
public async Task HaveReceivedACall_AtPathWildcardMatcher_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_adminApi.Should()
.HaveReceivedACall()
.AtPath("/anypath");
}
[Fact]
public void HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsWereMade()
{
Action act = () => _adminApi.Should()
.HaveReceivedACall()
.AtPath("anypath");
act.Should()
.Throw<Exception>()
.WithMessage("Expected _adminApi to have been called at address matching the path \"anypath\", but no calls were made.");
}
[Fact]
public async Task HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsMatchingThePathWereMade()
{
await _httpClient.GetAsync("", _ct);
Action act = () => _adminApi.Should()
.HaveReceivedACall()
.AtPath("/anypath");
act.Should()
.Throw<Exception>()
.WithMessage($"Expected _adminApi to have been called at address matching the path \"/anypath\", but didn't find it among the calls to {{\"/\"}}.");
}
[Fact]
public async Task HaveReceivedACall_WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
{
@@ -344,7 +444,6 @@ public class WireMockAdminApiAssertionsTests : IDisposable
public async Task HaveReceivedACall_WithHeader_ShouldCheckAllRequests()
{
// Arrange
var cancellationToken = _ct;
using var server = WireMockServer.Start(settings =>
{
settings.StartAdminInterface = true;
@@ -363,7 +462,7 @@ public class WireMockAdminApiAssertionsTests : IDisposable
{
Authorization = new AuthenticationHeaderValue("Bearer", "invalidToken")
}
}, cancellationToken);
}, _ct);
// Act 2
var task2 = client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
@@ -372,7 +471,7 @@ public class WireMockAdminApiAssertionsTests : IDisposable
{
Authorization = new AuthenticationHeaderValue("Bearer", "validToken")
}
}, cancellationToken);
}, _ct);
await Task.WhenAll(task1, task2);

View File

@@ -241,6 +241,106 @@ public class WireMockAssertionsTests : IDisposable
.WithMessage($"Expected _server to have been called at address matching the absolute path \"/anypath\", but didn't find it among the calls to {{\"/\"}}.");
}
[Fact]
public async Task HaveReceivedNoCalls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("xxx", _ct);
_server.Should()
.HaveReceivedNoCalls()
.AtPath("anypath");
}
[Fact]
public async Task HaveReceived0Calls_AtPath_WhenACallWasNotMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("xxx", _ct);
_server.Should()
.HaveReceived(0).Calls()
.AtPath("anypath");
}
[Fact]
public async Task HaveReceived1Call_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_server.Should()
.HaveReceived(1).Calls()
.AtPath("/anypath");
}
[Fact]
public async Task HaveReceived1Call_AtPathUsingPost_WhenAPostCallWasMadeToPath_Should_BeOK()
{
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
_server.Should()
.HaveReceived(1).Calls()
.AtPath("/anypath")
.And
.UsingPost();
}
[Fact]
public async Task HaveReceived2Calls_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
await _httpClient.GetAsync("anypath", _ct);
_server.Should()
.HaveReceived(2).Calls()
.AtPath("/anypath");
}
[Fact]
public async Task HaveReceivedACall_AtPath_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_server.Should()
.HaveReceivedACall()
.AtPath(new WildcardMatcher("/any*"));
}
[Fact]
public async Task HaveReceivedACall_AtPathWildcardMatcher_WhenACallWasMadeToPath_Should_BeOK()
{
await _httpClient.GetAsync("anypath", _ct);
_server.Should()
.HaveReceivedACall()
.AtPath("/anypath");
}
[Fact]
public void HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsWereMade()
{
Action act = () => _server.Should()
.HaveReceivedACall()
.AtPath("anypath");
act.Should()
.Throw<Exception>()
.WithMessage("Expected _server to have been called at address matching the path \"anypath\", but no calls were made.");
}
[Fact]
public async Task HaveReceivedACall_AtPath_Should_ThrowWhenNoCallsMatchingThePathWereMade()
{
await _httpClient.GetAsync("", _ct);
Action act = () => _server.Should()
.HaveReceivedACall()
.AtPath("/anypath");
act.Should()
.Throw<Exception>()
.WithMessage($"Expected _server to have been called at address matching the path \"anypath\", but didn't find it among the calls to {{\"\"}}.");
}
[Fact]
public async Task HaveReceivedACall_WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
{
@@ -332,7 +432,6 @@ public class WireMockAssertionsTests : IDisposable
public async Task HaveReceivedACall_WithHeader_ShouldCheckAllRequests()
{
// Arrange
var cancellationToken = _ct;
using var server = WireMockServer.Start();
using var client1 = server.CreateClient();
@@ -346,7 +445,7 @@ public class WireMockAssertionsTests : IDisposable
{
Authorization = new AuthenticationHeaderValue("Bearer", "invalidToken")
}
}, cancellationToken);
}, _ct);
// Act 2
var task2 = client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
@@ -355,7 +454,7 @@ public class WireMockAssertionsTests : IDisposable
{
Authorization = new AuthenticationHeaderValue("Bearer", "validToken")
}
}, cancellationToken);
}, _ct);
await Task.WhenAll(task1, task2);