mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 09:48:51 +02:00
Version 2.x (#1359)
* Version 2.x * Setup .NET 9 * 12 * cleanup some #if for NETSTANDARD1_3 * cleanup + fix tests for net8 * openapi * NO ConfigureAwait(false) + cleanup * . * #endif * HashSet * WireMock.Net.NUnit * HttpContext * Add WebSockets (#1423) * Add WebSockets * Add tests * fix * more tests * Add tests * ... * remove IOwin * - * tests * fluent * ok * match * . * byte[] * x * func * func * byte * trans * ... * frameworks......... * jmes * xxx * sc * using var httpClient = new HttpClient(); * usings * maxRetries * up * xunit v3 * ct * --- * ct * ct2 * T Unit * WireMock.Net.TUnitTests / 10 * t unit first * --project * no tunit * t2 * --project * --project * ci - --project * publish ./test/wiremock-coverage.xml * windows * . * log * ... * log * goed * BodyType * . * . * --scenario * ... * pact * ct * . * WireMock.Net.RestClient.AwesomeAssertions (#1427) * WireMock.Net.RestClient.AwesomeAssertions * ok * atpath * fix test * sonar fixes * ports * proxy test * FIX? * --- * await Task.Delay(100, _ct); * ? * --project * Aspire: use IDistributedApplicationEventingSubscriber (#1428) * broadcast * ok * more tsts * . * Collection * up * . * 2 * remove nfluent * <VersionPrefix>2.0.0-preview-02</VersionPrefix> * ... * . * nuget icon * . * <PackageReference Include="JmesPath.Net" Version="1.1.0" /> * x * 500 * . * fix some warnings * ws
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,39 +0,0 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using FluentAssertions.Execution;
|
||||
using WireMock.FluentAssertions;
|
||||
|
||||
namespace WireMock.Net.Tests.FluentAssertions;
|
||||
|
||||
public static class WireMockAssertionsExtensions
|
||||
{
|
||||
[CustomAssertion]
|
||||
public static AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl2(this WireMockAssertions assertions,
|
||||
string absoluteUrl, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = assertions.BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Execute.Assertion
|
||||
.BecauseOf(because, becauseArgs)
|
||||
.Given(() => assertions.RequestMessages)
|
||||
.ForCondition(requests => assertions.CallsCount == 0 || requests.Any())
|
||||
.FailWith(
|
||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
||||
absoluteUrl
|
||||
)
|
||||
.Then
|
||||
.ForCondition(condition)
|
||||
.FailWith(
|
||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but didn't find it among the calls to {1}.",
|
||||
_ => absoluteUrl,
|
||||
requests => requests.Select(request => request.AbsoluteUrl)
|
||||
);
|
||||
|
||||
assertions.FilterRequestMessages(filter);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(assertions, absoluteUrl);
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,22 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using WireMock.FluentAssertions;
|
||||
using System.Net.Http.Json;
|
||||
using WireMock.AwesomeAssertions;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.FluentAssertions;
|
||||
|
||||
public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||
|
||||
private readonly WireMockServer _server;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly int _portUsed;
|
||||
@@ -29,14 +27,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod()).RespondWith(Response.Create().WithSuccess());
|
||||
|
||||
_portUsed = _server.Ports.First();
|
||||
|
||||
_httpClient = new HttpClient { BaseAddress = new Uri(_server.Url!) };
|
||||
_httpClient = _server.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_AtAbsoluteUrl_WhenACallWasNotMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -46,7 +43,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived0Calls_AtAbsoluteUrl_WhenACallWasNotMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(0).Calls()
|
||||
@@ -54,9 +51,9 @@ 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").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -64,19 +61,19 @@ 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").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
.AtAbsoluteUrl2($"http://localhost:{_portUsed}/anyurl");
|
||||
.AtAbsoluteUrl($"http://localhost:{_portUsed}/anyurl");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_WhenAPostCallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anyurl", new StringContent(""), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -88,9 +85,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived2Calls_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(2).Calls()
|
||||
@@ -100,7 +97,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -110,7 +107,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrlWildcardMatcher_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -132,7 +129,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsoluteUrl_Should_ThrowWhenNoCallsMatchingTheAbsoluteUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -146,7 +143,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_AtAbsolutePath_WhenACallWasNotMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -156,7 +153,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived0Calls_AtAbsolutePath_WhenACallWasNotMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("xxx").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("xxx", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(0).Calls()
|
||||
@@ -164,9 +161,9 @@ 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").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -174,9 +171,9 @@ 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("")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anypath", new StringContent(""), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(1).Calls()
|
||||
@@ -188,9 +185,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceived2Calls_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceived(2).Calls()
|
||||
@@ -200,7 +197,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePath_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -210,7 +207,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePathWildcardMatcher_WhenACallWasMadeToAbsolutePath_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anypath").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anypath", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -232,7 +229,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtAbsolutePath_Should_ThrowWhenNoCallsMatchingTheAbsolutePathWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -243,11 +240,111 @@ 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()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -258,7 +355,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
public async Task HaveReceivedACall_WithHeader_WhenACallWasMadeWithExpectedHeaderWithValue_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -270,10 +367,10 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("1").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("1", _ct);
|
||||
|
||||
_httpClient.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("EN"));
|
||||
await _httpClient.GetAsync("2").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("2", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -285,7 +382,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -301,7 +398,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -309,7 +406,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
act.Should()
|
||||
.Throw<Exception>()
|
||||
.WithMessage("Expected _server to have been called with Header \"Accept\" and Values {\"missing-value\"}, but didn't find it among the calls with Header(s)*");
|
||||
.WithMessage("Expected _server to have been called with Header \"Accept\" and Values {\"missing-value\"}, but didn't find it among the calls with Header*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -319,7 +416,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
await httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -347,7 +444,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
Authorization = new AuthenticationHeaderValue("Bearer", "invalidToken")
|
||||
}
|
||||
});
|
||||
}, _ct);
|
||||
|
||||
// Act 2
|
||||
var task2 = client2.SendAsync(new HttpRequestMessage(HttpMethod.Get, "/")
|
||||
@@ -356,7 +453,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
Authorization = new AuthenticationHeaderValue("Bearer", "validToken")
|
||||
}
|
||||
});
|
||||
}, _ct);
|
||||
|
||||
await Task.WhenAll(task1, task2);
|
||||
|
||||
@@ -373,7 +470,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrl_WhenACallWasMadeToUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -383,7 +480,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrlWildcardMatcher_WhenACallWasMadeToUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -405,7 +502,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_AtUrl_Should_ThrowWhenNoCallsMatchingTheUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -423,7 +520,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -453,7 +550,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -467,7 +564,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
_server.Should()
|
||||
@@ -490,7 +587,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_FromClientIP_Should_ThrowWhenNoCallsFromClientIPWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("", _ct);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
Action act = () => _server.Should()
|
||||
@@ -505,7 +602,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedNoCalls_UsingPost_WhenACallWasNotMadeUsingPost_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
await _httpClient.GetAsync("anyurl", _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedNoCalls()
|
||||
@@ -517,9 +614,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
var tasks = new[]
|
||||
{
|
||||
_httpClient.DeleteAsync("anyurl"),
|
||||
_httpClient.DeleteAsync("anyurl"),
|
||||
_httpClient.GetAsync("anyurl")
|
||||
_httpClient.DeleteAsync("anyurl", _ct),
|
||||
_httpClient.DeleteAsync("anyurl", _ct),
|
||||
_httpClient.GetAsync("anyurl", _ct)
|
||||
};
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -544,7 +641,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingOptions_Should_ThrowWhenCallsWereNotMadeUsingOptions()
|
||||
{
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("anycontent")).ConfigureAwait(false);
|
||||
await _httpClient.PostAsync("anyurl", new StringContent("anycontent"), _ct);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -555,7 +652,6 @@ public class WireMockAssertionsTests : IDisposable
|
||||
.WithMessage("Expected _server to have been called using method \"OPTIONS\", but didn't find it among the methods {\"POST\"}.");
|
||||
}
|
||||
|
||||
#if !NET452
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingConnect_WhenACallWasMadeUsingConnect_Should_BeOK()
|
||||
{
|
||||
@@ -565,18 +661,17 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
_httpClient.DefaultRequestHeaders.Add("Host", new Uri(_server.Urls[0]).Authority);
|
||||
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("CONNECT"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("CONNECT"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
.UsingConnect();
|
||||
}
|
||||
#endif
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingDelete_WhenACallWasMadeUsingDelete_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("DELETE"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("DELETE"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -586,7 +681,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingGet_WhenACallWasMadeUsingGet_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -596,7 +691,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingHead_WhenACallWasMadeUsingHead_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("HEAD"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("HEAD"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -606,7 +701,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingOptions_WhenACallWasMadeUsingOptions_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("OPTIONS"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("OPTIONS"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -618,7 +713,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[InlineData("Post")]
|
||||
public async Task HaveReceivedACall_UsingPost_WhenACallWasMadeUsingPost_Should_BeOK(string method)
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod(method), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -626,7 +721,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HaveReceived1Calls_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
public async Task HaveReceived1Call_AtAbsoluteUrlUsingPost_ShouldChain()
|
||||
{
|
||||
// Arrange
|
||||
var server = WireMockServer.Start();
|
||||
@@ -648,9 +743,9 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
var tasks = new[]
|
||||
{
|
||||
httpClient.GetAsync($"{server.Url}/a"),
|
||||
httpClient.PostAsync($"{server.Url}/b", new StringContent("B")),
|
||||
httpClient.PostAsync($"{server.Url}/c", new StringContent("C"))
|
||||
httpClient.GetAsync($"{server.Url}/a", _ct),
|
||||
httpClient.PostAsync($"{server.Url}/b", new StringContent("B"), _ct),
|
||||
httpClient.PostAsync($"{server.Url}/c", new StringContent("C"), _ct)
|
||||
};
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
@@ -703,7 +798,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingPatch_WhenACallWasMadeUsingPatch_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PATCH"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -713,7 +808,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingPut_WhenACallWasMadeUsingPut_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PUT"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("PUT"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -723,7 +818,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingTrace_WhenACallWasMadeUsingTrace_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("TRACE"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("TRACE"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -733,7 +828,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
[Fact]
|
||||
public async Task HaveReceivedACall_UsingAnyMethod_WhenACallWasMadeUsingGet_Should_BeOK()
|
||||
{
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl")).ConfigureAwait(false);
|
||||
await _httpClient.SendAsync(new HttpRequestMessage(new HttpMethod("GET"), "anyurl"), _ct);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -781,7 +876,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -836,7 +931,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
x = "y"
|
||||
};
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody);
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody, _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -891,7 +986,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
{
|
||||
x = "123"
|
||||
};
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody);
|
||||
await httpClient.PostAsJsonAsync($"{server.Url}/a", requestBody, _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -922,7 +1017,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("123"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("123"), _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -953,7 +1048,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new ByteArrayContent([5]));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new ByteArrayContent([5]), _ct);
|
||||
|
||||
// Assert
|
||||
Action act = () => server
|
||||
@@ -984,7 +1079,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PutAsync($"{server.Url}/a", new ByteArrayContent([100]));
|
||||
await httpClient.PutAsync($"{server.Url}/a", new ByteArrayContent([100]), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -1027,7 +1122,7 @@ public class WireMockAssertionsTests : IDisposable
|
||||
// Act
|
||||
var httpClient = new HttpClient();
|
||||
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"));
|
||||
await httpClient.PostAsync($"{server.Url}/a", new StringContent("x"), _ct);
|
||||
|
||||
// Assert
|
||||
server
|
||||
@@ -1065,13 +1160,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
// Act : HTTP GET
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(server.Url!);
|
||||
await httpClient.GetAsync(server.Url, _ct);
|
||||
|
||||
// Act : HTTP POST
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url!);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url);
|
||||
request.Headers.Add("TestHeader", ["Value", "Value2"]);
|
||||
|
||||
await httpClient.SendAsync(request);
|
||||
await httpClient.SendAsync(request, _ct);
|
||||
|
||||
// Assert
|
||||
server.Should().HaveReceivedACall().UsingPost().And.WithHeader("TestHeader", ["Value", "Value2"]);
|
||||
@@ -1090,13 +1185,13 @@ public class WireMockAssertionsTests : IDisposable
|
||||
|
||||
// Act : HTTP GET
|
||||
using var httpClient = new HttpClient();
|
||||
await httpClient.GetAsync(server.Url!);
|
||||
await httpClient.GetAsync(server.Url, _ct);
|
||||
|
||||
// Act : HTTP POST
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url!);
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, server.Url);
|
||||
request.Headers.Add("TestHeader", ["Value", "Value2"]);
|
||||
|
||||
await httpClient.SendAsync(request);
|
||||
await httpClient.SendAsync(request, _ct);
|
||||
|
||||
// Assert
|
||||
server.Should().HaveReceivedACall().UsingPost().And.WitHeaderKey("TestHeader");
|
||||
|
||||
Reference in New Issue
Block a user