mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-11-16 22:01:26 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5589e1e2f | ||
|
|
cb4503b1a6 | ||
|
|
dd762f218b | ||
|
|
b0f9924933 | ||
|
|
dc4cdfae50 | ||
|
|
f19d94acae | ||
|
|
90819f031e | ||
|
|
471745f704 | ||
|
|
7db5b562d8 | ||
|
|
e4389333a1 | ||
|
|
f0969e9618 | ||
|
|
84f4109a7c | ||
|
|
ee0f890795 | ||
|
|
2b165eb6a1 | ||
|
|
42353f035e | ||
|
|
7e9718eab7 | ||
|
|
a0df0916f9 | ||
|
|
7a8582fef5 | ||
|
|
05929bdea6 | ||
|
|
84c32d5b2d | ||
|
|
d39f7c771f | ||
|
|
97c8e4a08a | ||
|
|
f5eb01c580 | ||
|
|
8260dba641 | ||
|
|
5e1c126e34 | ||
|
|
ca4eea808e | ||
|
|
5692498ea3 | ||
|
|
d270ad7f4f | ||
|
|
345efe8cfc | ||
|
|
a74468e780 | ||
|
|
041160d824 | ||
|
|
4666757df9 | ||
|
|
49dcbda647 |
No files matched your search
@@ -1,36 +0,0 @@
|
|||||||
name: "Copilot Setup Steps"
|
|
||||||
|
|
||||||
# Automatically run the setup steps when they are changed to allow for easy validation, and
|
|
||||||
# allow manual testing through the repository's "Actions" tab
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
push:
|
|
||||||
paths:
|
|
||||||
- .github/workflows/copilot-setup-steps.yml
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- .github/workflows/copilot-setup-steps.yml
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.
|
|
||||||
copilot-setup-steps:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
# Set the permissions to the lowest permissions possible needed for your steps.
|
|
||||||
# Copilot will be given its own token for its operations.
|
|
||||||
permissions:
|
|
||||||
# If you want to clone the repository as part of your setup steps, for example to install dependencies, you'll need the `contents: read` permission. If you don't clone the repository in your setup steps, Copilot will do this for you automatically after the steps complete.
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
# You can define any steps you want, and they will run before the agent starts.
|
|
||||||
# If you do not check out your code, Copilot will do this for you.
|
|
||||||
steps:
|
|
||||||
- name: Install .NET 10.x
|
|
||||||
uses: actions/setup-dotnet@v5
|
|
||||||
with:
|
|
||||||
dotnet-version: |
|
|
||||||
10.x
|
|
||||||
dotnet-quality: preview
|
|
||||||
|
|
||||||
- name: dotnet --info
|
|
||||||
run: dotnet --info
|
|
||||||
@@ -1,3 +1,46 @@
|
|||||||
|
# 2.19.0 (07 October 2026)
|
||||||
|
- [#1512](https://github.com/wiremock/WireMock.Net/pull/1512) - Use IDateTimeUtils in WireMockWebSocketContext [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1514](https://github.com/wiremock/WireMock.Net/pull/1514) - Fix DateTime in Response [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1511](https://github.com/wiremock/WireMock.Net/issues/1511) - Incorrect response datetime for mapped response [bug]
|
||||||
|
|
||||||
|
# 2.18.0 (22 September 2026)
|
||||||
|
- [#1510](https://github.com/wiremock/WireMock.Net/pull/1510) - WireMock.Net.OpenApiParser: fix depencency on RamlToOpenApiConverter.SourceOnly [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1508](https://github.com/wiremock/WireMock.Net/issues/1508) - Transitive Dependency Conflict with Microsoft.OpenApi in 2.16.0 [bug]
|
||||||
|
|
||||||
|
# 2.17.0 (21 September 2026)
|
||||||
|
- [#1509](https://github.com/wiremock/WireMock.Net/pull/1509) - Revert to RamlToOpenApiConverter.SourceOnly [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|
||||||
|
# 2.16.0 (19 September 2026)
|
||||||
|
- [#1502](https://github.com/wiremock/WireMock.Net/pull/1502) - Fix #1501: Generate WhenStateIs/WillSetStateTo correctly in ToCSharpCode contributed by [Bafyn](https://github.com/Bafyn)
|
||||||
|
- [#1503](https://github.com/wiremock/WireMock.Net/pull/1503) - Fix FormUrlEncodedMatcher (+ refactor values / matchers logic) contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1504](https://github.com/wiremock/WireMock.Net/pull/1504) - Update SharpYaml package to version 2.5.1 [dependencies] contributed by [johnthcall](https://github.com/johnthcall)
|
||||||
|
- [#1505](https://github.com/wiremock/WireMock.Net/pull/1505) - Upgrade dependency RamlToOpenApiConverter to version 0.40.0 [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1500](https://github.com/wiremock/WireMock.Net/issues/1500) - Sending a form-urlencoded body with a repeated field name returns HTTP 500 [bug]
|
||||||
|
- [#1501](https://github.com/wiremock/WireMock.Net/issues/1501) - Generated C# code for stateful (Scenario) mappings does not compile and drops the WhenStateIs condition [bug]
|
||||||
|
|
||||||
|
# 2.15.0 (15 August 2026)
|
||||||
|
- [#1495](https://github.com/wiremock/WireMock.Net/pull/1495) - Fix #1494: `WithClientIP(MatchOperator, params IStringMatcher[])` ignores the MatchOperator argument [bug] contributed by [Bafyn](https://github.com/Bafyn)
|
||||||
|
- [#1497](https://github.com/wiremock/WireMock.Net/pull/1497) - Fix WithParam RejectOnMatch inverting the match result #1496 [bug] contributed by [Bafyn](https://github.com/Bafyn)
|
||||||
|
- [#1499](https://github.com/wiremock/WireMock.Net/pull/1499) - Update Testcontainers [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1494](https://github.com/wiremock/WireMock.Net/issues/1494) - `WithClientIP(MatchOperator, params IStringMatcher[])` ignores the `MatchOperator` argument [bug]
|
||||||
|
- [#1496](https://github.com/wiremock/WireMock.Net/issues/1496) - `WithParam(key, MatchBehaviour.RejectOnMatch, values)` inverts the match result [bug]
|
||||||
|
|
||||||
|
# 2.14.0 (06 August 2026)
|
||||||
|
- [#1493](https://github.com/wiremock/WireMock.Net/pull/1493) - Fix #1492: Serialize WithClientIP matcher to Request.ClientIP [bug] contributed by [Bafyn](https://github.com/Bafyn)
|
||||||
|
- [#1492](https://github.com/wiremock/WireMock.Net/issues/1492) - `WithClientIP` matcher is lost / corrupted when a mapping is serialized [bug]
|
||||||
|
|
||||||
|
# 2.13.0 (19 July 2026)
|
||||||
|
- [#1488](https://github.com/wiremock/WireMock.Net/pull/1488) - feat(xunit logging): TestOutputHelperWireMockLogger [feature] contributed by [Stepami](https://github.com/Stepami)
|
||||||
|
- [#1490](https://github.com/wiremock/WireMock.Net/pull/1490) - Fix: Fully respect configured custom admin path (merge PR #1483) [feature] contributed by [Copilot](https://github.com/apps/copilot-swe-agent)
|
||||||
|
- [#1482](https://github.com/wiremock/WireMock.Net/issues/1482) - WireMock.Minimal.Owin does not respect custom pathing for determining admin paths [bug]
|
||||||
|
|
||||||
|
# 2.12.0 (07 July 2026)
|
||||||
|
- [#1479](https://github.com/wiremock/WireMock.Net/pull/1479) - Upgrade Microsoft.OpenApi to 3.7.0 and YamlDotNet to 18.1.0 [security] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1480](https://github.com/wiremock/WireMock.Net/pull/1480) - Upgrade RamlToOpenApiConverter.SourceOnly to 0.21.0 [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1484](https://github.com/wiremock/WireMock.Net/pull/1484) - Update Scriban.Signed package version to 7.2.5 [security] contributed by [johnthcall](https://github.com/johnthcall)
|
||||||
|
- [#1487](https://github.com/wiremock/WireMock.Net/pull/1487) - Response.Create() sets the DateTime to UtcNow [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#1486](https://github.com/wiremock/WireMock.Net/issues/1486) - ResponseMessage.DateTime defaults to DateTime.MinValue, causing premature log entry purging for *matched* requests [bug]
|
||||||
|
|
||||||
# 2.11.0 (12 June 2026)
|
# 2.11.0 (12 June 2026)
|
||||||
- [#1475](https://github.com/wiremock/WireMock.Net/pull/1475) - Update NuGet packages (Aspire, MessagePack and more) [security] contributed by [StefH](https://github.com/StefH)
|
- [#1475](https://github.com/wiremock/WireMock.Net/pull/1475) - Update NuGet packages (Aspire, MessagePack and more) [security] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#1476](https://github.com/wiremock/WireMock.Net/pull/1476) - Fix BodyParser [bug] contributed by [StefH](https://github.com/StefH)
|
- [#1476](https://github.com/wiremock/WireMock.Net/pull/1476) - Fix BodyParser [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>2.11.0</VersionPrefix>
|
<VersionPrefix>2.18.0</VersionPrefix>
|
||||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
@@ -51,8 +51,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2025.2.4" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2026.2.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.401" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
rem https://github.com/StefH/GitHubReleaseNotes
|
rem https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
SET version=2.11.0
|
SET version=2.19.0
|
||||||
|
|
||||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels wontfix test question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%
|
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels wontfix test question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 2.11.0 (12 June 2026)
|
# 2.19.0 (07 October 2026)
|
||||||
- #1475 Update NuGet packages (Aspire, MessagePack and more) [security]
|
- #1512 Use IDateTimeUtils in WireMockWebSocketContext [bug]
|
||||||
- #1476 Fix BodyParser [bug]
|
- #1514 Fix DateTime in Response [bug]
|
||||||
- #1473 JsonPartialWildCardMatcher With DateTime Regex Stopped Matching (Regression?) [bug]
|
- #1511 Incorrect response datetime for mapped response [bug]
|
||||||
|
|
||||||
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md
|
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
parameters:
|
||||||
|
- name: runWindowsReleaseToMyGet
|
||||||
|
displayName: Run Windows Release to MyGet
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
Prerelease: 'ci'
|
Prerelease: 'ci'
|
||||||
buildId: "1$(Build.BuildId)"
|
buildId: "1$(Build.BuildId)"
|
||||||
@@ -131,6 +137,7 @@ jobs:
|
|||||||
|
|
||||||
- job: Windows_Release_to_MyGet
|
- job: Windows_Release_to_MyGet
|
||||||
dependsOn: Windows_Build_Test
|
dependsOn: Windows_Build_Test
|
||||||
|
condition: and(succeeded(), ${{ parameters.runWindowsReleaseToMyGet }})
|
||||||
|
|
||||||
pool:
|
pool:
|
||||||
vmImage: 'windows-2025'
|
vmImage: 'windows-2025'
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RestEase;
|
using RestEase;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace WireMock.Net.Console.MimePart;
|
|||||||
|
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()!);
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||||
|
|
||||||
static async Task Main(params string[] args)
|
static async Task Main(params string[] args)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
|
|||||||
@@ -1,14 +1,8 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SharpYaml.Model;
|
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
@@ -291,11 +285,21 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
var server = WireMockServer.Start(new WireMockServerSettings
|
var server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
|
StartAdminInterface = true,
|
||||||
Logger = new WireMockConsoleLogger(),
|
Logger = new WireMockConsoleLogger(),
|
||||||
|
|
||||||
Port = 9091
|
Port = 9091
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server
|
||||||
|
.WhenRequest(r => r
|
||||||
|
.WithPath("/test")
|
||||||
|
.UsingAnyMethod()
|
||||||
|
)
|
||||||
|
.ThenRespondWith(r => r
|
||||||
|
.WithStatusCode(HttpStatusCode.OK)
|
||||||
|
.WithBody("OK")
|
||||||
|
);
|
||||||
|
|
||||||
server
|
server
|
||||||
.WhenRequest(r => r
|
.WhenRequest(r => r
|
||||||
.WithPath("/Content-Length")
|
.WithPath("/Content-Length")
|
||||||
@@ -1115,7 +1119,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
{
|
{
|
||||||
BodyData = new BodyData
|
BodyData = new BodyData
|
||||||
{
|
{
|
||||||
BodyAsString = "random200or505:" + code + ", HeadersFromRequest = " + string.Join(",", request.Headers),
|
BodyAsString = "random200or505:" + code + ", HeadersFromRequest = " + request.Headers != null ? string.Join(",", request.Headers!.Select(h => $"{h.Key}:{h.Value}")) : "none",
|
||||||
DetectedBodyType = BodyType.String,
|
DetectedBodyType = BodyType.String,
|
||||||
},
|
},
|
||||||
StatusCode = code
|
StatusCode = code
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using log4net;
|
using log4net;
|
||||||
using log4net.Config;
|
using log4net.Config;
|
||||||
using log4net.Repository;
|
using log4net.Repository;
|
||||||
@@ -12,8 +10,7 @@ namespace WireMock.Net.Console.NET8;
|
|||||||
|
|
||||||
static class Program
|
static class Program
|
||||||
{
|
{
|
||||||
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()!);
|
||||||
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
|
||||||
|
|
||||||
static async Task Main(params string[] args)
|
static async Task Main(params string[] args)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Net.StandAlone;
|
using WireMock.Net.StandAlone;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="WireMock.Net" Version="2.10.0" />
|
<PackageReference Include="WireMock.Net" Version="2.15.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
|
|
||||||
|
|||||||
+1
-6
@@ -6,18 +6,13 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.3.0" />
|
|
||||||
|
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj" />
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(Configuration)' == 'Release'">
|
<ItemGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
<PackageReference Include="Microsoft.OpenApi" Version="2.3.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.OpenApi" Version="3.10.2" PrivateAssets="All" />
|
||||||
<!--<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.3.0" PrivateAssets="All" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="8.0.5" />
|
|
||||||
<PackageReference Include="SharpYaml" Version="2.1.3" />-->
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -36,12 +36,6 @@
|
|||||||
<StartupObject>Wiremock.Net.Service.Program</StartupObject>
|
<StartupObject>Wiremock.Net.Service.Program</StartupObject>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="SimMetrics.Net, Version=1.0.5.0, Culture=neutral, PublicKeyToken=c58dc06d59f3391b, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
@@ -91,13 +85,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="log4net">
|
<PackageReference Include="log4net">
|
||||||
<Version>3.3.0</Version>
|
<Version>3.3.2</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core">
|
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core">
|
||||||
<Version>2.3.9</Version>
|
<Version>2.3.11</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="WireMock.Net">
|
<PackageReference Include="WireMock.Net">
|
||||||
<Version>2.10.0</Version>
|
<Version>2.12.0</Version>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public interface IRequestMessage
|
|||||||
string? ProxyUrl { get; set; }
|
string? ProxyUrl { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the DateTime.
|
/// The DateTime when this request was done.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DateTime DateTime { get; }
|
DateTime DateTime { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public interface IResponseMessage
|
|||||||
object? StatusCode { get; set; }
|
object? StatusCode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the DateTime.
|
/// The DateTime when this response was sent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
DateTime DateTime { get; }
|
DateTime DateTime { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public interface IBodyData
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body as Form UrlEncoded dictionary.
|
/// The body as Form UrlEncoded dictionary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IDictionary<string, string>? BodyAsFormUrlEncoded { get; set; }
|
IDictionary<string, WireMockList<string>>? BodyAsFormUrlEncoded { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The detected body type (detection based on body content).
|
/// The detected body type (detection based on body content).
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace WireMock.Types;
|
namespace WireMock.Types;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A special List which overrides the ToString() to return first value.
|
/// A special List which overrides the ToString() to return first value in case of a single element.
|
||||||
|
/// Else it will return a comma separated list of all values.
|
||||||
|
/// If null or empty, it will return an empty string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">The generic type</typeparam>
|
/// <typeparam name="T">The generic type</typeparam>
|
||||||
/// <seealso cref="List{T}" />
|
/// <seealso cref="List{T}" />
|
||||||
@@ -46,6 +46,98 @@ public class WireMockList<T> : List<T>
|
|||||||
/// <param name="values">The values to set.</param>
|
/// <param name="values">The values to set.</param>
|
||||||
public static implicit operator WireMockList<T>(T[] values) => new(values);
|
public static implicit operator WireMockList<T>(T[] values) => new(values);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Operator for equality comparison from WireMockList to T
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator ==(WireMockList<T>? left, T? right)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(left, right))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left?.Count == 1 && Equals(left[0], right))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Operator for equality comparison from T to WireMockList
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator ==(T? left, WireMockList<T>? right)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(left, right))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (right?.Count == 1 && Equals(left, right[0]))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Operator for inequality comparison from WireMockList to T
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator !=(WireMockList<T>? left, T? right) => !(left == right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Operator for inequality comparison from T to WireMockList
|
||||||
|
/// </summary>
|
||||||
|
public static bool operator !=(T? left, WireMockList<T>? right) => !(left == right);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the specified object is equal to the current instance.
|
||||||
|
/// Two <see cref="WireMockList{T}"/> instances are equal if they contain the same elements in the same order.
|
||||||
|
/// </summary>
|
||||||
|
public override bool Equals(object? obj)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(this, obj))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj is WireMockList<T> other)
|
||||||
|
{
|
||||||
|
if (Count != other.Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (!Equals(this[i], other[i]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a hash code for this instance based on its elements.
|
||||||
|
/// </summary>
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
var hashCode = 17;
|
||||||
|
foreach (var item in this)
|
||||||
|
{
|
||||||
|
hashCode = hashCode * 31 + (item?.GetHashCode() ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="string" /> that represents this instance.
|
/// Returns a <see cref="string" /> that represents this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -62,10 +154,10 @@ public class WireMockList<T> : List<T>
|
|||||||
return strValue;
|
return strValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this[0]?.ToString();
|
return this[0]?.ToString() ?? string.Empty;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var strings = this.Select(x => x as string ?? x?.ToString());
|
var strings = this.Select(x => x as string ?? x?.ToString() ?? string.Empty);
|
||||||
return string.Join(", ", strings);
|
return string.Join(", ", strings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class CSharpCodeMatcher : ICSharpCodeMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(CSharpCodeMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ public class SystemTextJsonPathMatcher : ISystemTextJsonPathMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(SystemTextJsonPathMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace WireMock.Extensions;
|
||||||
|
|
||||||
|
internal static class HttpContextExtensions
|
||||||
|
{
|
||||||
|
internal static bool TryGet<T>(this HttpContext httpContext, [NotNullWhen(true)] out T? value)
|
||||||
|
{
|
||||||
|
return httpContext.Items.TryGetValue(nameof(T), out value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,10 +80,10 @@ public class ContentTypeMatcher : WildcardMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(ContentTypeMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
|
$"new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}" +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}" +
|
||||||
$")";
|
$")";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class ExactMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(ExactMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Extensions;
|
using WireMock.Extensions;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
namespace WireMock.Matchers;
|
||||||
@@ -21,7 +21,7 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
private readonly List<(WildcardMatcher Key, WildcardMatcher? Value)> _pairs = [];
|
private readonly List<(WildcardMatcher Key, WildcardMatcher[]? Values)> KeyValueMatchers = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FormUrlEncodedMatcher"/> class.
|
/// Initializes a new instance of the <see cref="FormUrlEncodedMatcher"/> class.
|
||||||
@@ -91,9 +91,10 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
{
|
{
|
||||||
foreach (var nameValue in nameValueCollection)
|
foreach (var nameValue in nameValueCollection)
|
||||||
{
|
{
|
||||||
var keyMatcher = new WildcardMatcher(MatchBehaviour.AcceptOnMatch, [nameValue.Key], ignoreCase, MatchOperator);
|
var keyMatcher = new WildcardMatcher(MatchBehaviour.AcceptOnMatch, nameValue.Key, ignoreCase);
|
||||||
var valueMatcher = new WildcardMatcher(MatchBehaviour.AcceptOnMatch, [nameValue.Value], ignoreCase, MatchOperator);
|
var valueMatchers = nameValue.Value.Select(value => new WildcardMatcher(MatchBehaviour.AcceptOnMatch, value, ignoreCase)).ToArray();
|
||||||
_pairs.Add((keyMatcher, valueMatcher));
|
|
||||||
|
KeyValueMatchers.Add((keyMatcher, valueMatchers));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,34 +120,48 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
return MatchResult.From(Name, MatchBehaviourHelper.Convert(MatchBehaviour, score));
|
return MatchResult.From(Name, MatchBehaviourHelper.Convert(MatchBehaviour, score));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool[] GetMatches(IDictionary<string, string> inputNameValueCollection)
|
private List<double> GetMatches(IDictionary<string, WireMockList<string>> inputNameValueCollection)
|
||||||
{
|
{
|
||||||
var matches = new List<bool>();
|
var inputPairs = inputNameValueCollection.ToArray();
|
||||||
if (_pairs.Count > inputNameValueCollection.Count)
|
var rowCount = inputPairs.Length;
|
||||||
|
var columnCount = KeyValueMatchers.Count;
|
||||||
|
|
||||||
|
if (rowCount == 0 && columnCount == 0)
|
||||||
{
|
{
|
||||||
matches.AddRange(Enumerable.Repeat(false, _pairs.Count - inputNameValueCollection.Count));
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var inputKeyValuePair in inputNameValueCollection)
|
var matrix = new double[rowCount][];
|
||||||
|
|
||||||
|
for (var row = 0; row < rowCount; row++)
|
||||||
{
|
{
|
||||||
var match = false;
|
matrix[row] = new double[columnCount];
|
||||||
foreach (var pair in _pairs)
|
|
||||||
|
var inputKeyValuePair = inputPairs[row];
|
||||||
|
var inputKey = inputKeyValuePair.Key;
|
||||||
|
var inputValues = inputKeyValuePair.Value;
|
||||||
|
|
||||||
|
for (var column = 0; column < columnCount; column++)
|
||||||
{
|
{
|
||||||
var keyMatchResult = pair.Key.IsMatch(inputKeyValuePair.Key).IsPerfect();
|
var (keyMatcher, valuesMatchers) = KeyValueMatchers[column];
|
||||||
if (keyMatchResult)
|
|
||||||
{
|
|
||||||
match = pair.Value?.IsMatch(inputKeyValuePair.Value).IsPerfect() ?? false;
|
|
||||||
if (match)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
matches.Add(match);
|
var keyScore = keyMatcher.IsMatch(inputKey).Score;
|
||||||
|
var valueScore = valuesMatchers != null ? MatchScores.ToScore(inputValues, valuesMatchers) : MatchScores.Perfect;
|
||||||
|
|
||||||
|
matrix[row][column] = Math.Min(keyScore, valueScore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return matches.ToArray();
|
var rowScores = rowCount == 0 ? [] : matrix.Select(row => row.Length == 0 ? MatchScores.Mismatch : row.Max()).ToList();
|
||||||
|
|
||||||
|
var columnScores = new List<double>();
|
||||||
|
for (var column = 0; column < columnCount; column++)
|
||||||
|
{
|
||||||
|
columnScores.Add(rowCount == 0 ? MatchScores.Mismatch : matrix.Max(row => row[column]));
|
||||||
|
}
|
||||||
|
|
||||||
|
rowScores.AddRange(columnScores);
|
||||||
|
return rowScores;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -167,10 +182,10 @@ public class FormUrlEncodedMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(FormUrlEncodedMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
|
$"new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
||||||
$")";
|
$")";
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class FuncMatcher : IFuncMatcher
|
|||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
var funcType = _stringFunc != null ? "Func<string?, bool>" : "Func<byte[]?, bool>";
|
var funcType = _stringFunc != null ? "Func<string?, bool>" : "Func<byte[]?, bool>";
|
||||||
return $"new {Name}" +
|
return $"new {typeof(FuncMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"/* {funcType} function */, " +
|
$"/* {funcType} function */, " +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class JsonPathMatcher : IJsonPathMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(JsonPathMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class JmesPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(JmesPathMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string GetCSharpCodeArguments()
|
public virtual string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(JsonMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class JsonPartialMatcher : AbstractJsonPartialMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(JsonPartialMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class JsonPartialWildcardMatcher : AbstractJsonPartialMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(JsonPartialWildcardMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public class LinqMatcher : IObjectMatcher, IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(LinqMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Matchers.Helpers;
|
using WireMock.Matchers.Helpers;
|
||||||
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request;
|
namespace WireMock.Matchers.Request;
|
||||||
@@ -34,7 +35,7 @@ public class RequestMessageBodyMatcher : IRequestMatcher
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body data function for FormUrlEncoded
|
/// The body data function for FormUrlEncoded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Func<IDictionary<string, string>?, bool>? MatchOnBodyAsFormUrlEncodedFunc { get; }
|
public Func<IDictionary<string, WireMockList<string>>?, bool>? MatchOnBodyAsFormUrlEncodedFunc { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The matchers.
|
/// The matchers.
|
||||||
@@ -116,7 +117,7 @@ public class RequestMessageBodyMatcher : IRequestMatcher
|
|||||||
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The function.</param>
|
/// <param name="func">The function.</param>
|
||||||
public RequestMessageBodyMatcher(Func<IDictionary<string, string>?, bool> func)
|
public RequestMessageBodyMatcher(Func<IDictionary<string, WireMockList<string>>?, bool> func)
|
||||||
{
|
{
|
||||||
MatchOnBodyAsFormUrlEncodedFunc = Guard.NotNull(func);
|
MatchOnBodyAsFormUrlEncodedFunc = Guard.NotNull(func);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
@@ -54,7 +53,10 @@ public class RequestMessageParamMatcher : IRequestMatcher
|
|||||||
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, params string[]? values) :
|
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, string key, bool ignoreCase, params string[]? values) :
|
||||||
this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, ignoreCase, MatchOperator.And, value)).Cast<IStringMatcher>().ToArray())
|
// Note: the inner ExactMatcher must use AcceptOnMatch.
|
||||||
|
// The MatchBehaviour (e.g. RejectOnMatch) is applied once by this matcher's GetMatchingScore.
|
||||||
|
// Passing matchBehaviour here as well would apply the conversion twice and invert RejectOnMatch.
|
||||||
|
this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(MatchBehaviour.AcceptOnMatch, ignoreCase, MatchOperator.And, value)).Cast<IStringMatcher>().ToArray())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,36 +115,6 @@ public class RequestMessageParamMatcher : IRequestMatcher
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the score based on Matchers and valuesPresentInRequestMessage
|
// Return the score based on Matchers and valuesPresentInRequestMessage
|
||||||
return CalculateScore(Matchers, valuesPresentInRequestMessage);
|
return MatchScores.ToScore(valuesPresentInRequestMessage, Matchers.ToArray());
|
||||||
}
|
|
||||||
|
|
||||||
private static double CalculateScore(IReadOnlyList<IStringMatcher> matchers, WireMockList<string> valuesPresentInRequestMessage)
|
|
||||||
{
|
|
||||||
var total = new List<double>();
|
|
||||||
|
|
||||||
// If the total patterns in all matchers > values in message, use the matcher as base
|
|
||||||
if (matchers.Sum(m => m.GetPatterns().Length) > valuesPresentInRequestMessage.Count)
|
|
||||||
{
|
|
||||||
foreach (var matcher in matchers)
|
|
||||||
{
|
|
||||||
double score = 0d;
|
|
||||||
foreach (string valuePresentInRequestMessage in valuesPresentInRequestMessage)
|
|
||||||
{
|
|
||||||
score += matcher.IsMatch(valuePresentInRequestMessage).Score / matcher.GetPatterns().Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
total.Add(score);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (string valuePresentInRequestMessage in valuesPresentInRequestMessage)
|
|
||||||
{
|
|
||||||
var score = matchers.Max(m => m.IsMatch(valuePresentInRequestMessage).Score);
|
|
||||||
total.Add(score);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return total.Any() ? MatchScores.ToScore(total, MatchOperator.Average) : 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using SimMetrics.Net;
|
using SimMetrics.Net;
|
||||||
using SimMetrics.Net.API;
|
using SimMetrics.Net.API;
|
||||||
@@ -92,10 +91,10 @@ public class SimMetricsMatcher : IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string GetCSharpCodeArguments()
|
public virtual string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(SimMetricsMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
|
$"new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
|
||||||
$"{_simMetricType.GetFullyQualifiedEnumValue()}, " +
|
$"{_simMetricType.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
||||||
$")";
|
$")";
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public class SystemTextJsonMatcher : IJsonMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string GetCSharpCodeArguments()
|
public virtual string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(SystemTextJsonMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class SystemTextJsonPartialMatcher : AbstractSystemTextJsonPartialMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(SystemTextJsonPartialMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class SystemTextJsonPartialWildcardMatcher : AbstractSystemTextJsonPartia
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(SystemTextJsonPartialWildcardMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
$"{CSharpFormatter.ConvertToAnonymousObjectDefinition(Value, 3)}, " +
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class XPathMatcher : IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(XPathMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}, " +
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using WireMock.Matchers;
|
||||||
|
|
||||||
|
namespace WireMock.Owin;
|
||||||
|
|
||||||
|
internal sealed class AdminPaths(string? adminPath) : IAdminPaths
|
||||||
|
{
|
||||||
|
private const string DefaultAdminPathPrefix = "/__admin";
|
||||||
|
|
||||||
|
private readonly string _prefix = adminPath ?? DefaultAdminPathPrefix;
|
||||||
|
|
||||||
|
public string Files => $"{_prefix}/files";
|
||||||
|
|
||||||
|
public string Health => $"{_prefix}/health";
|
||||||
|
|
||||||
|
public string Mappings => $"{_prefix}/mappings";
|
||||||
|
|
||||||
|
public string MappingsCode => $"{_prefix}/mappings/code";
|
||||||
|
|
||||||
|
public string MappingsWireMockOrg => $"{_prefix}/mappings/wiremock.org";
|
||||||
|
|
||||||
|
public string Requests => $"{_prefix}/requests";
|
||||||
|
|
||||||
|
public string Settings => $"{_prefix}/settings";
|
||||||
|
|
||||||
|
public string Scenarios => $"{_prefix}/scenarios";
|
||||||
|
|
||||||
|
public string OpenApi => $"{_prefix}/openapi";
|
||||||
|
|
||||||
|
public string ProtoDefinitions => $"{_prefix}/protodefinitions";
|
||||||
|
|
||||||
|
private string PrefixRegexEscaped => Regex.Escape(_prefix);
|
||||||
|
|
||||||
|
public RegexMatcher MappingsGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||||
|
|
||||||
|
public RegexMatcher MappingsGuidEnablePathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\/enable$");
|
||||||
|
|
||||||
|
public RegexMatcher MappingsGuidDisablePathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\/disable$");
|
||||||
|
|
||||||
|
public RegexMatcher MappingsCodeGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/mappings\/code\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||||
|
|
||||||
|
public RegexMatcher RequestsGuidPathMatcher => new($@"^{PrefixRegexEscaped}\/requests\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
||||||
|
|
||||||
|
public RegexMatcher ScenariosNameMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+$");
|
||||||
|
|
||||||
|
public RegexMatcher ScenariosNameWithStateMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+\/state$");
|
||||||
|
|
||||||
|
public RegexMatcher ScenariosNameWithResetMatcher => new($@"^{PrefixRegexEscaped}\/scenarios\/.+\/reset$");
|
||||||
|
|
||||||
|
public RegexMatcher FilesFilenamePathMatcher => new($@"^{PrefixRegexEscaped}\/files\/.+$");
|
||||||
|
|
||||||
|
public RegexMatcher ProtoDefinitionsIdPathMatcher => new($@"^{PrefixRegexEscaped}\/protodefinitions\/.+$");
|
||||||
|
|
||||||
|
public bool Includes(string? path) => path?.StartsWith($"{_prefix}/") ?? false;
|
||||||
|
|
||||||
|
public override string ToString() => _prefix;
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@ internal partial class AspNetCoreSelfHost
|
|||||||
.ConfigureServices(services =>
|
.ConfigureServices(services =>
|
||||||
{
|
{
|
||||||
services.AddSingleton(_wireMockMiddlewareOptions);
|
services.AddSingleton(_wireMockMiddlewareOptions);
|
||||||
|
services.AddSingleton(_wireMockMiddlewareOptions.AdminPaths);
|
||||||
services.AddSingleton<IMappingMatcher, MappingMatcher>();
|
services.AddSingleton<IMappingMatcher, MappingMatcher>();
|
||||||
services.AddSingleton<IRandomizerDoubleBetween0And1, RandomizerDoubleBetween0And1>();
|
services.AddSingleton<IRandomizerDoubleBetween0And1, RandomizerDoubleBetween0And1>();
|
||||||
services.AddSingleton<IOwinRequestMapper, OwinRequestMapper>();
|
services.AddSingleton<IOwinRequestMapper, OwinRequestMapper>();
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using WireMock.Matchers;
|
||||||
|
|
||||||
|
namespace WireMock.Owin;
|
||||||
|
|
||||||
|
internal interface IAdminPaths
|
||||||
|
{
|
||||||
|
string Files { get; }
|
||||||
|
|
||||||
|
string Health { get; }
|
||||||
|
|
||||||
|
string Mappings { get; }
|
||||||
|
|
||||||
|
string MappingsCode { get; }
|
||||||
|
|
||||||
|
string MappingsWireMockOrg { get; }
|
||||||
|
|
||||||
|
RegexMatcher MappingsGuidPathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher MappingsGuidEnablePathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher MappingsGuidDisablePathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher MappingsCodeGuidPathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher RequestsGuidPathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher ScenariosNameMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher ScenariosNameWithStateMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher ScenariosNameWithResetMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher FilesFilenamePathMatcher { get; }
|
||||||
|
|
||||||
|
RegexMatcher ProtoDefinitionsIdPathMatcher { get; }
|
||||||
|
|
||||||
|
string Requests { get; }
|
||||||
|
|
||||||
|
string Settings { get; }
|
||||||
|
|
||||||
|
string Scenarios { get; }
|
||||||
|
|
||||||
|
string OpenApi { get; }
|
||||||
|
|
||||||
|
string ProtoDefinitions { get; }
|
||||||
|
|
||||||
|
bool Includes(string? path);
|
||||||
|
}
|
||||||
@@ -108,4 +108,6 @@ internal interface IWireMockMiddlewareOptions
|
|||||||
/// Set this property to customize how objects are serialized to and deserialized from JSON during mapping.
|
/// Set this property to customize how objects are serialized to and deserialized from JSON during mapping.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
IJsonConverter DefaultJsonSerializer { get; set; }
|
IJsonConverter DefaultJsonSerializer { get; set; }
|
||||||
|
|
||||||
|
IAdminPaths AdminPaths { get; set; }
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,7 @@ namespace WireMock.Owin.Mappers;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// OwinRequestMapper
|
/// OwinRequestMapper
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class OwinRequestMapper : IOwinRequestMapper
|
internal class OwinRequestMapper(IDateTimeUtils dateTimeUtils) : IOwinRequestMapper
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<RequestMessage> MapAsync(HttpContext context, IWireMockMiddlewareOptions options)
|
public async Task<RequestMessage> MapAsync(HttpContext context, IWireMockMiddlewareOptions options)
|
||||||
@@ -72,7 +72,7 @@ internal class OwinRequestMapper : IOwinRequestMapper
|
|||||||
await request.HttpContext.Connection.GetClientCertificateAsync()
|
await request.HttpContext.Connection.GetClientCertificateAsync()
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = dateTimeUtils.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ internal class WireMockMiddleware(
|
|||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
#pragma warning restore CS9113 // Parameter is unread.
|
#pragma warning restore CS9113 // Parameter is unread.
|
||||||
IWireMockMiddlewareOptions options,
|
IWireMockMiddlewareOptions options,
|
||||||
|
IAdminPaths adminPaths,
|
||||||
IOwinRequestMapper requestMapper,
|
IOwinRequestMapper requestMapper,
|
||||||
IOwinResponseMapper responseMapper,
|
IOwinResponseMapper responseMapper,
|
||||||
IMappingMatcher mappingMatcher,
|
IMappingMatcher mappingMatcher,
|
||||||
@@ -64,7 +65,7 @@ internal class WireMockMiddleware(
|
|||||||
Activity? activity = null;
|
Activity? activity = null;
|
||||||
|
|
||||||
// Check if we should trace this request (optionally exclude admin requests)
|
// Check if we should trace this request (optionally exclude admin requests)
|
||||||
var shouldTrace = tracingEnabled && !(excludeAdmin && request.Path.StartsWith("/__admin/"));
|
var shouldTrace = tracingEnabled && !(excludeAdmin && adminPaths.Includes(request.Path));
|
||||||
|
|
||||||
if (shouldTrace)
|
if (shouldTrace)
|
||||||
{
|
{
|
||||||
@@ -170,6 +171,12 @@ internal class WireMockMiddleware(
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
// Set the DateTime from the Response to the current DateTime
|
||||||
|
if (response is ResponseMessage responseMessage)
|
||||||
|
{
|
||||||
|
responseMessage.DateTime = dateTimeUtils.UtcNow;
|
||||||
|
}
|
||||||
|
|
||||||
logger.LogRequestAndResponse(logRequest, request, response, result.Match, result.Partial, activity);
|
logger.LogRequestAndResponse(logRequest, request, response, result.Match, result.Partial, activity);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -254,4 +261,4 @@ internal class WireMockMiddleware(
|
|||||||
scenario.Finished = mapping.NextState == null;
|
scenario.Finished = mapping.NextState == null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,39 +9,44 @@ using WireMock.Util;
|
|||||||
namespace WireMock.Owin;
|
namespace WireMock.Owin;
|
||||||
|
|
||||||
internal class WireMockMiddlewareLogger(
|
internal class WireMockMiddlewareLogger(
|
||||||
IWireMockMiddlewareOptions _options,
|
IWireMockMiddlewareOptions options,
|
||||||
LogEntryMapper _logEntryMapper,
|
LogEntryMapper logEntryMapper,
|
||||||
IGuidUtils _guidUtils
|
IGuidUtils guidUtils,
|
||||||
|
IAdminPaths adminPaths,
|
||||||
|
IDateTimeUtils dateTimeUtils
|
||||||
) : IWireMockMiddlewareLogger
|
) : IWireMockMiddlewareLogger
|
||||||
{
|
{
|
||||||
public void LogRequestAndResponse(bool logRequest, RequestMessage request, IResponseMessage? response, MappingMatcherResult? match, MappingMatcherResult? partialMatch, Activity? activity)
|
public void LogRequestAndResponse(bool logRequest, RequestMessage request, IResponseMessage? response, MappingMatcherResult? match, MappingMatcherResult? partialMatch, Activity? activity)
|
||||||
{
|
{
|
||||||
|
var mapping = match?.Mapping;
|
||||||
|
var partialMapping = partialMatch?.Mapping;
|
||||||
|
|
||||||
var logEntry = new LogEntry
|
var logEntry = new LogEntry
|
||||||
{
|
{
|
||||||
Guid = _guidUtils.NewGuid(),
|
Guid = guidUtils.NewGuid(),
|
||||||
RequestMessage = request,
|
RequestMessage = request,
|
||||||
ResponseMessage = response,
|
ResponseMessage = response,
|
||||||
|
|
||||||
MappingGuid = match?.Mapping?.Guid,
|
MappingGuid = mapping?.Guid,
|
||||||
MappingTitle = match?.Mapping?.Title,
|
MappingTitle = mapping?.Title,
|
||||||
RequestMatchResult = match?.RequestMatchResult,
|
RequestMatchResult = match?.RequestMatchResult,
|
||||||
|
|
||||||
PartialMappingGuid = partialMatch?.Mapping?.Guid,
|
PartialMappingGuid = partialMapping?.Guid,
|
||||||
PartialMappingTitle = partialMatch?.Mapping?.Title,
|
PartialMappingTitle = partialMapping?.Title,
|
||||||
PartialMatchResult = partialMatch?.RequestMatchResult
|
PartialMatchResult = partialMatch?.RequestMatchResult
|
||||||
};
|
};
|
||||||
|
|
||||||
WireMockActivitySource.EnrichWithLogEntry(activity, logEntry, _options.ActivityTracingOptions);
|
WireMockActivitySource.EnrichWithLogEntry(activity, logEntry, options.ActivityTracingOptions);
|
||||||
activity?.Dispose();
|
activity?.Dispose();
|
||||||
|
|
||||||
LogLogEntry(logEntry, logRequest);
|
LogLogEntry(logEntry, logRequest);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_options.SaveUnmatchedRequests == true && match?.RequestMatchResult is not { IsPerfectMatch: true })
|
if (options.SaveUnmatchedRequests == true && match?.RequestMatchResult is not { IsPerfectMatch: true })
|
||||||
{
|
{
|
||||||
var filename = $"{logEntry.Guid}.LogEntry.json";
|
var filename = $"{logEntry.Guid}.LogEntry.json";
|
||||||
_options.FileSystemHandler?.WriteUnmatchedRequest(filename, _options.DefaultJsonSerializer.Serialize(logEntry));
|
options.FileSystemHandler?.WriteUnmatchedRequest(filename, options.DefaultJsonSerializer.Serialize(logEntry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -52,35 +57,36 @@ internal class WireMockMiddlewareLogger(
|
|||||||
|
|
||||||
public void LogLogEntry(LogEntry entry, bool addRequest)
|
public void LogLogEntry(LogEntry entry, bool addRequest)
|
||||||
{
|
{
|
||||||
_options.Logger.DebugRequestResponse(_logEntryMapper.Map(entry), entry.RequestMessage?.Path.StartsWith("/__admin/") == true);
|
var isAdminRequest = adminPaths.Includes(entry.RequestMessage?.Path);
|
||||||
|
options.Logger.DebugRequestResponse(logEntryMapper.Map(entry), isAdminRequest);
|
||||||
|
|
||||||
// If addRequest is set to true and MaxRequestLogCount is null or does have a value greater than 0, try to add a new request log.
|
// If addRequest is set to true and MaxRequestLogCount is null or does have a value greater than 0, try to add a new request log.
|
||||||
if (addRequest && _options.MaxRequestLogCount is null or > 0)
|
if (addRequest && options.MaxRequestLogCount is null or > 0)
|
||||||
{
|
{
|
||||||
TryAddLogEntry(entry);
|
TryAddLogEntry(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// In case MaxRequestLogCount has a value greater than 0, try to delete existing request logs based on the count.
|
// In case MaxRequestLogCount has a value greater than 0, try to delete existing request logs based on the count.
|
||||||
if (_options.MaxRequestLogCount is > 0)
|
if (options.MaxRequestLogCount is > 0)
|
||||||
{
|
{
|
||||||
var logEntries = _options.LogEntries.ToList();
|
var logEntries = options.LogEntries.ToList();
|
||||||
|
|
||||||
foreach (var logEntry in logEntries
|
foreach (var logEntry in logEntries
|
||||||
.OrderBy(le => le.RequestMessage?.DateTime ?? le.ResponseMessage?.DateTime)
|
.OrderBy(le => le.RequestMessage?.DateTime)
|
||||||
.Take(logEntries.Count - _options.MaxRequestLogCount.Value))
|
.Take(logEntries.Count - options.MaxRequestLogCount.Value))
|
||||||
{
|
{
|
||||||
TryRemoveLogEntry(logEntry);
|
TryRemoveLogEntry(logEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case RequestLogExpirationDuration has a value greater than 0, try to delete existing request logs based on the date.
|
// In case RequestLogExpirationDuration has a value greater than 0, try to delete existing request logs based on the RequestMessage date.
|
||||||
if (_options.RequestLogExpirationDuration is > 0)
|
if (options.RequestLogExpirationDuration is > 0)
|
||||||
{
|
{
|
||||||
var logEntries = _options.LogEntries.ToList();
|
var logEntries = options.LogEntries.ToList();
|
||||||
|
|
||||||
var checkTime = DateTime.UtcNow.AddHours(-_options.RequestLogExpirationDuration.Value);
|
var checkTime = dateTimeUtils.UtcNow.AddHours(-options.RequestLogExpirationDuration.Value);
|
||||||
foreach (var logEntry in logEntries.Where(le => le.RequestMessage?.DateTime < checkTime || le.ResponseMessage?.DateTime < checkTime))
|
foreach (var logEntry in logEntries.Where(le => le.RequestMessage?.DateTime < checkTime))
|
||||||
{
|
{
|
||||||
TryRemoveLogEntry(logEntry);
|
TryRemoveLogEntry(logEntry);
|
||||||
}
|
}
|
||||||
@@ -91,7 +97,7 @@ internal class WireMockMiddlewareLogger(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_options.LogEntries.Add(logEntry);
|
options.LogEntries.Add(logEntry);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -103,7 +109,7 @@ internal class WireMockMiddlewareLogger(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_options.LogEntries.Remove(logEntry);
|
options.LogEntries.Remove(logEntry);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -115,4 +115,7 @@ internal class WireMockMiddlewareOptions : IWireMockMiddlewareOptions
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IJsonConverter DefaultJsonSerializer { get; set; } = new NewtonsoftJsonConverter();
|
public IJsonConverter DefaultJsonSerializer { get; set; } = new NewtonsoftJsonConverter();
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IAdminPaths AdminPaths { get; set; } = new AdminPaths(null);
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,7 @@ internal static class WireMockMiddlewareOptionsHelper
|
|||||||
options.QueryParameterMultipleValueSupport = settings.QueryParameterMultipleValueSupport;
|
options.QueryParameterMultipleValueSupport = settings.QueryParameterMultipleValueSupport;
|
||||||
options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
||||||
options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
||||||
|
options.AdminPaths = new AdminPaths(settings.AdminPath);
|
||||||
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
options.AdditionalServiceRegistration = settings.AdditionalServiceRegistration;
|
options.AdditionalServiceRegistration = settings.AdditionalServiceRegistration;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public partial class Request
|
|||||||
{
|
{
|
||||||
Guard.NotNullOrEmpty(matchers);
|
Guard.NotNullOrEmpty(matchers);
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Or, matchers));
|
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, matchOperator, matchers));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders;
|
namespace WireMock.RequestBuilders;
|
||||||
@@ -84,7 +85,7 @@ public partial class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRequestBuilder WithBody(Func<IDictionary<string, string>?, bool> func)
|
public IRequestBuilder WithBody(Func<IDictionary<string, WireMockList<string>>?, bool> func)
|
||||||
{
|
{
|
||||||
_requestMatchers.Add(new RequestMessageBodyMatcher(Guard.NotNull(func)));
|
_requestMatchers.Add(new RequestMessageBodyMatcher(Guard.NotNull(func)));
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ using WireMock.RequestBuilders;
|
|||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
using WireMock.Transformers;
|
using WireMock.Transformers;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
|
||||||
|
|
||||||
namespace WireMock.ResponseBuilders;
|
namespace WireMock.ResponseBuilders;
|
||||||
|
|
||||||
@@ -86,7 +85,11 @@ public partial class Response : IResponseBuilder
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static IResponseBuilder Create(ResponseMessage? responseMessage = null)
|
public static IResponseBuilder Create(ResponseMessage? responseMessage = null)
|
||||||
{
|
{
|
||||||
var message = responseMessage ?? new ResponseMessage();
|
var message = responseMessage ?? new ResponseMessage
|
||||||
|
{
|
||||||
|
DateTime = DateTime.UtcNow // Initially, this is set to the current time, but will be updated to the real time once the response has been sent.
|
||||||
|
};
|
||||||
|
|
||||||
return new Response(message);
|
return new Response(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
||||||
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
||||||
using System.Linq;
|
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ internal class WebSocketResponseProvider(WebSocketBuilder builder, IGuidUtils gu
|
|||||||
builder,
|
builder,
|
||||||
options,
|
options,
|
||||||
logger,
|
logger,
|
||||||
guidUtils
|
guidUtils,
|
||||||
|
dateTimeUtils
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add to registry
|
// Add to registry
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ internal class MappingConverter(MatcherMapper mapper)
|
|||||||
|
|
||||||
case JsonMatcher jsonMatcher:
|
case JsonMatcher jsonMatcher:
|
||||||
{
|
{
|
||||||
var matcherType = jsonMatcher.GetType().Name;
|
var matcherType = jsonMatcher.GetType().FullName;
|
||||||
sb.AppendLine($" .WithBody(new {matcherType}(");
|
sb.AppendLine($" .WithBody(new {matcherType}(");
|
||||||
sb.AppendLine($" value: {ConvertToAnonymousObjectDefinition(jsonMatcher.Value, 3)},");
|
sb.AppendLine($" value: {ConvertToAnonymousObjectDefinition(jsonMatcher.Value, 3)},");
|
||||||
sb.AppendLine($" ignoreCase: {ToCSharpBooleanLiteral(jsonMatcher.IgnoreCase)},");
|
sb.AppendLine($" ignoreCase: {ToCSharpBooleanLiteral(jsonMatcher.IgnoreCase)},");
|
||||||
@@ -162,14 +162,18 @@ internal class MappingConverter(MatcherMapper mapper)
|
|||||||
// Guid
|
// Guid
|
||||||
sb.AppendLine($" .WithGuid(\"{mapping.Guid}\")");
|
sb.AppendLine($" .WithGuid(\"{mapping.Guid}\")");
|
||||||
|
|
||||||
// Scenario + State
|
// Scenario, ExecutionConditionState, NextState and StateTimes
|
||||||
if (!string.IsNullOrEmpty(mapping.Scenario))
|
if (!string.IsNullOrEmpty(mapping.Scenario))
|
||||||
{
|
{
|
||||||
sb.AppendLine($" .InScenario({ToCSharpStringLiteral(mapping.Scenario)})");
|
sb.AppendLine($" .InScenario({ToCSharpStringLiteral(mapping.Scenario)})");
|
||||||
}
|
}
|
||||||
|
if (!string.IsNullOrEmpty(mapping.ExecutionConditionState))
|
||||||
|
{
|
||||||
|
sb.AppendLine($" .WhenStateIs({ToCSharpStringLiteral(mapping.ExecutionConditionState)})");
|
||||||
|
}
|
||||||
if (!string.IsNullOrEmpty(mapping.NextState))
|
if (!string.IsNullOrEmpty(mapping.NextState))
|
||||||
{
|
{
|
||||||
sb.AppendLine($" .WhenStateIs({ToCSharpStringLiteral(mapping.NextState)}, {ToCSharpIntLiteral(mapping.TimesInSameState)})");
|
sb.AppendLine($" .WillSetStateTo({ToCSharpStringLiteral(mapping.NextState)}, {ToCSharpIntLiteral(mapping.TimesInSameState)})");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mapping.Probability != null)
|
if (mapping.Probability != null)
|
||||||
@@ -342,7 +346,7 @@ internal class MappingConverter(MatcherMapper mapper)
|
|||||||
if (clientIPMatcher?.Matchers != null)
|
if (clientIPMatcher?.Matchers != null)
|
||||||
{
|
{
|
||||||
var clientIPMatchers = _mapper.Map(clientIPMatcher.Matchers);
|
var clientIPMatchers = _mapper.Map(clientIPMatcher.Matchers);
|
||||||
mappingModel.Request.Path = new ClientIPModel
|
mappingModel.Request.ClientIP = new ClientIPModel
|
||||||
{
|
{
|
||||||
Matchers = clientIPMatchers,
|
Matchers = clientIPMatchers,
|
||||||
MatchOperator = clientIPMatchers?.Length > 1 ? clientIPMatcher.MatchOperator.ToString() : null
|
MatchOperator = clientIPMatchers?.Length > 1 ? clientIPMatcher.MatchOperator.ToString() : null
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ using WireMock.Owin;
|
|||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseProviders;
|
using WireMock.ResponseProviders;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Settings;
|
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
@@ -28,50 +27,16 @@ namespace WireMock.Server;
|
|||||||
public partial class WireMockServer
|
public partial class WireMockServer
|
||||||
{
|
{
|
||||||
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
|
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
|
||||||
private const string DefaultAdminPathPrefix = "/__admin";
|
|
||||||
private const string QueryParamReloadStaticMappings = "reloadStaticMappings";
|
private const string QueryParamReloadStaticMappings = "reloadStaticMappings";
|
||||||
private static readonly Guid ProxyMappingGuid = new("e59914fd-782e-428e-91c1-4810ffb86567");
|
private static readonly Guid ProxyMappingGuid = new("e59914fd-782e-428e-91c1-4810ffb86567");
|
||||||
private static readonly RegexMatcher AdminRequestContentTypeJson = new ContentTypeMatcher(WireMockConstants.ContentTypeJson, true);
|
private static readonly RegexMatcher AdminRequestContentTypeJson = new ContentTypeMatcher(WireMockConstants.ContentTypeJson, true);
|
||||||
private EnhancedFileSystemWatcher? _enhancedFileSystemWatcher;
|
private EnhancedFileSystemWatcher? _enhancedFileSystemWatcher;
|
||||||
private AdminPaths? _adminPaths;
|
private IAdminPaths? _adminPaths;
|
||||||
|
|
||||||
private sealed class AdminPaths
|
|
||||||
{
|
|
||||||
private readonly string _prefix;
|
|
||||||
private readonly string _prefixEscaped;
|
|
||||||
|
|
||||||
public AdminPaths(WireMockServerSettings settings)
|
|
||||||
{
|
|
||||||
_prefix = settings.AdminPath ?? DefaultAdminPathPrefix;
|
|
||||||
_prefixEscaped = _prefix.Replace("/", "\\/");
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Files => $"{_prefix}/files";
|
|
||||||
public string Health => $"{_prefix}/health";
|
|
||||||
public string Mappings => $"{_prefix}/mappings";
|
|
||||||
public string MappingsCode => $"{_prefix}/mappings/code";
|
|
||||||
public string MappingsWireMockOrg => $"{_prefix}mappings/wiremock.org";
|
|
||||||
public string Requests => $"{_prefix}/requests";
|
|
||||||
public string Settings => $"{_prefix}/settings";
|
|
||||||
public string Scenarios => $"{_prefix}/scenarios";
|
|
||||||
public string OpenApi => $"{_prefix}/openapi";
|
|
||||||
|
|
||||||
public RegexMatcher MappingsGuidPathMatcher => new($"^{_prefixEscaped}\\/mappings\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
|
||||||
public RegexMatcher MappingsGuidEnablePathMatcher => new($"^{_prefixEscaped}\\/mappings\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\\/enable$");
|
|
||||||
public RegexMatcher MappingsGuidDisablePathMatcher => new($"^{_prefixEscaped}\\/mappings\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})\\/disable$");
|
|
||||||
public RegexMatcher MappingsCodeGuidPathMatcher => new($"^{_prefixEscaped}\\/mappings\\/code\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
|
||||||
public RegexMatcher RequestsGuidPathMatcher => new($"^{_prefixEscaped}\\/requests\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
|
|
||||||
public RegexMatcher ScenariosNameMatcher => new($"^{_prefixEscaped}\\/scenarios\\/.+$");
|
|
||||||
public RegexMatcher ScenariosNameWithStateMatcher => new($"^{_prefixEscaped}\\/scenarios\\/.+\\/state$");
|
|
||||||
public RegexMatcher ScenariosNameWithResetMatcher => new($"^{_prefixEscaped}\\/scenarios\\/.+\\/reset$");
|
|
||||||
public RegexMatcher FilesFilenamePathMatcher => new($"^{_prefixEscaped}\\/files\\/.+$");
|
|
||||||
public RegexMatcher ProtoDefinitionsIdPathMatcher => new($"^{_prefixEscaped}\\/protodefinitions\\/.+$");
|
|
||||||
}
|
|
||||||
|
|
||||||
#region InitAdmin
|
#region InitAdmin
|
||||||
private void InitAdmin()
|
private void InitAdmin()
|
||||||
{
|
{
|
||||||
_adminPaths = new AdminPaths(_settings);
|
_adminPaths = _options.AdminPaths;
|
||||||
|
|
||||||
// __admin/health
|
// __admin/health
|
||||||
Given(Request.Create().WithPath(_adminPaths.Health).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(HealthGet));
|
Given(Request.Create().WithPath(_adminPaths.Health).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(HealthGet));
|
||||||
@@ -631,7 +596,7 @@ public partial class WireMockServer
|
|||||||
{
|
{
|
||||||
if (TryParseGuidFromRequestMessage(requestMessage, out var guid))
|
if (TryParseGuidFromRequestMessage(requestMessage, out var guid))
|
||||||
{
|
{
|
||||||
var entry = LogEntries.SingleOrDefault(r => r.RequestMessage != null && !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid);
|
var entry = LogEntries.SingleOrDefault(r => r.RequestMessage != null && !_adminPaths!.Includes(r.RequestMessage.Path) && r.Guid == guid);
|
||||||
if (entry is { })
|
if (entry is { })
|
||||||
{
|
{
|
||||||
var model = new LogEntryMapper(_options).Map(entry);
|
var model = new LogEntryMapper(_options).Map(entry);
|
||||||
@@ -660,7 +625,7 @@ public partial class WireMockServer
|
|||||||
{
|
{
|
||||||
var logEntryMapper = new LogEntryMapper(_options);
|
var logEntryMapper = new LogEntryMapper(_options);
|
||||||
var result = LogEntries
|
var result = LogEntries
|
||||||
.Where(r => r.RequestMessage != null && !r.RequestMessage.Path.StartsWith("/__admin/"))
|
.Where(r => r.RequestMessage != null && !_adminPaths!.Includes(r.RequestMessage.Path))
|
||||||
.Select(logEntryMapper.Map);
|
.Select(logEntryMapper.Map);
|
||||||
|
|
||||||
return ToJson(result);
|
return ToJson(result);
|
||||||
@@ -682,7 +647,7 @@ public partial class WireMockServer
|
|||||||
var request = (Request)InitRequestBuilder(requestModel);
|
var request = (Request)InitRequestBuilder(requestModel);
|
||||||
|
|
||||||
var dict = new Dictionary<ILogEntry, RequestMatchResult>();
|
var dict = new Dictionary<ILogEntry, RequestMatchResult>();
|
||||||
foreach (var logEntry in LogEntries.Where(le => le.RequestMessage != null && !le.RequestMessage.Path.StartsWith("/__admin/")))
|
foreach (var logEntry in LogEntries.Where(le => le.RequestMessage != null && !_adminPaths!.Includes(le.RequestMessage.Path)))
|
||||||
{
|
{
|
||||||
var requestMatchResult = new RequestMatchResult();
|
var requestMatchResult = new RequestMatchResult();
|
||||||
if (request.GetMatchingScore(logEntry.RequestMessage!, requestMatchResult) > MatchScores.AlmostPerfect)
|
if (request.GetMatchingScore(logEntry.RequestMessage!, requestMatchResult) > MatchScores.AlmostPerfect)
|
||||||
@@ -704,7 +669,7 @@ public partial class WireMockServer
|
|||||||
Guid.TryParse(value.ToString(), out var mappingGuid)
|
Guid.TryParse(value.ToString(), out var mappingGuid)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
var logEntries = LogEntries.Where(le => le.RequestMessage != null && !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid);
|
var logEntries = LogEntries.Where(le => le.RequestMessage != null && !_adminPaths!.Includes(le.RequestMessage.Path) && le.MappingGuid == mappingGuid);
|
||||||
var logEntryMapper = new LogEntryMapper(_options);
|
var logEntryMapper = new LogEntryMapper(_options);
|
||||||
var result = logEntries.Select(logEntryMapper.Map);
|
var result = logEntries.Select(logEntryMapper.Map);
|
||||||
return ToJson(result);
|
return ToJson(result);
|
||||||
|
|||||||
@@ -155,7 +155,8 @@ public partial class WireMockServer
|
|||||||
var clientIPModel = _settings.DefaultJsonSerializer.ParseJsonToken<ClientIPModel>(requestModel.ClientIP);
|
var clientIPModel = _settings.DefaultJsonSerializer.ParseJsonToken<ClientIPModel>(requestModel.ClientIP);
|
||||||
if (clientIPModel.Matchers != null)
|
if (clientIPModel.Matchers != null)
|
||||||
{
|
{
|
||||||
requestBuilder = requestBuilder.WithPath(clientIPModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
var matchOperator = StringUtils.ParseMatchOperator(clientIPModel.MatchOperator);
|
||||||
|
requestBuilder = requestBuilder.WithClientIP(matchOperator, clientIPModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -18,6 +18,8 @@ namespace WireMock.WebSockets;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class WireMockWebSocketContext : IWebSocketContext
|
public class WireMockWebSocketContext : IWebSocketContext
|
||||||
{
|
{
|
||||||
|
private readonly IDateTimeUtils _dateTimeUtils;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public Guid ConnectionId { get; }
|
public Guid ConnectionId { get; }
|
||||||
|
|
||||||
@@ -50,7 +52,8 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
WebSocketBuilder builder,
|
WebSocketBuilder builder,
|
||||||
IWireMockMiddlewareOptions options,
|
IWireMockMiddlewareOptions options,
|
||||||
IWireMockMiddlewareLogger logger,
|
IWireMockMiddlewareLogger logger,
|
||||||
IGuidUtils guidUtils
|
IGuidUtils guidUtils,
|
||||||
|
IDateTimeUtils dateTimeUtils
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
HttpContext = httpContext;
|
HttpContext = httpContext;
|
||||||
@@ -61,6 +64,7 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
Builder = builder;
|
Builder = builder;
|
||||||
Options = options;
|
Options = options;
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
|
_dateTimeUtils = dateTimeUtils;
|
||||||
|
|
||||||
ConnectionId = guidUtils.NewGuid();
|
ConnectionId = guidUtils.NewGuid();
|
||||||
}
|
}
|
||||||
@@ -169,7 +173,7 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = _dateTimeUtils.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -179,7 +183,7 @@ public class WireMockWebSocketContext : IWebSocketContext
|
|||||||
{
|
{
|
||||||
Method = method,
|
Method = method,
|
||||||
BodyData = bodyData,
|
BodyData = bodyData,
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = _dateTimeUtils.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||||
<PackageReference Include="TinyMapper.Signed" Version="4.0.0" />
|
<PackageReference Include="TinyMapper.Signed" Version="4.0.0" />
|
||||||
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.34.0" />
|
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.34.0" />
|
||||||
<PackageReference Include="Scriban.Signed" Version="7.2.0" />
|
<PackageReference Include="Scriban.Signed" Version="7.2.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -85,4 +85,4 @@
|
|||||||
<ProjectReference Include="..\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj" />
|
<ProjectReference Include="..\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
#if NETSTANDARD2_0
|
|
||||||
namespace System.Collections.Generic;
|
namespace System.Collections.Generic;
|
||||||
|
|
||||||
internal static class DictionaryExtensions
|
internal static class DictionaryExtensions
|
||||||
{
|
{
|
||||||
|
#if NETSTANDARD2_0
|
||||||
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue>? dictionary, TKey key, TValue value)
|
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue>? dictionary, TKey key, TValue value)
|
||||||
{
|
{
|
||||||
if (dictionary is null || dictionary.ContainsKey(key))
|
if (dictionary is null || dictionary.ContainsKey(key))
|
||||||
@@ -16,5 +16,29 @@ internal static class DictionaryExtensions
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
#endif
|
|
||||||
|
public static bool TryGetFirstValue<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, out TValue? value)
|
||||||
|
{
|
||||||
|
if (dictionary != null && dictionary.Count > 0)
|
||||||
|
{
|
||||||
|
value = dictionary.First().Value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryGetFirstOrDefault<TKey, TValue>(this IDictionary<TKey, TValue>? dictionary, out KeyValuePair<TKey, TValue> value)
|
||||||
|
{
|
||||||
|
if (dictionary != null && dictionary.Count > 0)
|
||||||
|
{
|
||||||
|
value = dictionary.First();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = default;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
@@ -56,37 +54,25 @@ internal static class OpenApiSchemaExtensions
|
|||||||
|
|
||||||
public static SchemaFormat GetSchemaFormat(this IOpenApiSchema? schema)
|
public static SchemaFormat GetSchemaFormat(this IOpenApiSchema? schema)
|
||||||
{
|
{
|
||||||
switch (schema?.Format)
|
return (schema?.Format) switch
|
||||||
{
|
{
|
||||||
case "float":
|
"float" => SchemaFormat.Float,
|
||||||
return SchemaFormat.Float;
|
"double" => SchemaFormat.Double,
|
||||||
|
"int32" => SchemaFormat.Int32,
|
||||||
|
"int64" => SchemaFormat.Int64,
|
||||||
|
"date" => SchemaFormat.Date,
|
||||||
|
"date-time" => SchemaFormat.DateTime,
|
||||||
|
"password" => SchemaFormat.Password,
|
||||||
|
"byte" => SchemaFormat.Byte,
|
||||||
|
"binary" => SchemaFormat.Binary,
|
||||||
|
_ => SchemaFormat.Undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case "double":
|
internal static JsonNode? FindFirstExample(this IOpenApiSchema? schema)
|
||||||
return SchemaFormat.Double;
|
{
|
||||||
|
#pragma warning disable CS0618 // Type or member is obsolete
|
||||||
case "int32":
|
return schema?.Examples?.FirstOrDefault() ?? schema?.Example;
|
||||||
return SchemaFormat.Int32;
|
#pragma warning restore CS0618 // Type or member is obsolete
|
||||||
|
|
||||||
case "int64":
|
|
||||||
return SchemaFormat.Int64;
|
|
||||||
|
|
||||||
case "date":
|
|
||||||
return SchemaFormat.Date;
|
|
||||||
|
|
||||||
case "date-time":
|
|
||||||
return SchemaFormat.DateTime;
|
|
||||||
|
|
||||||
case "password":
|
|
||||||
return SchemaFormat.Password;
|
|
||||||
|
|
||||||
case "byte":
|
|
||||||
return SchemaFormat.Byte;
|
|
||||||
|
|
||||||
case "binary":
|
|
||||||
return SchemaFormat.Binary;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return SchemaFormat.Undefined;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Net.OpenApiParser.Models;
|
using WireMock.Net.OpenApiParser.Models;
|
||||||
@@ -16,7 +14,8 @@ namespace WireMock.Net.OpenApiParser.Extensions;
|
|||||||
public static class WireMockServerExtensions
|
public static class WireMockServerExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 file.
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1/V3.2 file.
|
||||||
|
/// In case of an error, no mappings are registered and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
||||||
@@ -28,7 +27,8 @@ public static class WireMockServerExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 file.
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1/V3.2 file.
|
||||||
|
/// In case of an error, no mappings are registered and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
/// <param name="path">Path containing OpenAPI file to parse and use the mappings.</param>
|
||||||
@@ -46,7 +46,8 @@ public static class WireMockServerExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 stream.
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1/V3.2 stream.
|
||||||
|
/// In case of an error, no mappings are registered and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
||||||
@@ -58,7 +59,8 @@ public static class WireMockServerExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 stream.
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1/V3.2 stream.
|
||||||
|
/// In case of an error, no mappings are registered and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
/// <param name="stream">Stream containing OpenAPI description to parse and use the mappings.</param>
|
||||||
@@ -77,7 +79,8 @@ public static class WireMockServerExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1 document.
|
/// Register the mappings via an OpenAPI (swagger) V2/V3/V3.1/V3.2 document.
|
||||||
|
/// In case of an error, no mappings are registered and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The WireMockServer instance</param>
|
/// <param name="server">The WireMockServer instance</param>
|
||||||
/// <param name="document">The OpenAPI document to use as mappings.</param>
|
/// <param name="document">The OpenAPI document to use as mappings.</param>
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
<InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Microsoft.OpenApi'" />
|
<InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Microsoft.OpenApi'" />
|
||||||
<LibraryPath Include="%(ReferencePathWithRefAssemblies.RelativeDir)" />
|
<LibraryPath Include="%(ReferencePathWithRefAssemblies.RelativeDir)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<DoNotInternalizeAssemblies Include="WireMock.Net.OpenApiParser" />
|
<DoNotInternalizeAssemblies Include="WireMock.Net.OpenApiParser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ILRepack
|
<ILRepack
|
||||||
Parallel="true"
|
Parallel="true"
|
||||||
Internalize="true"
|
Internalize="true"
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Net.OpenApiParser.Models;
|
using WireMock.Net.OpenApiParser.Models;
|
||||||
using WireMock.Net.OpenApiParser.Settings;
|
using WireMock.Net.OpenApiParser.Settings;
|
||||||
@@ -15,6 +13,7 @@ public interface IWireMockOpenApiParser
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a file-path.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a file-path.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3/V31 or Raml file.</param>
|
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3/V31 or Raml file.</param>
|
||||||
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
@@ -23,6 +22,7 @@ public interface IWireMockOpenApiParser
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a file-path.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a file-path.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3/V31 or Raml file.</param>
|
/// <param name="path">The path to read the OpenApi/Swagger/V2/V3/V31 or Raml file.</param>
|
||||||
/// <param name="settings">Additional settings</param>
|
/// <param name="settings">Additional settings</param>
|
||||||
@@ -40,6 +40,7 @@ public interface IWireMockOpenApiParser
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="Stream"/>.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="Stream"/>.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">The source stream</param>
|
/// <param name="stream">The source stream</param>
|
||||||
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
@@ -48,6 +49,7 @@ public interface IWireMockOpenApiParser
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="Stream"/>.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="Stream"/>.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="stream">The source stream</param>
|
/// <param name="stream">The source stream</param>
|
||||||
/// <param name="settings">Additional settings</param>
|
/// <param name="settings">Additional settings</param>
|
||||||
@@ -57,6 +59,7 @@ public interface IWireMockOpenApiParser
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="string"/>.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="string"/>.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The source text</param>
|
/// <param name="text">The source text</param>
|
||||||
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
/// <param name="diagnostic">OpenApiDiagnostic output</param>
|
||||||
@@ -65,6 +68,7 @@ public interface IWireMockOpenApiParser
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="string"/>.
|
/// Generate <see cref="IReadOnlyList{MappingModel}"/> from a <seealso cref="string"/>.
|
||||||
|
/// In case of an error, an empty list is returned and <see cref="OpenApiDiagnostic"/> contains the error details.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">The source text</param>
|
/// <param name="text">The source text</param>
|
||||||
/// <param name="settings">Additional settings</param>
|
/// <param name="settings">Additional settings</param>
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
Headers = MapRequestHeaders(requestHeaders),
|
Headers = MapRequestHeaders(requestHeaders),
|
||||||
Body = GetRequestBodyModel(operation.RequestBody)
|
Body = GetRequestBodyModel(operation.RequestBody)
|
||||||
},
|
},
|
||||||
Response = GetResponseModel(operation.Responses?.FirstOrDefault())
|
Response = operation.Responses?.TryGetFirstOrDefault(out var firstResponse) == true ? GetResponseModel(firstResponse) : new ResponseModel { StatusCode = 200 }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +70,7 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
|
|
||||||
var requestExample = requestContent?.Example;
|
var requestExample = requestContent?.Example;
|
||||||
var requestExamples = requestContent?.Examples;
|
var requestExamples = requestContent?.Examples;
|
||||||
var requestSchemaExample = requestContent?.Schema?.Example;
|
var requestSchemaExample = requestContent?.Schema.FindFirstExample();
|
||||||
var requestSchemaExamples = requestContent?.Schema?.Examples;
|
|
||||||
|
|
||||||
JsonNode? request;
|
JsonNode? request;
|
||||||
if (requestExample != null)
|
if (requestExample != null)
|
||||||
@@ -86,10 +85,6 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
{
|
{
|
||||||
request = requestExamples.FirstOrDefault().Value.Value;
|
request = requestExamples.FirstOrDefault().Value.Value;
|
||||||
}
|
}
|
||||||
else if (requestSchemaExamples != null)
|
|
||||||
{
|
|
||||||
request = requestSchemaExamples.FirstOrDefault();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var requestSchema = content?.FirstOrDefault().Value.Schema;
|
var requestSchema = content?.FirstOrDefault().Value.Schema;
|
||||||
@@ -99,16 +94,15 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
return MapRequestBody(request) ?? new BodyModel();
|
return MapRequestBody(request) ?? new BodyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseModel GetResponseModel(KeyValuePair<string, IOpenApiResponse>? openApiResponse)
|
private ResponseModel GetResponseModel(KeyValuePair<string, IOpenApiResponse> openApiResponse)
|
||||||
{
|
{
|
||||||
var content = openApiResponse?.Value.Content;
|
var content = openApiResponse.Value.Content;
|
||||||
|
|
||||||
TryGetContent(content, out var responseContent, out var contentType);
|
TryGetContent(content, out var responseContent, out var contentType);
|
||||||
|
|
||||||
var responseExample = responseContent?.Example;
|
var responseExample = responseContent?.Example;
|
||||||
var responseExamples = responseContent?.Examples;
|
var responseExamples = responseContent?.Examples;
|
||||||
var responseSchemaExample = responseContent?.Schema?.Example;
|
var responseSchemaExample = responseContent?.Schema.FindFirstExample();
|
||||||
var responseSchemaExamples = responseContent?.Schema?.Examples;
|
|
||||||
|
|
||||||
JsonNode? response;
|
JsonNode? response;
|
||||||
if (responseExample != null)
|
if (responseExample != null)
|
||||||
@@ -119,24 +113,19 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
{
|
{
|
||||||
response = responseSchemaExample;
|
response = responseSchemaExample;
|
||||||
}
|
}
|
||||||
else if (responseExamples != null)
|
else if (responseExamples.TryGetFirstValue(out var firstResponseFromExamples))
|
||||||
{
|
{
|
||||||
response = responseExamples.FirstOrDefault().Value.Value;
|
response = firstResponseFromExamples?.Value;
|
||||||
}
|
|
||||||
else if (responseSchemaExamples != null)
|
|
||||||
{
|
|
||||||
response = responseSchemaExamples.FirstOrDefault();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var responseSchema = content?.FirstOrDefault().Value?.Schema;
|
response = content.TryGetFirstValue(out var firstContent) ? MapSchemaToObject(firstContent?.Schema) : null;
|
||||||
response = MapSchemaToObject(responseSchema);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponseModel
|
return new ResponseModel
|
||||||
{
|
{
|
||||||
StatusCode = int.TryParse(openApiResponse?.Key, out var httpStatusCode) ? httpStatusCode : 200,
|
StatusCode = int.TryParse(openApiResponse.Key, out var httpStatusCode) ? httpStatusCode : 200,
|
||||||
Headers = MapHeaders(contentType, openApiResponse?.Value.Headers),
|
Headers = MapHeaders(contentType, openApiResponse.Value.Headers),
|
||||||
BodyAsJson = response != null ? JsonConvert.DeserializeObject(SystemTextJsonSerializer.Serialize(response)) : null
|
BodyAsJson = response != null ? JsonConvert.DeserializeObject(SystemTextJsonSerializer.Serialize(response)) : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -159,7 +148,7 @@ internal class OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryGetContent(IDictionary<string, OpenApiMediaType>? contents, [NotNullWhen(true)] out OpenApiMediaType? openApiMediaType, [NotNullWhen(true)] out string? contentType)
|
private static bool TryGetContent(IDictionary<string, IOpenApiMediaType>? contents, [NotNullWhen(true)] out IOpenApiMediaType? openApiMediaType, [NotNullWhen(true)] out string? contentType)
|
||||||
{
|
{
|
||||||
openApiMediaType = null;
|
openApiMediaType = null;
|
||||||
contentType = null;
|
contentType = null;
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using RamlToOpenApiConverter;
|
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Models;
|
namespace WireMock.Net.OpenApiParser.Models;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -24,5 +21,5 @@ public class OpenApiDiagnostic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open API specification version of the document parsed.
|
/// Open API specification version of the document parsed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OpenApiSpecificationVersion SpecificationVersion { get; set; }
|
public OpenApiSpecVersion SpecificationVersion { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using RamlToOpenApiConverter;
|
|
||||||
using MicrosoftOpenApiDiagnostic = Microsoft.OpenApi.Reader.OpenApiDiagnostic;
|
using MicrosoftOpenApiDiagnostic = Microsoft.OpenApi.Reader.OpenApiDiagnostic;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Models;
|
namespace WireMock.Net.OpenApiParser.Models;
|
||||||
@@ -19,7 +17,7 @@ internal static class OpenApiMapper
|
|||||||
{
|
{
|
||||||
Errors = openApiDiagnostic.Errors.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(),
|
Errors = openApiDiagnostic.Errors.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(),
|
||||||
Warnings = openApiDiagnostic.Warnings.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(),
|
Warnings = openApiDiagnostic.Warnings.Select(e => new OpenApiError(e.Pointer, e.Message)).ToList(),
|
||||||
SpecificationVersion = (OpenApiSpecificationVersion)openApiDiagnostic.SpecificationVersion
|
SpecificationVersion = (OpenApiSpecVersion)openApiDiagnostic.SpecificationVersion
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
namespace WireMock.Net.OpenApiParser.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents versions of OpenAPI specification.
|
||||||
|
/// </summary>
|
||||||
|
public enum OpenApiSpecVersion
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents OpenAPI V2.0 spec
|
||||||
|
/// </summary>
|
||||||
|
OpenApi2_0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents all patches of OpenAPI V3.0 spec (e.g. 3.0.0, 3.0.1)
|
||||||
|
/// </summary>
|
||||||
|
OpenApi3_0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents OpenAPI V3.1 spec
|
||||||
|
/// </summary>
|
||||||
|
OpenApi3_1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents OpenAPI V3.2 spec
|
||||||
|
/// </summary>
|
||||||
|
OpenApi3_2
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.OpenApi;
|
using Microsoft.OpenApi;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Settings;
|
namespace WireMock.Net.OpenApiParser.Settings;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.OpenApi;
|
using Microsoft.OpenApi;
|
||||||
using RandomDataGenerator.FieldOptions;
|
using RandomDataGenerator.FieldOptions;
|
||||||
using RandomDataGenerator.Randomizers;
|
using RandomDataGenerator.Randomizers;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using Microsoft.OpenApi;
|
using Microsoft.OpenApi;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Settings;
|
namespace WireMock.Net.OpenApiParser.Settings;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace WireMock.Net.OpenApiParser.Utils;
|
namespace WireMock.Net.OpenApiParser.Utils;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
using Microsoft.OpenApi;
|
using Microsoft.OpenApi;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -39,7 +37,7 @@ internal class ExampleValueGenerator
|
|||||||
|
|
||||||
public JsonNode GetExampleValue(IOpenApiSchema? schema)
|
public JsonNode GetExampleValue(IOpenApiSchema? schema)
|
||||||
{
|
{
|
||||||
var schemaExample = schema?.Example;
|
var schemaExample = schema?.FindFirstExample();
|
||||||
var schemaEnum = schema?.Enum?.FirstOrDefault();
|
var schemaEnum = schema?.Enum?.FirstOrDefault();
|
||||||
|
|
||||||
_exampleValues.Schema = schema;
|
_exampleValues.Schema = schema;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
|
||||||
<PackageReference Include="Required" Version="1.0.0">
|
<PackageReference Include="Required" Version="1.0.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@@ -40,25 +40,29 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
|
||||||
<PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.11.0" />
|
|
||||||
<PackageReference Include="YamlDotNet" Version="16.3.0" />
|
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.19.1" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.19.1" />
|
||||||
<PackageReference Include="Stef.Validation" Version="0.3.0" />
|
<PackageReference Include="Stef.Validation" Version="0.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- https://github.com/wiremock/WireMock.Net/issues/1508 -->
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="RamlToOpenApiConverter.SourceOnly" Version="0.50.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
|
<ItemGroup Condition="'$(Configuration)' == 'Debug'">
|
||||||
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.3.0" />
|
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.10.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(Configuration)' == 'Release'">
|
<ItemGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
|
<!-- Keep at version 2.0.43 (https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task/issues/80) -->
|
||||||
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.43" PrivateAssets="All" />
|
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.43" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.OpenApi" Version="2.3.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.OpenApi" Version="3.10.2" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="2.3.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.OpenApi.YamlReader" Version="3.10.2" PrivateAssets="All" />
|
||||||
<PackageReference Include="SharpYaml" Version="2.1.3" />
|
<PackageReference Include="SharpYaml" Version="2.1.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\..\src\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Microsoft.OpenApi;
|
using Microsoft.OpenApi;
|
||||||
@@ -18,7 +16,7 @@ using OpenApiDiagnostic = WireMock.Net.OpenApiParser.Models.OpenApiDiagnostic;
|
|||||||
namespace WireMock.Net.OpenApiParser;
|
namespace WireMock.Net.OpenApiParser;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a OpenApi/Swagger/V2/V3/V3.1 to WireMock.Net MappingModels.
|
/// Parse a OpenApi/Swagger/V2/V3/V3.1/V3.2 to WireMock.Net MappingModels.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class WireMockOpenApiParser : IWireMockOpenApiParser
|
public class WireMockOpenApiParser : IWireMockOpenApiParser
|
||||||
{
|
{
|
||||||
@@ -32,8 +30,15 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
|
|||||||
_readerSettings = new OpenApiReaderSettings();
|
_readerSettings = new OpenApiReaderSettings();
|
||||||
_readerSettings.AddMicrosoftExtensionParsers();
|
_readerSettings.AddMicrosoftExtensionParsers();
|
||||||
_readerSettings.AddJsonReader();
|
_readerSettings.AddJsonReader();
|
||||||
_readerSettings.TryAddReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
|
|
||||||
_readerSettings.TryAddReader(OpenApiConstants.Yml, new OpenApiYamlReader());
|
var openApiYamlReaderSettings = new OpenApiYamlReaderSettings
|
||||||
|
{
|
||||||
|
MaxAliasExpansionNodeCount = 1_000_000
|
||||||
|
};
|
||||||
|
var openApiYamlReader = new OpenApiYamlReader(openApiYamlReaderSettings);
|
||||||
|
|
||||||
|
_readerSettings.TryAddReader(OpenApiConstants.Yaml, openApiYamlReader);
|
||||||
|
_readerSettings.TryAddReader(OpenApiConstants.Yml, openApiYamlReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -55,7 +60,12 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
document = Read(File.OpenRead(path), out diagnostic);
|
if (!TryRead(File.OpenRead(path), out var documentFromYaml, out diagnostic))
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
document = documentFromYaml;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FromDocument(document, settings);
|
return FromDocument(document, settings);
|
||||||
@@ -74,14 +84,24 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IReadOnlyList<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic)
|
public IReadOnlyList<MappingModel> FromStream(Stream stream, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
return FromDocument(Read(stream, out diagnostic));
|
if (TryRead(stream, out var openApiDocument, out diagnostic))
|
||||||
|
{
|
||||||
|
return FromDocument(openApiDocument);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public IReadOnlyList<MappingModel> FromStream(Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
public IReadOnlyList<MappingModel> FromStream(Stream stream, WireMockOpenApiParserSettings settings, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
return FromDocument(Read(stream, out diagnostic), settings);
|
if (TryRead(stream, out var openApiDocument, out diagnostic))
|
||||||
|
{
|
||||||
|
return FromDocument(openApiDocument, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -98,7 +118,7 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
|
|||||||
return FromStream(new MemoryStream(Encoding.UTF8.GetBytes(text)), settings, out diagnostic);
|
return FromStream(new MemoryStream(Encoding.UTF8.GetBytes(text)), settings, out diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
private OpenApiDocument Read(Stream stream, out OpenApiDiagnostic diagnostic)
|
private bool TryRead(Stream stream, [NotNullWhen(true)] out OpenApiDocument? openApiDocument, out OpenApiDiagnostic diagnostic)
|
||||||
{
|
{
|
||||||
if (stream is not MemoryStream memoryStream)
|
if (stream is not MemoryStream memoryStream)
|
||||||
{
|
{
|
||||||
@@ -108,7 +128,8 @@ public class WireMockOpenApiParser : IWireMockOpenApiParser
|
|||||||
var result = OpenApiDocument.Load(memoryStream, settings: _readerSettings);
|
var result = OpenApiDocument.Load(memoryStream, settings: _readerSettings);
|
||||||
|
|
||||||
diagnostic = OpenApiMapper.Map(result.Diagnostic) ?? new OpenApiDiagnostic();
|
diagnostic = OpenApiMapper.Map(result.Diagnostic) ?? new OpenApiDiagnostic();
|
||||||
return result.Document ?? throw new InvalidOperationException("The document is null.");
|
openApiDocument = result.Document;
|
||||||
|
return openApiDocument != null && !diagnostic.Errors.Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MemoryStream ReadStreamIntoMemoryStream(Stream stream)
|
private static MemoryStream ReadStreamIntoMemoryStream(Stream stream)
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
using WireMock.Types;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
namespace WireMock.Matchers;
|
||||||
|
|
||||||
@@ -57,7 +55,7 @@ public static class MatchScores
|
|||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
/// <param name="matchOperator">The <see cref="MatchOperator"/>.</param>
|
/// <param name="matchOperator">The <see cref="MatchOperator"/>.</param>
|
||||||
/// <returns>average score</returns>
|
/// <returns>average score</returns>
|
||||||
public static double ToScore(IReadOnlyCollection<bool> values, MatchOperator matchOperator)
|
public static double ToScore(IReadOnlyList<bool> values, MatchOperator matchOperator)
|
||||||
{
|
{
|
||||||
return ToScore(values.Select(ToScore).ToArray(), matchOperator);
|
return ToScore(values.Select(ToScore).ToArray(), matchOperator);
|
||||||
}
|
}
|
||||||
@@ -68,9 +66,9 @@ public static class MatchScores
|
|||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
/// <param name="matchOperator"></param>
|
/// <param name="matchOperator"></param>
|
||||||
/// <returns>average score</returns>
|
/// <returns>average score</returns>
|
||||||
public static double ToScore(IReadOnlyCollection<double> values, MatchOperator matchOperator)
|
public static double ToScore(IReadOnlyList<double> values, MatchOperator matchOperator)
|
||||||
{
|
{
|
||||||
if (!values.Any())
|
if (values.Count == 0)
|
||||||
{
|
{
|
||||||
return Mismatch;
|
return Mismatch;
|
||||||
}
|
}
|
||||||
@@ -82,4 +80,28 @@ public static class MatchScores
|
|||||||
_ => values.Average()
|
_ => values.Average()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static double ToScore(WireMockList<string> values, IStringMatcher[] matchers, MatchOperator matchOperator = MatchOperator.And)
|
||||||
|
{
|
||||||
|
// Create a matrix of scores where each row corresponds to a value and each column corresponds to a matcher.
|
||||||
|
var matrix = values
|
||||||
|
.Select(value => matchers
|
||||||
|
.Select(matcher => matcher.IsMatch(value).Score).ToArray()
|
||||||
|
)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (matrix.Length == 0 || matchers.Length == 0)
|
||||||
|
{
|
||||||
|
return Mismatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each value, how well was it matched by its best matcher?
|
||||||
|
var rowScore = matchOperator == MatchOperator.And ? matrix.Average(row => row.Max()) : matrix.Max(row => row.Max());
|
||||||
|
|
||||||
|
// For each matcher, how well was it satisfied by its best value?
|
||||||
|
var columnRange = Enumerable.Range(0, matchers.Length);
|
||||||
|
var columnScore = matchOperator == MatchOperator.And ? columnRange.Average(column => matrix.Max(row => row[column])) : columnRange.Max(column => matrix.Max(row => row[column]));
|
||||||
|
|
||||||
|
return matchOperator == MatchOperator.And ? Math.Min(rowScore, columnScore) : Math.Max(rowScore, columnScore);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string GetCSharpCodeArguments()
|
public string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(NotNullOrEmptyMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}" +
|
||||||
$")";
|
$")";
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -132,10 +130,10 @@ public class RegexMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string GetCSharpCodeArguments()
|
public virtual string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(RegexMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
|
$"new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(_useRegexExtended)}, " +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(_useRegexExtended)}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using AnyOfTypes;
|
using AnyOfTypes;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
@@ -74,10 +73,10 @@ public class WildcardMatcher : RegexMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string GetCSharpCodeArguments()
|
public override string GetCSharpCodeArguments()
|
||||||
{
|
{
|
||||||
return $"new {Name}" +
|
return $"new {typeof(WildcardMatcher).FullName}" +
|
||||||
$"(" +
|
$"(" +
|
||||||
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
$"{MatchBehaviour.GetFullyQualifiedEnumValue()}, " +
|
||||||
$"{MappingConverterUtils.ToCSharpCodeArguments(_patterns)}, " +
|
$"new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] {{ {MappingConverterUtils.ToCSharpCodeArguments(_patterns)} }}, " +
|
||||||
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
$"{CSharpFormatter.ToCSharpBooleanLiteral(IgnoreCase)}, " +
|
||||||
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
$"{MatchOperator.GetFullyQualifiedEnumValue()}" +
|
||||||
$")";
|
$")";
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class BodyData : IBodyData
|
|||||||
public string? BodyAsString { get; set; }
|
public string? BodyAsString { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IDictionary<string, string>? BodyAsFormUrlEncoded { get; set; }
|
public IDictionary<string, WireMockList<string>>? BodyAsFormUrlEncoded { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public object? BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders;
|
namespace WireMock.RequestBuilders;
|
||||||
@@ -100,5 +99,5 @@ public interface IBodyRequestBuilder : IMultiPartRequestBuilder
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="func">The form-urlencoded values.</param>
|
/// <param name="func">The form-urlencoded values.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBody(Func<IDictionary<string, string>?, bool> func);
|
IRequestBuilder WithBody(Func<IDictionary<string, WireMockList<string>>?, bool> func);
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
@@ -16,7 +13,7 @@ internal static class QueryStringParser
|
|||||||
{
|
{
|
||||||
private static readonly Dictionary<string, WireMockList<string>> Empty = new();
|
private static readonly Dictionary<string, WireMockList<string>> Empty = new();
|
||||||
|
|
||||||
public static bool TryParse(string? queryString, bool caseIgnore, [NotNullWhen(true)] out IDictionary<string, string>? nameValueCollection)
|
public static bool TryParse(string? queryString, bool caseIgnore, [NotNullWhen(true)] out IDictionary<string, WireMockList<string>>? nameValueCollection)
|
||||||
{
|
{
|
||||||
if (queryString == null)
|
if (queryString == null)
|
||||||
{
|
{
|
||||||
@@ -29,12 +26,22 @@ internal static class QueryStringParser
|
|||||||
.Select(parameter => parameter.Split('='))
|
.Select(parameter => parameter.Split('='))
|
||||||
.Distinct();
|
.Distinct();
|
||||||
|
|
||||||
nameValueCollection = caseIgnore ? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) : new Dictionary<string, string>();
|
nameValueCollection = caseIgnore ? new Dictionary<string, WireMockList<string>>(StringComparer.OrdinalIgnoreCase) : new Dictionary<string, WireMockList<string>>();
|
||||||
foreach (var part in parts)
|
foreach (var part in parts)
|
||||||
{
|
{
|
||||||
if (part.Length == 2)
|
if (part.Length == 2)
|
||||||
{
|
{
|
||||||
nameValueCollection.Add(part[0], WebUtility.UrlDecode(part[1]));
|
var key = part[0];
|
||||||
|
var value = WebUtility.UrlDecode(part[1]);
|
||||||
|
|
||||||
|
if (!nameValueCollection.TryGetValue(key, out var stringList))
|
||||||
|
{
|
||||||
|
nameValueCollection.Add(key, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stringList.Add(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Stef.Validation" Version="0.3.0" />
|
<PackageReference Include="Stef.Validation" Version="0.3.0" />
|
||||||
<PackageReference Include="Testcontainers" Version="4.12.0" />
|
<PackageReference Include="Testcontainers" Version="4.14.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
@@ -14,51 +13,61 @@ namespace WireMock.Net.Xunit;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class TestOutputHelperWireMockLogger : IWireMockLogger
|
public sealed class TestOutputHelperWireMockLogger : IWireMockLogger
|
||||||
{
|
{
|
||||||
private readonly ITestOutputHelper _testOutputHelper;
|
private readonly Func<ITestOutputHelper?> _testOutputHelperFactory;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new instance on the <see cref="TestOutputHelperWireMockLogger"/>.
|
/// Create a new instance on the <see cref="TestOutputHelperWireMockLogger"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="testOutputHelper">Represents a class which can be used to provide test output.</param>
|
/// <param name="testOutputHelper">Represents a class which can be used to provide test output.</param>
|
||||||
public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper)
|
public TestOutputHelperWireMockLogger(ITestOutputHelper testOutputHelper) :
|
||||||
|
this(() => testOutputHelper)
|
||||||
{
|
{
|
||||||
_testOutputHelper = Guard.NotNull(testOutputHelper);
|
Guard.NotNull(testOutputHelper);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new instance on the <see cref="TestOutputHelperWireMockLogger"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="testOutputHelperFactory">Represents a factory to provide current test output.</param>
|
||||||
|
public TestOutputHelperWireMockLogger(Func<ITestOutputHelper?> testOutputHelperFactory)
|
||||||
|
{
|
||||||
|
_testOutputHelperFactory = Guard.NotNull(testOutputHelperFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Debug(string formatString, params object[] args)
|
public void Debug(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Debug", formatString, args));
|
_testOutputHelperFactory()?.WriteLine(Format("Debug", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Info(string formatString, params object[] args)
|
public void Info(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Info", formatString, args));
|
_testOutputHelperFactory()?.WriteLine(Format("Info", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Warn(string formatString, params object[] args)
|
public void Warn(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Warning", formatString, args));
|
_testOutputHelperFactory()?.WriteLine(Format("Warning", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Error(string formatString, params object[] args)
|
public void Error(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Error", formatString, args));
|
_testOutputHelperFactory()?.WriteLine(Format("Error", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Error(string message, Exception exception)
|
public void Error(string message, Exception exception)
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Error", $"{message} {{0}}", exception));
|
_testOutputHelperFactory()?.WriteLine(Format("Error", $"{message} {{0}}", exception));
|
||||||
|
|
||||||
if (exception is AggregateException ae)
|
if (exception is AggregateException ae)
|
||||||
{
|
{
|
||||||
ae.Handle(ex =>
|
ae.Handle(ex =>
|
||||||
{
|
{
|
||||||
_testOutputHelper.WriteLine(Format("Error", "Exception {0}", ex));
|
_testOutputHelperFactory()?.WriteLine(Format("Error", "Exception {0}", ex));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -72,7 +81,7 @@ public sealed class TestOutputHelperWireMockLogger : IWireMockLogger
|
|||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
NullValueHandling = NullValueHandling.Ignore
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
});
|
});
|
||||||
_testOutputHelper.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message));
|
_testOutputHelperFactory()?.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string Format(string level, string formatString, params object[] args)
|
private static string Format(string level, string formatString, params object[] args)
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
|
||||||
<PackageReference Include="WireMock.Net" Version="2.10.0" />
|
<PackageReference Include="WireMock.Net" Version="2.12.0" />
|
||||||
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
<PackageReference Include="xunit.v3" Version="3.2.2" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
@@ -29,13 +29,13 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Update="JetBrains.Annotations" Version="2025.2.4" />
|
<!--<PackageReference Update="JetBrains.Annotations" Version="2025.2.4" />-->
|
||||||
<PackageReference Include="OpenTelemetry" Version="1.15.3" />
|
<PackageReference Include="OpenTelemetry" Version="1.17.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Api" Version="1.15.3" />
|
<PackageReference Include="OpenTelemetry.Api" Version="1.17.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" Version="1.15.3" />
|
<PackageReference Include="OpenTelemetry.Api.ProviderBuilderExtensions" Version="1.17.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.17.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.17.0" />
|
||||||
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.17.0" />
|
||||||
<PackageReference Update="SonarAnalyzer.CSharp" Version="10.11.0.117924" />
|
<PackageReference Update="SonarAnalyzer.CSharp" Version="10.11.0.117924" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,617 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using WireMock.Types;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.Abstractions;
|
||||||
|
|
||||||
|
public class WireMockListTests
|
||||||
|
{
|
||||||
|
#region String Generic Type Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Constructor_Empty_ShouldCreateEmptyList()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<string>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
list.Count.Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Constructor_WithSingleString_ShouldCreateListWithOneElement()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var value = "test";
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<string>(value);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(1);
|
||||||
|
list[0].Should().Be("test");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Constructor_WithMultipleStrings_ShouldCreateListWithAllElements()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var values = new[] { "value1", "value2", "value3" };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<string>(values);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(3);
|
||||||
|
list.Should().ContainInOrder("value1", "value2", "value3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Constructor_WithIEnumerable_ShouldCreateListWithAllElements()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var values = new List<string> { "a", "b", "c" };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<string>(values);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(3);
|
||||||
|
list.Should().ContainInOrder("a", "b", "c");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ToString_WhenEmpty_ShouldReturnEmptyString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ToString_WhenSingleElement_ShouldReturnElementValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("singleValue");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("singleValue");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ToString_WhenMultipleElements_ShouldReturnCommaSeparatedValues()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("value1", "value2", "value3");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("value1, value2, value3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ImplicitOperator_WithSingleValue_ShouldCreateList()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
WireMockList<string> list = "testValue";
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(1);
|
||||||
|
list[0].Should().Be("testValue");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ImplicitOperator_WithArray_ShouldCreateList()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var values = new[] { "first", "second", "third" };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
WireMockList<string> list = values;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(3);
|
||||||
|
list.Should().ContainInOrder("first", "second", "third");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Object Generic Type Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_Constructor_Empty_ShouldCreateEmptyList()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<object>();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().BeEmpty();
|
||||||
|
list.Count.Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_Constructor_WithSingleObject_ShouldCreateListWithOneElement()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var obj = new { Name = "Test", Value = 123 };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<object>(obj);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(1);
|
||||||
|
list[0].Should().Be(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_Constructor_WithMultipleObjects_ShouldCreateListWithAllElements()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var obj1 = new object();
|
||||||
|
var obj2 = new object();
|
||||||
|
var obj3 = new object();
|
||||||
|
var values = new[] { obj1, obj2, obj3 };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<object>(values);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(3);
|
||||||
|
list.Should().ContainInOrder(obj1, obj2, obj3);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_Constructor_WithIEnumerable_ShouldCreateListWithAllElements()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var values = new List<object?>
|
||||||
|
{
|
||||||
|
"string",
|
||||||
|
123,
|
||||||
|
45.67,
|
||||||
|
true,
|
||||||
|
null
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var list = new WireMockList<object?>(values);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(5);
|
||||||
|
list.Should().ContainInOrder("string", 123, 45.67, true, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenEmpty_ShouldReturnEmptyString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object>();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenSingleString_ShouldReturnString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object>("singleString");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("singleString");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenSingleObject_ShouldReturnObjectToString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var obj = new { Name = "Test" };
|
||||||
|
var list = new WireMockList<object>(obj);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Contain("Name");
|
||||||
|
result.Should().Contain("Test");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenSingleInt_ShouldReturnIntAsString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object>(42);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("42");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenMultipleElements_ShouldReturnCommaSeparatedValues()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object>("text", 123, 45.67);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be($"text, 123, {45.67}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WithMixedTypes_ShouldReturnCommaSeparatedStringRepresentation()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object>
|
||||||
|
{
|
||||||
|
"string",
|
||||||
|
123,
|
||||||
|
45.67,
|
||||||
|
true
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be($"string, 123, {45.67}, True");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WithNullValue_ShouldReturnEmptyStringForNull()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<object?>
|
||||||
|
{
|
||||||
|
"value1",
|
||||||
|
null,
|
||||||
|
"value3"
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("value1, , value3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ImplicitOperator_WithSingleValue_ShouldCreateList()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var obj = new { Id = 1 };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
WireMockList<object> list = obj;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(1);
|
||||||
|
list[0].Should().Be(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ImplicitOperator_WithArray_ShouldCreateList()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var values = new object[] { "first", 2, 3.0 };
|
||||||
|
|
||||||
|
// Act
|
||||||
|
WireMockList<object> list = values;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(3);
|
||||||
|
list.Should().ContainInOrder("first", 2, 3.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region List Operations Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Add_ShouldAddElement()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("initial");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
list.Add("new");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(2);
|
||||||
|
list[1].Should().Be("new");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Remove_ShouldRemoveElement()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("value1", "value2", "value3");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var removed = list.Remove("value2");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
removed.Should().BeTrue();
|
||||||
|
list.Should().HaveCount(2);
|
||||||
|
list.Should().ContainInOrder("value1", "value3");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Edge Cases
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_ToString_WithEmptyString_ShouldReturnEmptyString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be("");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Constructor_WithNull_ShouldThrow()
|
||||||
|
{
|
||||||
|
// Act & Assert
|
||||||
|
var act = () => new WireMockList<string?>(null!);
|
||||||
|
act.Should().Throw<ArgumentNullException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ImplicitOperator_WithNull_ShouldCreateListWithNullElement()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
WireMockList<object> list = (null as object)!;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
list.Should().HaveCount(1);
|
||||||
|
list[0].Should().BeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfObject_ToString_WhenSingleNullObject_ShouldReturnEmptyString()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
object? nullObj = null;
|
||||||
|
var list = new WireMockList<object>(nullObj!);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = list.ToString();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
result.Should().Be(string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Equality Operator Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_EqualityOperator_ListToSingleValue_WhenSingleElementMatchesValue_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
(list == "hello").Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_EqualityOperator_ListToSingleValue_WhenSingleElementDoesNotMatchValue_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
(list == "world").Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_EqualityOperator_ListToSingleValue_WhenMultipleElements_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello", "world");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
(list == "hello").Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_EqualityOperator_SingleValueToList_WhenSingleElementMatchesValue_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
("hello" == list).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_EqualityOperator_SingleValueToList_WhenSingleElementDoesNotMatchValue_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
("world" == list).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_InequalityOperator_ListToSingleValue_WhenSingleElementMatchesValue_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
(list != "hello").Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_InequalityOperator_ListToSingleValue_WhenSingleElementDoesNotMatchValue_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
(list != "world").Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_InequalityOperator_SingleValueToList_WhenSingleElementMatchesValue_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
("hello" != list).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_InequalityOperator_SingleValueToList_WhenSingleElementDoesNotMatchValue_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("hello");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
("world" != list).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Equals and GetHashCode Tests
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenBothListsHaveSameElements_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>("a", "b", "c");
|
||||||
|
var list2 = new WireMockList<string>("a", "b", "c");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.Equals(list2).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenListsHaveDifferentElements_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>("a", "b");
|
||||||
|
var list2 = new WireMockList<string>("a", "x");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.Equals(list2).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenListsHaveDifferentCounts_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>("a", "b");
|
||||||
|
var list2 = new WireMockList<string>("a");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.Equals(list2).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenBothEmpty_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>();
|
||||||
|
var list2 = new WireMockList<string>();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.Equals(list2).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenSameReference_ShouldBeTrue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("a", "b");
|
||||||
|
var sameReference = list;
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list.Equals(sameReference).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenComparedToNull_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("a");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list.Should().NotBeNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_Equals_WhenComparedToNonWireMockList_ShouldBeFalse()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list = new WireMockList<string>("a");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list.Equals(new List<string> { "a" }).Should().BeFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_GetHashCode_WhenListsHaveSameElements_ShouldBeEqual()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>("a", "b", "c");
|
||||||
|
var list2 = new WireMockList<string>("a", "b", "c");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.GetHashCode().Should().Be(list2.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_GetHashCode_WhenListsHaveDifferentElements_ShouldNotBeEqual()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>("a", "b");
|
||||||
|
var list2 = new WireMockList<string>("x", "y");
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.GetHashCode().Should().NotBe(list2.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void WireMockListOfString_GetHashCode_WhenEmpty_ShouldReturnConsistentValue()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var list1 = new WireMockList<string>();
|
||||||
|
var list2 = new WireMockList<string>();
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
list1.GetHashCode().Should().Be(list2.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
+2
-2
@@ -2,8 +2,8 @@
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo1", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/foo1" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("p1", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "xyz"))
|
.WithParam("p1", new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "xyz"))
|
||||||
)
|
)
|
||||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
|
|||||||
+9
-9
@@ -2,8 +2,8 @@
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post2", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post2" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonPartialMatcher(
|
.WithBody(new WireMock.Matchers.JsonPartialMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
city = "City",
|
city = "City",
|
||||||
@@ -22,8 +22,8 @@ Some ""value"" in Line2")
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo2", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/foo2" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("p2", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "abc"))
|
.WithParam("p2", new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "abc"))
|
||||||
.WithHeader("h1", "W/\"234f2q3r\"", true)
|
.WithHeader("h1", "W/\"234f2q3r\"", true)
|
||||||
)
|
)
|
||||||
.WithGuid("4126dec8-470b-4eff-93bb-c24f83b8b1fd")
|
.WithGuid("4126dec8-470b-4eff-93bb-c24f83b8b1fd")
|
||||||
@@ -37,8 +37,8 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post1", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post1" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonMatcher(
|
.WithBody(new WireMock.Matchers.JsonMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
city = "Amsterdam",
|
city = "Amsterdam",
|
||||||
@@ -55,7 +55,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("DELETE")
|
.UsingMethod("DELETE")
|
||||||
.WithUrl(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "https://localhost/test", false, WireMock.Matchers.MatchOperator.Or))
|
.WithUrl(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "https://localhost/test" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("c9929240-7ae8-4a5d-8ed8-0913479f6eeb")
|
.WithGuid("c9929240-7ae8-4a5d-8ed8-0913479f6eeb")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -99,8 +99,8 @@ text
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo1", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/foo1" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("p1", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "xyz"))
|
.WithParam("p1", new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.And, "xyz"))
|
||||||
)
|
)
|
||||||
.WithGuid("f74fd144-df53-404f-8e35-da22a640bd5f")
|
.WithGuid("f74fd144-df53-404f-8e35-da22a640bd5f")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
#if NET6_0_OR_GREATER
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using WireMock.Net.Testcontainers.Utils;
|
||||||
|
|
||||||
|
namespace WireMock.Net.Tests.Facts;
|
||||||
|
|
||||||
|
[ExcludeFromCodeCoverage]
|
||||||
|
public sealed class RunOnDockerFact : FactAttribute
|
||||||
|
{
|
||||||
|
public RunOnDockerFact(
|
||||||
|
[CallerFilePath] string? sourceFilePath = null,
|
||||||
|
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||||
|
{
|
||||||
|
|
||||||
|
OSPlatform currentPlatform;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
currentPlatform = TestcontainersUtils.GetImageOSAsync.Value.Result;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Skip = $"Only run test when Docker is installed.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -15,7 +15,19 @@ public sealed class RunOnDockerPlatformFact : FactAttribute
|
|||||||
[CallerFilePath] string? sourceFilePath = null,
|
[CallerFilePath] string? sourceFilePath = null,
|
||||||
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
[CallerLineNumber] int sourceLineNumber = -1) : base(sourceFilePath, sourceLineNumber)
|
||||||
{
|
{
|
||||||
if (TestcontainersUtils.GetImageOSAsync.Value.Result != OSPlatform.Create(platform))
|
|
||||||
|
OSPlatform currentPlatform;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
currentPlatform = TestcontainersUtils.GetImageOSAsync.Value.Result;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Skip = $"Only run test when Docker is installed.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPlatform != OSPlatform.Create(platform))
|
||||||
{
|
{
|
||||||
Skip = $"Only run test when Docker OS Platform {platform} is used.";
|
Skip = $"Only run test when Docker OS Platform {platform} is used.";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/foo" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("test", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
.WithParam("test", new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
||||||
)
|
)
|
||||||
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -13,8 +13,8 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post1", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post1" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonMatcher(
|
.WithBody(new WireMock.Matchers.JsonMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
Request = "Hello?"
|
Request = "Hello?"
|
||||||
@@ -30,8 +30,8 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post2", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post2" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonMatcher(
|
.WithBody(new WireMock.Matchers.JsonMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
city = "Amsterdam",
|
city = "Amsterdam",
|
||||||
@@ -48,7 +48,7 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/form-urlencoded", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/form-urlencoded" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithHeader("Content-Type", "application/x-www-form-urlencoded", true)
|
.WithHeader("Content-Type", "application/x-www-form-urlencoded", true)
|
||||||
.WithBody("name=John Doe")
|
.WithBody("name=John Doe")
|
||||||
)
|
)
|
||||||
@@ -59,8 +59,8 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/regex", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/regex" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("foo", new RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, ".*", false, true, WireMock.Matchers.MatchOperator.Or))
|
.WithParam("foo", new WireMock.Matchers.RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { ".*" }, false, true, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931004")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931004")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -69,11 +69,11 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/todo/items", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/todo/items" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931005")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931005")
|
||||||
.InScenario("To do list")
|
.InScenario("To do list")
|
||||||
.WhenStateIs("TodoList State Started", 2)
|
.WillSetStateTo("TodoList State Started", 2)
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithBody("Buy milk")
|
.WithBody("Buy milk")
|
||||||
);
|
);
|
||||||
@@ -81,7 +81,7 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/delay", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/delay" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -91,7 +91,7 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/random-delay", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/random-delay" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -101,7 +101,7 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/prob" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
||||||
.WithProbability(0.1)
|
.WithProbability(0.1)
|
||||||
@@ -112,7 +112,7 @@ builder
|
|||||||
builder
|
builder
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/prob" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
||||||
.WithProbability(0.9)
|
.WithProbability(0.9)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/foo" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("test", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
.WithParam("test", new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
||||||
)
|
)
|
||||||
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -13,8 +13,8 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post1", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post1" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonMatcher(
|
.WithBody(new WireMock.Matchers.JsonMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
Request = "Hello?"
|
Request = "Hello?"
|
||||||
@@ -30,8 +30,8 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/users/post2", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/users/post2" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithBody(new JsonMatcher(
|
.WithBody(new WireMock.Matchers.JsonMatcher(
|
||||||
value: new
|
value: new
|
||||||
{
|
{
|
||||||
city = "Amsterdam",
|
city = "Amsterdam",
|
||||||
@@ -48,7 +48,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("POST")
|
.UsingMethod("POST")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/form-urlencoded", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/form-urlencoded" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithHeader("Content-Type", "application/x-www-form-urlencoded", true)
|
.WithHeader("Content-Type", "application/x-www-form-urlencoded", true)
|
||||||
.WithBody("name=John Doe")
|
.WithBody("name=John Doe")
|
||||||
)
|
)
|
||||||
@@ -59,8 +59,8 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/regex", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/regex" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
.WithParam("foo", new RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, ".*", false, true, WireMock.Matchers.MatchOperator.Or))
|
.WithParam("foo", new WireMock.Matchers.RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { ".*" }, false, true, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931004")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931004")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -69,11 +69,11 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/todo/items", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/todo/items" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931005")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931005")
|
||||||
.InScenario("To do list")
|
.InScenario("To do list")
|
||||||
.WhenStateIs("TodoList State Started", 2)
|
.WillSetStateTo("TodoList State Started", 2)
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithBody("Buy milk")
|
.WithBody("Buy milk")
|
||||||
);
|
);
|
||||||
@@ -81,7 +81,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/delay", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/delay" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931006")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -91,7 +91,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/random-delay", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/random-delay" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931007")
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
@@ -101,7 +101,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/prob" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931008")
|
||||||
.WithProbability(0.1)
|
.WithProbability(0.1)
|
||||||
@@ -112,7 +112,7 @@ server
|
|||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/prob", false, WireMock.Matchers.MatchOperator.Or))
|
.WithPath(new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { "/prob" }, false, WireMock.Matchers.MatchOperator.Or))
|
||||||
)
|
)
|
||||||
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
.WithGuid("98fae52e-76df-47d9-876f-2ee32e931009")
|
||||||
.WithProbability(0.9)
|
.WithProbability(0.9)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using AnyOfTypes;
|
using WireMock.Extensions;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Models;
|
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.Matchers;
|
namespace WireMock.Net.Tests.Matchers;
|
||||||
|
|
||||||
@@ -12,59 +11,155 @@ public class FormUrlEncodedMatcherTest
|
|||||||
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
private readonly CancellationToken _ct = TestContext.Current.CancellationToken;
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("*=*")]
|
[InlineData(true, "*=*")]
|
||||||
[InlineData("name=John Doe")]
|
[InlineData(true, "name=John Doe")]
|
||||||
[InlineData("name=*")]
|
[InlineData(false, "name=Stef")]
|
||||||
[InlineData("*=John Doe")]
|
[InlineData(false, "name=John Doe&name=Stef")]
|
||||||
[InlineData("email=johndoe@example.com")]
|
[InlineData(true, "name=*")]
|
||||||
[InlineData("email=*")]
|
[InlineData(true, "*=John Doe")]
|
||||||
[InlineData("*=johndoe@example.com")]
|
[InlineData(false, "*=Stef")]
|
||||||
[InlineData("name=John Doe", "email=johndoe@example.com")]
|
[InlineData(false, "*=John Doe&*=Stef")]
|
||||||
[InlineData("name=John Doe", "email=*")]
|
[InlineData(true, "email=johndoe@example.com")]
|
||||||
[InlineData("name=*", "email=*")]
|
[InlineData(true, "email=*")]
|
||||||
[InlineData("*=John Doe", "*=johndoe@example.com")]
|
[InlineData(true, "*=johndoe@example.com")]
|
||||||
public async Task FormUrlEncodedMatcher_IsMatch(params string[] patterns)
|
[InlineData(true, "name=John Doe", "email=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe", "email=*")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "email=*")]
|
||||||
|
[InlineData(true, "name=Stef", "email=*")]
|
||||||
|
[InlineData(true, "name=*", "email=*")]
|
||||||
|
[InlineData(true, "*=John Doe", "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "*=Stef", "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "*=johndoe@example.com")]
|
||||||
|
public async Task FormUrlEncodedMatcher_IsMatch_Single_Or(bool expected, params string[] patterns)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = new FormUrlEncodedContent(
|
using var content = new FormUrlEncodedContent(
|
||||||
[
|
[
|
||||||
new KeyValuePair<string, string>("name", "John Doe"),
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
]);
|
]);
|
||||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
|
|
||||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray());
|
var matcher = new FormUrlEncodedMatcher(patterns.ToAnyOfPatterns());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
score.Should().BeTrue();
|
score.Should().Be(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
[InlineData(true, "*=*")]
|
||||||
[InlineData(false, "name=John Doe")]
|
[InlineData(false, "name=John Doe")]
|
||||||
|
[InlineData(false, "name=Stef")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef")]
|
||||||
|
[InlineData(true, "name=*")]
|
||||||
|
[InlineData(false, "*=John Doe")]
|
||||||
|
[InlineData(false, "*=Stef")]
|
||||||
|
[InlineData(true, "*=John Doe&*=Stef")]
|
||||||
|
[InlineData(true, "email=johndoe@example.com")]
|
||||||
|
[InlineData(true, "email=*")]
|
||||||
|
[InlineData(true, "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe", "email=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe", "email=*")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "email=*")]
|
||||||
|
[InlineData(true, "name=Stef", "email=*")]
|
||||||
|
[InlineData(true, "name=*", "email=*")]
|
||||||
|
[InlineData(true, "*=John Doe", "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "*=Stef", "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "*=johndoe@example.com")]
|
||||||
|
public async Task FormUrlEncodedMatcher_IsMatch_Multiple_Or(bool expected, params string[] patterns)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using var content = new FormUrlEncodedContent(
|
||||||
|
[
|
||||||
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
|
new KeyValuePair<string, string>("name", "Stef"),
|
||||||
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
|
]);
|
||||||
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
|
|
||||||
|
var matcher = new FormUrlEncodedMatcher(patterns.ToAnyOfPatterns());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
score.Should().Be(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(true, "*=*")]
|
||||||
|
[InlineData(false, "name=John Doe")]
|
||||||
|
[InlineData(false, "name=Stef")]
|
||||||
|
[InlineData(false, "name=John Doe&name=Stef")]
|
||||||
[InlineData(false, "name=*")]
|
[InlineData(false, "name=*")]
|
||||||
[InlineData(false, "*=John Doe")]
|
[InlineData(false, "*=John Doe")]
|
||||||
|
[InlineData(false, "*=Stef")]
|
||||||
|
[InlineData(false, "*=John Doe&*=Stef")]
|
||||||
[InlineData(false, "email=johndoe@example.com")]
|
[InlineData(false, "email=johndoe@example.com")]
|
||||||
[InlineData(false, "email=*")]
|
[InlineData(false, "email=*")]
|
||||||
[InlineData(false, "*=johndoe@example.com")]
|
[InlineData(false, "*=johndoe@example.com")]
|
||||||
[InlineData(true, "name=John Doe", "email=johndoe@example.com")]
|
[InlineData(true, "name=John Doe", "email=johndoe@example.com")]
|
||||||
[InlineData(true, "name=John Doe", "email=*")]
|
[InlineData(true, "name=John Doe", "email=*")]
|
||||||
|
[InlineData(false, "name=John Doe&name=Stef", "email=*")]
|
||||||
|
[InlineData(false, "name=Stef", "email=*")]
|
||||||
[InlineData(true, "name=*", "email=*")]
|
[InlineData(true, "name=*", "email=*")]
|
||||||
[InlineData(true, "*=John Doe", "*=johndoe@example.com")]
|
[InlineData(true, "*=John Doe", "*=johndoe@example.com")]
|
||||||
[InlineData(true, "*=*")]
|
[InlineData(false, "*=Stef", "*=johndoe@example.com")]
|
||||||
public async Task FormUrlEncodedMatcher_IsMatch_And(bool expected, params string[] patterns)
|
[InlineData(false, "name=John Doe&name=Stef", "*=johndoe@example.com")]
|
||||||
|
public async Task FormUrlEncodedMatcher_IsMatch_Single_And(bool expected, params string[] patterns)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = new FormUrlEncodedContent(
|
using var content = new FormUrlEncodedContent(
|
||||||
[
|
[
|
||||||
new KeyValuePair<string, string>("name", "John Doe"),
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
]);
|
]);
|
||||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
|
|
||||||
var matcher = new FormUrlEncodedMatcher(patterns.Select(p => new AnyOf<string, StringPattern>(p)).ToArray(), true, MatchOperator.And);
|
var matcher = new FormUrlEncodedMatcher(patterns.ToAnyOfPatterns(), true, MatchOperator.And);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
score.Should().Be(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(true, "*=*")]
|
||||||
|
[InlineData(false, "name=John Doe")]
|
||||||
|
[InlineData(false, "name=Stef")]
|
||||||
|
[InlineData(false, "name=John Doe&name=Stef")]
|
||||||
|
[InlineData(false, "name=*")]
|
||||||
|
[InlineData(false, "*=John Doe")]
|
||||||
|
[InlineData(false, "*=Stef")]
|
||||||
|
[InlineData(false, "*=John Doe&*=Stef")]
|
||||||
|
[InlineData(false, "email=johndoe@example.com")]
|
||||||
|
[InlineData(false, "email=*")]
|
||||||
|
[InlineData(false, "*=johndoe@example.com")]
|
||||||
|
[InlineData(false, "name=John Doe", "email=johndoe@example.com")]
|
||||||
|
[InlineData(false, "name=John Doe", "email=*")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "email=*")]
|
||||||
|
[InlineData(false, "name=Stef", "email=*")]
|
||||||
|
[InlineData(true, "name=*", "email=*")]
|
||||||
|
[InlineData(false, "*=John Doe", "*=johndoe@example.com")]
|
||||||
|
[InlineData(false, "*=Stef", "*=johndoe@example.com")]
|
||||||
|
[InlineData(true, "name=John Doe&name=Stef", "*=johndoe@example.com")]
|
||||||
|
public async Task FormUrlEncodedMatcher_IsMatch_Multiple_And(bool expected, params string[] patterns)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using var content = new FormUrlEncodedContent(
|
||||||
|
[
|
||||||
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
|
new KeyValuePair<string, string>("name", "Stef"),
|
||||||
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
|
]);
|
||||||
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
|
|
||||||
|
var matcher = new FormUrlEncodedMatcher(patterns.ToAnyOfPatterns(), true, MatchOperator.And);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
||||||
@@ -74,12 +169,13 @@ public class FormUrlEncodedMatcherTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties()
|
public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties_MissingRequiredKey_ShouldNotMatch()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var content = new FormUrlEncodedContent(
|
using var content = new FormUrlEncodedContent(
|
||||||
[
|
[
|
||||||
new KeyValuePair<string, string>("name", "John Doe"),
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
|
new KeyValuePair<string, string>("name", "Stef"),
|
||||||
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
]);
|
]);
|
||||||
var contentAsString = await content.ReadAsStringAsync(_ct);
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
@@ -93,4 +189,25 @@ public class FormUrlEncodedMatcherTest
|
|||||||
// Assert
|
// Assert
|
||||||
score.Should().BeFalse();
|
score.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task FormUrlEncodedMatcher_IsMatch_And_MatchAllProperties_ConflictingEmailPatterns_ShouldNotMatch()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
using var content = new FormUrlEncodedContent(
|
||||||
|
[
|
||||||
|
new KeyValuePair<string, string>("name", "John Doe"),
|
||||||
|
new KeyValuePair<string, string>("name", "Stef"),
|
||||||
|
new KeyValuePair<string, string>("email", "johndoe@example.com")
|
||||||
|
]);
|
||||||
|
var contentAsString = await content.ReadAsStringAsync(_ct);
|
||||||
|
|
||||||
|
var matcher = new FormUrlEncodedMatcher(["name=*", "email=*", "email=x"], matchOperator: MatchOperator.And);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var score = matcher.IsMatch(contentAsString).IsPerfect();
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
score.Should().BeFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ public class FuncMatcherTests
|
|||||||
var code = matcher.GetCSharpCodeArguments();
|
var code = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
code.Should().Be("new FuncMatcher(/* Func<string?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
code.Should().Be("new WireMock.Matchers.FuncMatcher(/* Func<string?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -271,7 +271,7 @@ public class FuncMatcherTests
|
|||||||
var code = matcher.GetCSharpCodeArguments();
|
var code = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
code.Should().Be("new FuncMatcher(/* Func<byte[]?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
code.Should().Be("new WireMock.Matchers.FuncMatcher(/* Func<byte[]?, bool> function */, WireMock.Matchers.MatchBehaviour.AcceptOnMatch)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ public class JsonMatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().StartWith($"new JsonMatcher(WireMock.Matchers.MatchBehaviour.{matchBehaviour},");
|
result.Should().StartWith($"new WireMock.Matchers.JsonMatcher(WireMock.Matchers.MatchBehaviour.{matchBehaviour},");
|
||||||
result.Should().EndWith($", {ignoreCase.ToString().ToLowerInvariant()}, {regex.ToString().ToLowerInvariant()}, {ignoreArrayOrder.ToString().ToLowerInvariant()})");
|
result.Should().EndWith($", {ignoreCase.ToString().ToLowerInvariant()}, {regex.ToString().ToLowerInvariant()}, {ignoreArrayOrder.ToString().ToLowerInvariant()})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new ContentTypeMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, \"application/json\", false)");
|
result.Should().Be("new WireMock.Matchers.ContentTypeMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { \"application/json\" }, false)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -27,7 +27,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, \"test\")");
|
result.Should().Be("new WireMock.Matchers.ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, \"test\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -53,7 +53,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new FormUrlEncodedMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, \"key=value\", false, WireMock.Matchers.MatchOperator.Or)");
|
result.Should().Be("new WireMock.Matchers.FormUrlEncodedMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { \"key=value\" }, false, WireMock.Matchers.MatchOperator.Or)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -66,7 +66,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new JmesPathMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"expression\")");
|
result.Should().Be("new WireMock.Matchers.JmesPathMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"expression\")");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -79,7 +79,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().StartWith("new JsonMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
result.Should().StartWith("new WireMock.Matchers.JsonMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -92,7 +92,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().StartWith("new JsonPartialMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
result.Should().StartWith("new WireMock.Matchers.JsonPartialMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -105,7 +105,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().StartWith("new JsonPartialWildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
result.Should().StartWith("new WireMock.Matchers.JsonPartialWildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Fact]
|
//[Fact]
|
||||||
@@ -118,7 +118,7 @@ public class MatcherTests
|
|||||||
// var result = matcher.GetCSharpCodeArguments();
|
// var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// // Assert
|
// // Assert
|
||||||
// result.Should().Be("new LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"it.Contains(\\\"test\\\"\")");
|
// result.Should().Be("new WireMock.Matchers.LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"it.Contains(\\\"test\\\"\")");
|
||||||
//}
|
//}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -131,7 +131,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, \"pattern\", false, true, WireMock.Matchers.MatchOperator.Or)");
|
result.Should().Be("new WireMock.Matchers.RegexMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { \"pattern\" }, false, true, WireMock.Matchers.MatchOperator.Or)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -144,7 +144,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new SimMetricsMatcher.Levenstein(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, \"test\", SimMetrics.Net.SimMetricType.Levenstein, WireMock.Matchers.MatchOperator.Average)");
|
result.Should().Be("new WireMock.Matchers.SimMetricsMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { \"test\" }, SimMetrics.Net.SimMetricType.Levenstein, WireMock.Matchers.MatchOperator.Average)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -157,7 +157,7 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, \"pattern\", false, WireMock.Matchers.MatchOperator.Or)");
|
result.Should().Be("new WireMock.Matchers.WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern>[] { \"pattern\" }, false, WireMock.Matchers.MatchOperator.Or)");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -170,6 +170,6 @@ public class MatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().Be("new XPathMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, null, \"pattern1\")");
|
result.Should().Be("new WireMock.Matchers.XPathMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, null, \"pattern1\")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,7 +478,7 @@ public class SystemTextJsonMatcherTests
|
|||||||
var result = matcher.GetCSharpCodeArguments();
|
var result = matcher.GetCSharpCodeArguments();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
result.Should().StartWith($"new SystemTextJsonMatcher(WireMock.Matchers.MatchBehaviour.{matchBehaviour},");
|
result.Should().StartWith($"new WireMock.Matchers.SystemTextJsonMatcher(WireMock.Matchers.MatchBehaviour.{matchBehaviour},");
|
||||||
result.Should().EndWith($", {ignoreCase.ToString().ToLowerInvariant()}, {regex.ToString().ToLowerInvariant()}, {ignoreArrayOrder.ToString().ToLowerInvariant()})");
|
result.Should().EndWith($", {ignoreCase.ToString().ToLowerInvariant()}, {regex.ToString().ToLowerInvariant()}, {ignoreArrayOrder.ToString().ToLowerInvariant()})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,38 @@ public class WireMockOpenApiParserTests
|
|||||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "payroc-openapi-spec.yaml"));
|
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "payroc-openapi-spec.yaml"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var mappings = _sut.FromText(openApiDocument, settings, out _);
|
var mappings = _sut.FromText(openApiDocument, settings, out var diagnostic);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
mappings.Should().NotBeEmpty();
|
||||||
|
diagnostic.Should().NotBeNull();
|
||||||
|
diagnostic.Errors.Should().BeEmpty();
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
await Verify(mappings);
|
await Verify(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void FromText_UsingInvalidYaml_ShouldReturnEmptyMappingsWithDiagnostic()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var settings = new WireMockOpenApiParserSettings
|
||||||
|
{
|
||||||
|
ExampleValues = _exampleValuesMock.Object
|
||||||
|
};
|
||||||
|
|
||||||
|
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "invalid.yaml"));
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var mappings = _sut.FromText(openApiDocument, settings, out var diagnostic);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
mappings.Should().BeEmpty();
|
||||||
|
diagnostic.Should().NotBeNull();
|
||||||
|
diagnostic.Errors.Should().HaveCount(1);
|
||||||
|
diagnostic.Errors[0].Message.Should().Be("Responses must contain at least one response");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task FromText_UsingJson_WithPlainTextExample_ShouldReturnMappings()
|
public async Task FromText_UsingJson_WithPlainTextExample_ShouldReturnMappings()
|
||||||
{
|
{
|
||||||
@@ -54,7 +80,12 @@ public class WireMockOpenApiParserTests
|
|||||||
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "oas-content-example.json"));
|
var openApiDocument = File.ReadAllText(Path.Combine("OpenApiParser", "oas-content-example.json"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var mappings = _sut.FromText(openApiDocument, settings, out _);
|
var mappings = _sut.FromText(openApiDocument, settings, out var diagnostic);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
mappings.Should().NotBeEmpty();
|
||||||
|
diagnostic.Should().NotBeNull();
|
||||||
|
diagnostic.Errors.Should().BeEmpty();
|
||||||
|
|
||||||
// Verify
|
// Verify
|
||||||
await Verify(mappings);
|
await Verify(mappings);
|
||||||
|
|||||||
Loaded 100 of 132 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user