mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-21 00:11:44 +02:00
WireMock.Net.RestClient.AwesomeAssertions (#1427)
* WireMock.Net.RestClient.AwesomeAssertions * ok * atpath * fix test * sonar fixes * ports
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -52,7 +52,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrl2_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrl2_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anyurl", new StringContent(""), _ct);
|
||||
|
||||
@@ -162,7 +162,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
@@ -172,7 +172,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsolutePathUsingPost_WhenAPostCallWasMadeToAbsolutePath_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsolutePathUsingPost_WhenAPostCallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -625,7 +724,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start();
|
||||
|
||||
Reference in New Issue
Block a user