Add overloads to AtUrl and AtAbsoluteUrl which can use a IStringMatcher (#1221)

This commit is contained in:
Stef Heyenrath
2024-12-22 17:11:21 +01:00
committed by GitHub
parent deda7fb686
commit 6db5427e6e
3 changed files with 84 additions and 15 deletions

View File

@@ -102,6 +102,16 @@ public class WireMockAssertionsTests : IDisposable
{
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
_server.Should()
.HaveReceivedACall()
.AtAbsoluteUrl(new WildcardMatcher($"http://localhost:{_portUsed}/any*"));
}
[Fact]
public async Task HaveReceivedACall_AtAbsoluteUrlWilcardMAtcher_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
{
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
_server.Should()
.HaveReceivedACall()
.AtAbsoluteUrl($"http://localhost:{_portUsed}/anyurl");
@@ -231,7 +241,7 @@ public class WireMockAssertionsTests : IDisposable
using var client2 = server.CreateClient(handler);
// Act 1
await client1.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
var task1 = client1.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
{
Headers =
{
@@ -240,7 +250,7 @@ public class WireMockAssertionsTests : IDisposable
});
// Act 2
await client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
var task2 = client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
{
Headers =
{
@@ -248,6 +258,8 @@ public class WireMockAssertionsTests : IDisposable
}
});
await Task.WhenAll(task1, task2);
// Assert
server.Should()
.HaveReceivedACall()
@@ -268,6 +280,16 @@ public class WireMockAssertionsTests : IDisposable
.AtUrl($"http://localhost:{_portUsed}/anyurl");
}
[Fact]
public async Task HaveReceivedACall_AtUrlWildcardMatcher_WhenACallWasMadeToUrl_Should_BeOK()
{
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
_server.Should()
.HaveReceivedACall()
.AtUrl(new WildcardMatcher($"http://localhost:{_portUsed}/AN*", true));
}
[Fact]
public void HaveReceivedACall_AtUrl_Should_ThrowWhenNoCallsWereMade()
{
@@ -393,11 +415,14 @@ public class WireMockAssertionsTests : IDisposable
[Fact]
public async Task HaveReceived2Calls_UsingDelete_WhenACallWasMadeUsingDelete_Should_BeOK()
{
await _httpClient.DeleteAsync("anyurl").ConfigureAwait(false);
var tasks = new[]
{
_httpClient.DeleteAsync("anyurl"),
_httpClient.DeleteAsync("anyurl"),
_httpClient.GetAsync("anyurl")
};
await _httpClient.DeleteAsync("anyurl").ConfigureAwait(false);
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
await Task.WhenAll(tasks);
_server.Should()
.HaveReceived(2).Calls()
@@ -521,11 +546,14 @@ public class WireMockAssertionsTests : IDisposable
// Act
var httpClient = new HttpClient();
await httpClient.GetAsync($"{server.Url}/a");
var tasks = new[]
{
httpClient.GetAsync($"{server.Url}/a"),
httpClient.PostAsync($"{server.Url}/b", new StringContent("B")),
httpClient.PostAsync($"{server.Url}/c", new StringContent("C"))
};
await httpClient.PostAsync($"{server.Url}/b", new StringContent("B"));
await httpClient.PostAsync($"{server.Url}/c", new StringContent("C"));
await Task.WhenAll(tasks);
// Assert
server