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:
Stef Heyenrath
2026-03-11 17:02:47 +01:00
committed by GitHub
parent d6e19532bc
commit a292f28dda
521 changed files with 79740 additions and 5246 deletions

View File

@@ -1,19 +1,13 @@
// Copyright © WireMock.Net
#if !NET452
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests;
@@ -28,7 +22,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_MultipleJmesPathMatchers_ShouldMatch()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create()
.WithPath("/a")
@@ -61,7 +56,7 @@ public partial class WireMockServerTests
var requestUri = new Uri($"http://localhost:{server.Port}/a");
var json = new { requestId = "1", value = "A" };
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json).ConfigureAwait(false);
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json, cancellationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -73,7 +68,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_MultipleJmesPathMatchers_ShouldMatch_BestMatching()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create()
.WithPath("/a")
@@ -109,7 +105,7 @@ public partial class WireMockServerTests
var requestUri = new Uri($"http://localhost:{server.Port}/a");
var json = new { extra = "X", requestId = "1", value = "A" };
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json).ConfigureAwait(false);
var response = await server.CreateClient().PostAsJsonAsync(requestUri, json, cancellationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -121,7 +117,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsJsonAsync_And_WildcardMatcher_ShouldMatch()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create().UsingPost().WithPath("/foo").WithBody(new WildcardMatcher("*Hello*"))
)
@@ -135,7 +132,7 @@ public partial class WireMockServerTests
};
// Act
var response = await new HttpClient().PostAsJsonAsync("http://localhost:" + server.Ports[0] + "/foo", jsonObject).ConfigureAwait(false);
var response = await new HttpClient().PostAsJsonAsync("http://localhost:" + server.Ports[0] + "/foo", jsonObject, cancellationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -147,7 +144,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsync_And_WildcardMatcher_ShouldMatch()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create().UsingPost().WithPath("/foo").WithBody(new WildcardMatcher("*Hello*"))
)
@@ -156,7 +154,7 @@ public partial class WireMockServerTests
);
// Act
var response = await new HttpClient().PostAsync("http://localhost:" + server.Ports[0] + "/foo", new StringContent("{ Hi = \"Hello World\" }")).ConfigureAwait(false);
var response = await new HttpClient().PostAsync("http://localhost:" + server.Ports[0] + "/foo", new StringContent("{ Hi = \"Hello World\" }"), cancellationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -168,6 +166,7 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsync_And_JsonPartialWildcardMatcher_ShouldMatch()
{
// Arrange
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
var matcher = new JsonPartialWildcardMatcher(new { method = "initialize", id = "^[a-f0-9]{32}-[0-9]$" }, ignoreCase: true, regex: true);
@@ -189,13 +188,13 @@ public partial class WireMockServerTests
// Act
var content = "{\"jsonrpc\":\"2.0\",\"id\":\"ec475f56d4694b48bc737500ba575b35-1\",\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2024-11-05\",\"capabilities\":{},\"clientInfo\":{\"name\":\"GitHub Test\",\"version\":\"1.0.0\"}}}";
var response = await new HttpClient()
.PostAsync($"{server.Url}/foo", new StringContent(content, Encoding.UTF8, "application/json"))
.ConfigureAwait(false);
.PostAsync($"{server.Url}/foo", new StringContent(content, Encoding.UTF8, "application/json"), cancellationToken)
;
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var responseText = await response.Content.ReadAsStringAsync();
var responseText = await response.Content.ReadAsStringAsync(cancellationToken);
responseText.Should().Contain("ec475f56d4694b48bc737500ba575b35-1");
}
@@ -204,6 +203,7 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsJson_Using_PostAsync_And_JsonPartialWildcardMatcher_And_SystemTextJson_ShouldMatch()
{
// Arrange
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start(x => x.DefaultJsonSerializer = new JsonConverter.System.Text.Json.SystemTextJsonConverter() );
var matcher = new JsonPartialWildcardMatcher(new { id = "^[a-f0-9]{32}-[0-9]$" }, ignoreCase: true, regex: true);
@@ -219,14 +219,13 @@ public partial class WireMockServerTests
// Act
var content = """{"id":"ec475f56d4694b48bc737500ba575b35-1"}""";
var response = await new HttpClient()
.PostAsync($"{server.Url}/system-text-json", new StringContent(content, Encoding.UTF8, "application/json"))
.ConfigureAwait(false);
using var httpClient = new HttpClient();
var response = await httpClient.PostAsync($"{server.Url}/system-text-json", new StringContent(content, Encoding.UTF8, "application/json"), cancellationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var responseText = await response.Content.ReadAsStringAsync();
var responseText = await response.Content.ReadAsStringAsync(cancellationToken);
responseText.Should().Contain("OK");
}
#endif
@@ -235,6 +234,7 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithFunc()
{
// Arrange
var cancelationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create()
@@ -249,8 +249,7 @@ public partial class WireMockServerTests
// Act
var content = new FormUrlEncodedContent([new KeyValuePair<string, string>("key1", "value1")]);
var response = await new HttpClient()
.PostAsync($"{server.Url}/foo", content)
.ConfigureAwait(false);
.PostAsync($"{server.Url}/foo", content, cancelationToken);
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -262,7 +261,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithExactMatcher()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server.Given(
Request.Create()
.UsingPost()
@@ -276,15 +276,14 @@ public partial class WireMockServerTests
);
// Act
var content = new FormUrlEncodedContent(new[]
{
var content = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("name", "John Doe"),
new KeyValuePair<string, string>("email", "johndoe@example.com")
});
var response = await new HttpClient()
.PostAsync($"{server.Url}/foo", content)
.ConfigureAwait(false);
]);
using var httpClient = new HttpClient();
var response = await httpClient.PostAsync($"{server.Url}/foo", content, cancellationToken)
;
// Assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -295,8 +294,9 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithBodyAsFormUrlEncoded_Using_PostAsync_And_WithFormUrlEncodedMatcher()
{
// Arrange
var cancelationToken = TestContext.Current.CancellationToken;
var matcher = new FormUrlEncodedMatcher(["email=johndoe@example.com", "name=John Doe"]);
var server = WireMockServer.Start();
using var server = WireMockServer.Start();
server.Given(
Request.Create()
.UsingPost()
@@ -320,28 +320,28 @@ public partial class WireMockServerTests
);
// Act 1
var contentOrdered = new FormUrlEncodedContent(new[]
{
var contentOrdered = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("name", "John Doe"),
new KeyValuePair<string, string>("email", "johndoe@example.com")
});
]);
var responseOrdered = await new HttpClient()
.PostAsync($"{server.Url}/foo", contentOrdered)
.ConfigureAwait(false);
.PostAsync($"{server.Url}/foo", contentOrdered, cancelationToken)
;
// Assert 1
responseOrdered.StatusCode.Should().Be(HttpStatusCode.OK);
// Act 2
var contentUnordered = new FormUrlEncodedContent(new[]
{
var contentUnordered = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("email", "johndoe@example.com"),
new KeyValuePair<string, string>("name", "John Doe"),
});
]);
var responseUnordered = await new HttpClient()
.PostAsync($"{server.Url}/bar", contentUnordered)
.ConfigureAwait(false);
.PostAsync($"{server.Url}/bar", contentUnordered, cancelationToken)
;
// Assert 2
responseUnordered.StatusCode.Should().Be(HttpStatusCode.OK);
@@ -353,7 +353,8 @@ public partial class WireMockServerTests
public async Task WireMockServer_WithSseBody()
{
// Arrange
var server = WireMockServer.Start();
var cancellationToken = TestContext.Current.CancellationToken;
using var server = WireMockServer.Start();
server
.WhenRequest(r => r
.UsingGet()
@@ -386,24 +387,22 @@ public partial class WireMockServerTests
using var client = new HttpClient();
// Act 1
var normal = await new HttpClient()
.GetAsync(server.Url)
.ConfigureAwait(false);
(await normal.Content.ReadAsStringAsync()).Should().Be("normal");
var normal = await client.GetAsync(server.Url, cancellationToken)
;
(await normal.Content.ReadAsStringAsync(cancellationToken)).Should().Be("normal");
// Act 2
using var response = await client.GetStreamAsync($"{server.Url}/sse");
using var response = await client.GetStreamAsync($"{server.Url}/sse", _ct);
using var reader = new StreamReader(response);
var data = string.Empty;
while (!reader.EndOfStream)
{
var line = await reader.ReadLineAsync();
var line = reader.ReadLine();
data += line;
}
// Assert 2
data.Should().Be("x 1;x 2;x 3;");
}
}
#endif
}