Compare commits

..

12 Commits

Author SHA1 Message Date
Stef Heyenrath
8151119cca 1.8.11 2025-06-11 12:04:21 +02:00
Stef Heyenrath
77000372c6 Fix for WithTransformer and JsonBody as list (#1315)
* Fix for WithTransformer and JsonBody as list

* Fix WithTransformer when the response BodyAsJson is a List
2025-06-11 11:51:29 +02:00
Stef Heyenrath
ec248a9a78 Fix TestcontainersTests to ignore exception when stopping (#1314) 2025-06-11 11:12:58 +02:00
Stef Heyenrath
2f7e3a3178 Update TestcontainersTests to ignore exception when stopping 2025-06-11 10:21:42 +02:00
Stef Heyenrath
ac9c51e34e Update RandomDataGenerator.Net to 1.0.19 (#1313)
* Update RandomDataGenerator.Net to 1.0.19

* Handlebars.Net.Helpers
2025-06-11 09:00:23 +02:00
Sébastien Crocquesel
8ba243ddcd Bump Testcontainers version to 4.5.0 (#1311)
* Bump Testcontainers version to 4.5.0

The Testcontainers dependency Docker.DotNet was bumped to 3.128.1 and is not binary compatible with previous version.
When a user has a direct dependency on Testcontainers 4.5.0, WireMock.Net.Testcontainers fails with :

System.MissingMethodException : Method not found: 'Docker.DotNet.DockerClient Docker.DotNet.DockerClientConfiguration.CreateClient(System.Version)'

* Bump System.Net.Http.Json version to 8.0.1

Minimum required version for Testcontainers 4.5.0

* Do not dispose null container
2025-06-10 22:23:56 +02:00
Stef Heyenrath
d4b95e73ea Remove unit test which uses postman-echo 2025-06-10 13:16:24 +02:00
Stef Heyenrath
f9ae045847 Images/Icons 2025-06-10 12:23:07 +02:00
Stef Heyenrath
05b5876b5c 1.8.10 2025-06-10 08:15:22 +02:00
Stef Heyenrath
c1bd2d315f Update AwesomeAssertions to version 9 (#1309) 2025-06-06 21:06:38 +02:00
Stef Heyenrath
8917a6eaaa For some projects, change dependency to WireMock.Net.Minimal (#1308) 2025-06-06 11:22:34 +02:00
Stef Heyenrath
3cc9040f51 Update RequestModelBuilder (add WithHeader) (#1306)
* Update RequestModelBuilder (add WithHeader)

* rejectOnMatch

* fix
2025-06-05 12:24:40 +02:00
28 changed files with 204 additions and 102 deletions

View File

@@ -1,3 +1,17 @@
# 1.8.11 (11 June 2025)
- [#1311](https://github.com/wiremock/WireMock.Net/pull/1311) - Bump Testcontainers version to 4.5.0 [feature] contributed by [scrocquesel](https://github.com/scrocquesel)
- [#1313](https://github.com/wiremock/WireMock.Net/pull/1313) - Update RandomDataGenerator.Net to 1.0.19 [feature] contributed by [StefH](https://github.com/StefH)
- [#1315](https://github.com/wiremock/WireMock.Net/pull/1315) - Fix for WithTransformer and JsonBody as list [bug] contributed by [StefH](https://github.com/StefH)
- [#1310](https://github.com/wiremock/WireMock.Net/issues/1310) - Binary compat issue with testcontainers 4.5.0 [bug]
- [#1312](https://github.com/wiremock/WireMock.Net/issues/1312) - WithTransformer breaks when the response BodyAsJson is a List [bug]
# 1.8.10 (10 June 2025)
- [#1306](https://github.com/wiremock/WireMock.Net/pull/1306) - Update RequestModelBuilder (add WithHeader) [feature] contributed by [StefH](https://github.com/StefH)
- [#1308](https://github.com/wiremock/WireMock.Net/pull/1308) - For some projects, change dependency to WireMock.Net.Minimal [feature] contributed by [StefH](https://github.com/StefH)
- [#1309](https://github.com/wiremock/WireMock.Net/pull/1309) - Update AwesomeAssertions to version 9 [feature] contributed by [StefH](https://github.com/StefH)
- [#1305](https://github.com/wiremock/WireMock.Net/issues/1305) - AdminApiMappingBuilder do not expose WithHeader for Request [feature]
- [#1307](https://github.com/wiremock/WireMock.Net/issues/1307) - Update WireMock.Net.AwesomeAssertions to use latest version from AwesomeAssertions [feature]
# 1.8.9 (28 May 2025)
- [#1303](https://github.com/wiremock/WireMock.Net/pull/1303) - Add option to provide X509Certificate [feature] contributed by [StefH](https://github.com/StefH)
- [#1302](https://github.com/wiremock/WireMock.Net/issues/1302) - Support In-Memory SSL Certificate [feature]

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.8.9</VersionPrefix>
<VersionPrefix>1.8.11</VersionPrefix>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

View File

@@ -1,6 +1,6 @@
rem https://github.com/StefH/GitHubReleaseNotes
SET version=1.8.9
SET version=1.8.11
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels wontfix test question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%

View File

@@ -1,5 +1,8 @@
# 1.8.8 (28 May 2025)
- #1303 Add option to provide X509Certificate [feature]
- #1302 Support In-Memory SSL Certificate [feature]
# 1.8.11 (11 June 2025)
- #1311 Bump Testcontainers version to 4.5.0 [feature]
- #1313 Update RandomDataGenerator.Net to 1.0.19 [feature]
- #1315 Fix for WithTransformer and JsonBody as list [bug]
- #1310 Binary compat issue with testcontainers 4.5.0 [bug]
- #1312 WithTransformer breaks when the response BodyAsJson is a List [bug]
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md

View File

@@ -1,4 +1,4 @@
# WireMock.Net
# ![Project Icon](./resources/logo_32x32.png) WireMock.Net
A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) which mimics the functionality from the JAVA based [WireMock](http://wiremock.org).
For more info, see also this WIKI page: [What is WireMock.Net](https://github.com/wiremock/WireMock.Net/wiki/What-Is-WireMock.Net).

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

BIN
resources/logo_32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -138,4 +138,27 @@ public partial class RequestModelBuilder
return builder.Build();
});
}
/// <summary>
/// WithHeader: matching based on name, pattern and matchBehaviour.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="pattern">The pattern.</param>
/// <param name="rejectOnMatch">The match behaviour. Default value is <c>false</c>.</param>
/// <returns>The <see cref="RequestModelBuilder"/>.</returns>
public RequestModelBuilder WithHeader(string name, string pattern, bool rejectOnMatch = false)
{
return WithHeaders(headersBuilder => headersBuilder
.Add(headerBuilder => headerBuilder
.WithName(name)
.WithMatchers(matchersBuilder => matchersBuilder
.Add(matcherBuilder => matcherBuilder
.WithName("WildcardMatcher")
.WithPattern(pattern)
.WithRejectOnMatch(rejectOnMatch)
)
)
)
);
}
}

View File

@@ -42,7 +42,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
<ProjectReference Include="..\WireMock.Net.Minimal\WireMock.Net.Minimal.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,6 @@
// Copyright © WireMock.Net
using FluentAssertions.Primitives;
using AwesomeAssertions.Primitives;
using WireMock.Server;
// ReSharper disable once CheckNamespace

View File

@@ -1,5 +1,5 @@
// Copyright © WireMock.Net
global using System.Linq;
global using FluentAssertions;
global using FluentAssertions.Execution;
global using AwesomeAssertions;
global using AwesomeAssertions.Execution;

View File

@@ -32,11 +32,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AwesomeAssertions" Version="8.1.0" />
<PackageReference Include="AwesomeAssertions" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
<ProjectReference Include="..\WireMock.Net.Minimal\WireMock.Net.Minimal.csproj" />
</ItemGroup>
</Project>

View File

@@ -40,7 +40,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
<ProjectReference Include="..\WireMock.Net.Minimal\WireMock.Net.Minimal.csproj" />
</ItemGroup>
</Project>

View File

@@ -34,7 +34,7 @@
<Target Name="CheckIfShouldKillVBCSCompiler" />
<ItemGroup>
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
<ProjectReference Include="..\WireMock.Net.Minimal\WireMock.Net.Minimal.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'net452' ">

View File

@@ -1,6 +1,7 @@
// Copyright © WireMock.Net
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using HandlebarsDotNet.Helpers.Models;
@@ -170,8 +171,8 @@ internal class Transformer : ITransformer
WalkNode(transformerContext, options, jToken, model);
break;
case Array bodyAsArray:
jToken = JArray.FromObject(bodyAsArray, _jsonSerializer);
case var bodyAsEnumerable when bodyAsEnumerable is IEnumerable and not string:
jToken = JArray.FromObject(bodyAsEnumerable, _jsonSerializer);
WalkNode(transformerContext, options, jToken, model);
break;

View File

@@ -157,13 +157,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Handlebars.Net.Helpers" Version="2.5.0" />
<!--<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.5.0" />-->
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.5.0" />
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.5.0" />
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.5.0" />
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.5.0" />
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.5.0" />
<PackageReference Include="Handlebars.Net.Helpers" Version="2.5.2" />
<!--<PackageReference Include="Handlebars.Net.Helpers.DynamicLinq" Version="2.5.2" />-->
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.5.2" />
<PackageReference Include="Handlebars.Net.Helpers.Json" Version="2.5.2" />
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.5.2" />
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.5.2" />
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.5.2" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard1.3' and '$(TargetFramework)' != 'net451' and '$(TargetFramework)' != 'net452' ">

View File

@@ -29,7 +29,7 @@
</PackageReference>
<PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.8.0" />
<PackageReference Include="YamlDotNet" Version="8.1.0" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.18" />
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.19" />
<PackageReference Include="Stef.Validation" Version="0.1.1" />
</ItemGroup>

View File

@@ -39,11 +39,11 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Stef.Validation" Version="0.1.1" />
<PackageReference Include="Testcontainers" Version="4.0.0" />
<PackageReference Include="Testcontainers" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WireMock.Net.RestClient\WireMock.Net.RestClient.csproj" />
</ItemGroup>
</Project>

View File

@@ -15,6 +15,19 @@
Methods: [
POST
],
Headers: [
{
Name: Authorization,
Matchers: [
{
Name: WildcardMatcher,
Pattern: *,
IgnoreCase: false,
RejectOnMatch: true
}
]
}
],
Body: {
Matcher: {
Name: JsonPartialMatcher,

View File

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using FluentAssertions;
using VerifyTests;
using VerifyXunit;
using WireMock.Admin.Mappings;
using WireMock.Client;
using WireMock.Client.Extensions;
using WireMock.Net.Tests.VerifyExtensions;
@@ -41,6 +42,7 @@ public class AdminApiMappingBuilderTests
.WithRequest(req => req
.UsingPost()
.WithPath("/bla1")
.WithHeader("Authorization", "*", true)
.WithBody(body => body
.WithMatcher(matcher => matcher
.WithName("JsonPartialMatcher")

View File

@@ -69,7 +69,7 @@ public partial class TestcontainersTests
}
finally
{
await wireMockContainer.StopAsync();
await StopAsync(wireMockContainer);
}
}
@@ -121,7 +121,7 @@ public partial class TestcontainersTests
}
finally
{
await wireMockContainer.StopAsync();
await StopAsync(wireMockContainer);
}
}
@@ -136,7 +136,7 @@ public partial class TestcontainersTests
Then_ReplyMessage_Should_BeCorrect(reply);
await wireMockContainer.StopAsync();
await StopAsync(wireMockContainer);
}
[Fact]
@@ -150,7 +150,7 @@ public partial class TestcontainersTests
Then_ReplyMessage_Should_BeCorrect(reply);
await wireMockContainer.StopAsync();
await StopAsync(wireMockContainer);
}
private static async Task<WireMockContainer> Given_WireMockContainerIsStartedForHttpAndGrpcAsync()

View File

@@ -11,10 +11,11 @@ using WireMock.Net.Testcontainers;
using WireMock.Net.Testcontainers.Utils;
using WireMock.Net.Tests.Facts;
using Xunit;
using Xunit.Abstractions;
namespace WireMock.Net.Tests.Testcontainers;
public partial class TestcontainersTests
public partial class TestcontainersTests(ITestOutputHelper testOutputHelper)
{
[Fact]
public async Task WireMockContainer_Build_And_StartAsync_and_StopAsync()
@@ -28,7 +29,8 @@ public partial class TestcontainersTests
.WithAdminUserNameAndPassword(adminUsername, adminPassword)
.Build();
await StartTestAndStopAsync(wireMockContainer);
await StartTestAsync(wireMockContainer);
await StopAsync(wireMockContainer);
}
// https://github.com/testcontainers/testcontainers-dotnet/issues/1322
@@ -48,7 +50,8 @@ public partial class TestcontainersTests
.WithCleanUp(true)
.Build();
await StartTestAndStopAsync(wireMockContainer);
await StartTestAsync(wireMockContainer);
await StopAsync(wireMockContainer);
}
[Fact]
@@ -74,7 +77,8 @@ public partial class TestcontainersTests
var wireMockContainer = wireMockContainerBuilder.Build();
await StartTestAndStopAsync(wireMockContainer);
await StartTestAsync(wireMockContainer);
await StopAsync(wireMockContainer);
}
[Fact]
@@ -100,31 +104,48 @@ public partial class TestcontainersTests
var wireMockContainer = wireMockContainerBuilder.Build();
await StartTestAndStopAsync(wireMockContainer);
await StartTestAsync(wireMockContainer);
await StopAsync(wireMockContainer);
}
private static async Task StartTestAndStopAsync(WireMockContainer wireMockContainer)
private static async Task StartTestAsync(WireMockContainer wireMockContainer)
{
// Start
await wireMockContainer.StartAsync().ConfigureAwait(false);
// Assert
using (new AssertionScope())
{
var url = wireMockContainer.GetPublicUrl();
url.Should().NotBeNullOrWhiteSpace();
var adminClient = wireMockContainer.CreateWireMockAdminClient();
var settings = await adminClient.GetSettingsAsync();
settings.Should().NotBeNull();
}
}
private async Task StopAsync(WireMockContainer wireMockContainer)
{
try
{
await wireMockContainer.StartAsync().ConfigureAwait(false);
// Assert
using (new AssertionScope())
{
var url = wireMockContainer.GetPublicUrl();
url.Should().NotBeNullOrWhiteSpace();
var adminClient = wireMockContainer.CreateWireMockAdminClient();
var settings = await adminClient.GetSettingsAsync();
settings.Should().NotBeNull();
}
}
finally
{
await wireMockContainer.StopAsync();
}
catch (Exception ex)
{
// Sometimes we get this exception, so for now ignore it.
/*
Failed WireMock.Net.Tests.Testcontainers.TestcontainersTests.WireMockContainer_Build_WithImageAsText_And_StartAsync_and_StopAsync [9 s]
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
at DotNet.Testcontainers.Containers.DockerContainer.UnsafeStopAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 567
at DotNet.Testcontainers.Containers.DockerContainer.StopAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 319
*/
testOutputHelper.WriteLine($"Exception during StopAsync: {ex}");
}
}
}
#endif

View File

@@ -102,7 +102,7 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net452'">
<PackageReference Include="System.Net.Http.Json" Version="3.2.1" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.1" />
<PackageReference Include="JsonConverter.System.Text.Json" Version="0.7.0" />
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
<PackageReference Include="Grpc.Net.Client" Version="2.60.0" />

View File

@@ -924,49 +924,4 @@ public class WireMockServerProxyTests
server.LogEntries.Should().HaveCount(1);
server.Stop();
}
[Fact]
public async Task WireMockServer_ProxyAndRecordSettings_SameRequest_ShouldProxyAll()
{
//Arrange
var wireMockServerSettings = new WireMockServerSettings
{
Urls = new[] { "http://localhost:19091" },
ProxyAndRecordSettings = new ProxyAndRecordSettings
{
Url = "http://postman-echo.com",
SaveMapping = true,
ProxyAll = true,
SaveMappingToFile = false,
ExcludedHeaders = new[] { "Postman-Token" },
ExcludedCookies = new[] { "sails.sid" }
}
};
var server = WireMockServer.Start(wireMockServerSettings);
var requestBody = "{\"key1\": \"value1\", \"key2\": \"value2\"}";
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("http://localhost:19091/post"),
Content = new StringContent(requestBody)
};
var request2 = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("http://localhost:19091/post"),
Content = new StringContent(requestBody)
};
server.ResetMappings();
//Act
await new HttpClient().SendAsync(request);
await new HttpClient().SendAsync(request2);
//Assert
Check.That(server.Mappings.Count()).IsEqualTo(3);
server.Dispose();
}
}

View File

@@ -1,12 +1,11 @@
// Copyright © WireMock.Net
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using FluentAssertions;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
using Xunit;
@@ -44,6 +43,78 @@ public partial class WireMockServerTests
response.Should().Contain("Hello, Stef!");
}
[Fact]
public async Task WireMockServer_WithTransformer_WithJsonBodyAsArray_ShouldWork()
{
// Arrange
using var server = WireMockServer.Start();
server
.WhenRequest(req => req
.WithPath("/withbody")
.UsingPost()
)
.ThenRespondWith(rsp => rsp
.WithSuccess()
.WithBodyAsJson(new[]
{
new
{
test = "test",
secret = true
},
new
{
test = "123",
secret = false
}
}
)
.WithTransformer()
);
// Act
var response = await GetResponseAsync(server, "/withbody");
// Assert
response.Should().Be("""[{"test":"test","secret":true},{"test":"123","secret":false}]""");
}
[Fact]
public async Task WireMockServer_WithTransformer_WithJsonBodyAsList_ShouldWork()
{
// Arrange
using var server = WireMockServer.Start();
server
.WhenRequest(req => req
.WithPath("/withbody")
.UsingPost()
)
.ThenRespondWith(rsp => rsp
.WithSuccess()
.WithBodyAsJson(
new List<object>
{
new
{
test = "test",
secret = true
},
new
{
test = "123",
secret = false
}
})
.WithTransformer()
);
// Act
var response = await GetResponseAsync(server, "/withbody");
// Assert
response.Should().Be("""[{"test":"test","secret":true},{"test":"123","secret":false}]""");
}
[Fact]
public async Task WireMockServer_WithTransformerBefore_WithBodyFromFile_ShouldWork()
{
@@ -88,8 +159,7 @@ public partial class WireMockServerTests
private static async Task<string> GetResponseAsync(WireMockServer server, string relativePath)
{
using HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(server.Urls[0]);
using var httpClient = server.CreateClient();
using var requestContent = new StringContent(RequestXml);
using var responseMsg = await httpClient.PostAsync(relativePath, requestContent);