mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-13 20:49:56 +02:00
Compare commits
3 Commits
1.5.59
...
stef-1062-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44be24a129 | ||
|
|
0185b116ca | ||
|
|
237cd227d9 |
32
.github/workflows/ci.yml
vendored
32
.github/workflows/ci.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: Run Tests
|
name: Build with Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -10,29 +10,47 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
windows-build-and-run:
|
windows-build-and-run:
|
||||||
name: Run Tests on Windows
|
|
||||||
runs-on: windows-2022
|
runs-on: windows-2022
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IsRunningOnGitHubActions: 'true'
|
IsRunningOnGitHubActions: 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: |
|
||||||
|
7.0.x
|
||||||
|
8.0.x
|
||||||
|
|
||||||
|
- name: 'Build Unit Tests'
|
||||||
|
run: |
|
||||||
|
dotnet build './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
|
||||||
|
|
||||||
- name: 'Run Unit Tests'
|
- name: 'Run Unit Tests'
|
||||||
run: |
|
run: |
|
||||||
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net8.0
|
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
|
||||||
|
|
||||||
linux-build-and-run:
|
linux-build-and-run:
|
||||||
name: Run Tests on Linux
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
env:
|
env:
|
||||||
IsRunningOnGitHubActions: 'true'
|
IsRunningOnGitHubActions: 'true'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-dotnet@v3
|
||||||
|
with:
|
||||||
|
dotnet-version: |
|
||||||
|
7.0.x
|
||||||
|
8.0.x
|
||||||
|
|
||||||
|
- name: 'Build Unit Tests'
|
||||||
|
run: |
|
||||||
|
dotnet build './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
|
||||||
|
|
||||||
- name: 'Run Unit Tests'
|
- name: 'Run Unit Tests'
|
||||||
run: |
|
run: |
|
||||||
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net8.0
|
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
|
||||||
50
CHANGELOG.md
50
CHANGELOG.md
@@ -1,53 +1,3 @@
|
|||||||
# 1.5.59 (26 June 2024)
|
|
||||||
- [#1127](https://github.com/WireMock-Net/WireMock.Net/pull/1127) - Made changes to accommodate breaking change in testcontainers-dotnet 3.9 [feature] contributed by [epDugas](https://github.com/epDugas)
|
|
||||||
|
|
||||||
# 1.5.58 (08 June 2024)
|
|
||||||
- [#1116](https://github.com/WireMock-Net/WireMock.Net/pull/1116) - Add some methods to the BodyModelBuilder [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1117](https://github.com/WireMock-Net/WireMock.Net/issues/1117) - AbstractJsonPartialMatcher: Regex Value is Uppercased when IgnoreCase is set to true [bug]
|
|
||||||
|
|
||||||
# 1.5.57 (04 June 2024)
|
|
||||||
- [#1113](https://github.com/WireMock-Net/WireMock.Net/pull/1113) - Add some Extension methods to IWireMockAdminApi [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
|
|
||||||
# 1.5.56 (03 June 2024)
|
|
||||||
- [#1111](https://github.com/WireMock-Net/WireMock.Net/pull/1111) - Fix Request.Create().WithBodyAsJson(...) [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1112](https://github.com/WireMock-Net/WireMock.Net/pull/1112) - Add "/__admin/health" endpoint [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1110](https://github.com/WireMock-Net/WireMock.Net/issues/1110) - Connection prematurely closed BEFORE response [bug]
|
|
||||||
|
|
||||||
# 1.5.55 (22 May 2024)
|
|
||||||
- [#1107](https://github.com/WireMock-Net/WireMock.Net/pull/1107) - When only Port is provided, bind to * (Fixes #1100) [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
|
|
||||||
# 1.5.54 (18 May 2024)
|
|
||||||
- [#1100](https://github.com/WireMock-Net/WireMock.Net/pull/1100) - Add support to bind to ip-address instead of only localhost [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1104](https://github.com/WireMock-Net/WireMock.Net/pull/1104) - Use try..catch to set encoding in WireMockConsoleLogger [feature] contributed by [asherber](https://github.com/asherber)
|
|
||||||
|
|
||||||
# 1.5.53 (08 May 2024)
|
|
||||||
- [#1093](https://github.com/WireMock-Net/WireMock.Net/pull/1093) - Update Handlebars.Net [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1101](https://github.com/WireMock-Net/WireMock.Net/pull/1101) - Fix MappingConverter to support Body with JsonMatcher [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1095](https://github.com/WireMock-Net/WireMock.Net/issues/1095) - When using C# code generation WithBody() matcher is not generated for POST Request [bug]
|
|
||||||
|
|
||||||
# 1.5.52 (06 April 2024)
|
|
||||||
- [#1091](https://github.com/WireMock-Net/WireMock.Net/pull/1091) - Add RegEx support to JsonMatcher [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1088](https://github.com/WireMock-Net/WireMock.Net/issues/1088) - Regex support for JsonMatcher [feature]
|
|
||||||
|
|
||||||
# 1.5.51 (20 March 2024)
|
|
||||||
- [#1085](https://github.com/WireMock-Net/WireMock.Net/pull/1085) - Fix FluentAssertions (actual body is not displayed in error message) [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1084](https://github.com/WireMock-Net/WireMock.Net/issues/1084) - FluentAssertions - Actual body is not displayed in error message when using Json Body [bug]
|
|
||||||
|
|
||||||
# 1.5.50 (12 March 2024)
|
|
||||||
- [#1080](https://github.com/WireMock-Net/WireMock.Net/pull/1080) - Fix FluentAssertions on Header(s) [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1082](https://github.com/WireMock-Net/WireMock.Net/pull/1082) - Make WireMockAssertions extendable [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1074](https://github.com/WireMock-Net/WireMock.Net/issues/1074) - FluentAssertions extensions do not filter headers correctly [bug]
|
|
||||||
- [#1075](https://github.com/WireMock-Net/WireMock.Net/issues/1075) - FluentAssertions extensions are not open for extension [feature]
|
|
||||||
|
|
||||||
# 1.5.49 (06 March 2024)
|
|
||||||
- [#1069](https://github.com/WireMock-Net/WireMock.Net/pull/1069) - Extend TypeLoader [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1078](https://github.com/WireMock-Net/WireMock.Net/pull/1078) - Upgrade ProtoBufJsonConverter to fix issue with dot(s) in package name [bug] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1077](https://github.com/WireMock-Net/WireMock.Net/issues/1077) - ProtoBufMatcher not working when proto package name contains dots [bug]
|
|
||||||
|
|
||||||
# 1.5.48 (22 February 2024)
|
|
||||||
- [#1047](https://github.com/WireMock-Net/WireMock.Net/pull/1047) - Add Grpc ProtoBuf support (request-response) [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#1058](https://github.com/WireMock-Net/WireMock.Net/pull/1058) - Fix some SonarCloud issues [refactor] contributed by [StefH](https://github.com/StefH)
|
|
||||||
|
|
||||||
# 1.5.47 (25 January 2024)
|
# 1.5.47 (25 January 2024)
|
||||||
- [#1049](https://github.com/WireMock-Net/WireMock.Net/pull/1049) - Add WithoutHeader to WireMock.FluentAssertions [feature] contributed by [StefH](https://github.com/StefH)
|
- [#1049](https://github.com/WireMock-Net/WireMock.Net/pull/1049) - Add WithoutHeader to WireMock.FluentAssertions [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#1053](https://github.com/WireMock-Net/WireMock.Net/pull/1053) - [Snyk] Security upgrade Microsoft.IdentityModel.Protocols.OpenIdConnect from 6.12.2 to 6.34.0 [security] contributed by [StefH](https://github.com/StefH)
|
- [#1053](https://github.com/WireMock-Net/WireMock.Net/pull/1053) - [Snyk] Security upgrade Microsoft.IdentityModel.Protocols.OpenIdConnect from 6.12.2 to 6.34.0 [security] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.5.59</VersionPrefix>
|
<VersionPrefix>1.5.47</VersionPrefix>
|
||||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
rem https://github.com/StefH/GitHubReleaseNotes
|
rem https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
SET version=1.5.59
|
SET version=1.5.47
|
||||||
|
|
||||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%
|
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%
|
||||||
|
|
||||||
GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --template PackageReleaseNotes.template --version %version% --token %GH_TOKEN%
|
GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate --template PackageReleaseNotes.template --version %version% --token %GH_TOKEN%
|
||||||
@@ -1,4 +1,10 @@
|
|||||||
# 1.5.59 (26 June 2024)
|
# 1.5.47 (25 January 2024)
|
||||||
- #1127 Made changes to accommodate breaking change in testcontainers-dotnet 3.9 [feature]
|
- #1049 Add WithoutHeader to WireMock.FluentAssertions [feature]
|
||||||
|
- #1053 [Snyk] Security upgrade Microsoft.IdentityModel.Protocols.OpenIdConnect from 6.12.2 to 6.34.0 [security]
|
||||||
|
- #1055 Bump System.IdentityModel.Tokens.Jwt from 6.25.0 to 6.34.0 in /examples/WireMock.Net.Console.Net472.Classic [example]
|
||||||
|
- #1057 Pin the version from Testcontainers to 3.7.0 in WireMock.Net.Testcontainers [bug]
|
||||||
|
- #1048 WithoutHeader fluent assertion [feature]
|
||||||
|
- #1054 WireMock.Net 1.5.46 is incompatible with TestContainers 3.7.0 (issue 1) [bug]
|
||||||
|
- #1059 WireMock.Net 1.5.46 is incompatible with TestContainers 3.7.0 (issue 2) [bug]
|
||||||
|
|
||||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||||
@@ -17,7 +17,6 @@ For more info, see also this WIKI page: [What is WireMock.Net](https://github.co
|
|||||||
## :memo: Blogs
|
## :memo: Blogs
|
||||||
- [mstack.nl : Generate C# Code from Mapping(s)](https://mstack.nl/blog/20230201-wiremock.net-tocode/)
|
- [mstack.nl : Generate C# Code from Mapping(s)](https://mstack.nl/blog/20230201-wiremock.net-tocode/)
|
||||||
- [mstack.nl : Chaos Engineering with Fault Injections](https://mstack.nl/blogs/wiremock-net-chaos-engineering-with-fault-injections/)
|
- [mstack.nl : Chaos Engineering with Fault Injections](https://mstack.nl/blogs/wiremock-net-chaos-engineering-with-fault-injections/)
|
||||||
- [mstack.nl : gRPC / ProtoBuf Support](https://mstack.nl/blogs/wiremock-net-grpc/)
|
|
||||||
|
|
||||||
|
|
||||||
## :computer: Project Info
|
## :computer: Project Info
|
||||||
@@ -92,3 +91,4 @@ For more details see also [Docker](https://github.com/WireMock-Net/WireMock.Net-
|
|||||||
|
|
||||||
#### HTTPS / SSL
|
#### HTTPS / SSL
|
||||||
More details on using HTTPS (SSL) can be found here [Wiki : HTTPS](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-(SSL))
|
More details on using HTTPS (SSL) can be found here [Wiki : HTTPS](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-HTTPS-(SSL))
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Net472
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{1DAEFF47-D117-4E95-8B3E-4F7C8B92011A}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{1DAEFF47-D117-4E95-8B3E-4F7C8B92011A}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
.github\workflows\ci.yml = .github\workflows\ci.yml
|
..\System.Linq.Dynamic.Core\.github\workflows\ci.yml = ..\System.Linq.Dynamic.Core\.github\workflows\ci.yml
|
||||||
.github\workflows\CreateRelease.yml = .github\workflows\CreateRelease.yml
|
.github\workflows\CreateRelease.yml = .github\workflows\CreateRelease.yml
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
@@ -112,8 +112,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NET8",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMockAzureQueueProxy", "examples\WireMockAzureQueueProxy\WireMockAzureQueueProxy.csproj", "{7FC0B409-2682-40EE-B3B9-3930D6769D01}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMockAzureQueueProxy", "examples\WireMockAzureQueueProxy\WireMockAzureQueueProxy.csproj", "{7FC0B409-2682-40EE-B3B9-3930D6769D01}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.GrpcClient", "examples\WireMock.Net.Console.GrpcClient\WireMock.Net.Console.GrpcClient.csproj", "{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}"
|
|
||||||
EndProject
|
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -264,10 +262,6 @@ Global
|
|||||||
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7FC0B409-2682-40EE-B3B9-3930D6769D01}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -311,7 +305,6 @@ Global
|
|||||||
{941229D6-191B-4B5E-AC81-0905EBF4F19D} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{941229D6-191B-4B5E-AC81-0905EBF4F19D} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{1EA72C0F-92E9-486B-8FFE-53F992BFC4AA} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{1EA72C0F-92E9-486B-8FFE-53F992BFC4AA} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{7FC0B409-2682-40EE-B3B9-3930D6769D01} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{7FC0B409-2682-40EE-B3B9-3930D6769D01} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{B1580A38-84E7-44BE-8FE7-3EE5031D74A1} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
||||||
|
|||||||
@@ -23,17 +23,14 @@
|
|||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WWW/@EntryIndexedValue">WWW</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WWW/@EntryIndexedValue">WWW</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XMS/@EntryIndexedValue">XMS</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XMS/@EntryIndexedValue">XMS</s:String>
|
||||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XUA/@EntryIndexedValue">XUA</s:String>
|
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XUA/@EntryIndexedValue">XUA</s:String>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dlls/@EntryIndexedValue">True</s:Boolean>
|
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Flurl/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Flurl/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=funcs/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=funcs/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Grpc/@EntryIndexedValue">True</s:Boolean>
|
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=guidb/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=guidb/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Guids/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Guids/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=openapi/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=openapi/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pacticipant/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pacticipant/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=protobuf/@EntryIndexedValue">True</s:Boolean>
|
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriban/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriban/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|||||||
@@ -14,45 +14,53 @@ jobs:
|
|||||||
echo "BuildId = $(buildId)"
|
echo "BuildId = $(buildId)"
|
||||||
displayName: 'Print buildId'
|
displayName: 'Print buildId'
|
||||||
|
|
||||||
- script: |
|
- task: UseDotNet@2
|
||||||
dotnet tool install --global dotnet-sonarscanner
|
displayName: Use .NET 8.0
|
||||||
dotnet tool install --global dotnet-coverage
|
inputs:
|
||||||
dotnet tool install --global coverlet.console
|
packageType: 'sdk'
|
||||||
displayName: 'Install dotnet tools'
|
version: '8.0.x'
|
||||||
|
|
||||||
- task: PowerShell@2
|
- task: PowerShell@2
|
||||||
displayName: "Use JDK17 by default"
|
displayName: "Use JDK11 by default"
|
||||||
inputs:
|
inputs:
|
||||||
targetType: 'inline'
|
targetType: 'inline'
|
||||||
script: |
|
script: |
|
||||||
$jdkPath = $env:JAVA_HOME_17_X64
|
$jdkPath = $env:JAVA_HOME_11_X64
|
||||||
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
|
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
|
||||||
|
|
||||||
- script: |
|
- script: |
|
||||||
dotnet dev-certs https --trust || true
|
dotnet dev-certs https --trust || true
|
||||||
displayName: 'dotnet dev-certs https'
|
displayName: 'dotnet dev-certs https'
|
||||||
|
|
||||||
# See: https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/dotnet-test-coverage
|
- task: SonarCloudPrepare@1
|
||||||
- script: |
|
displayName: 'Prepare analysis on SonarCloud'
|
||||||
dotnet sonarscanner begin /k:"WireMock-Net_WireMock.Net" /o:"wiremock-net" /d:sonar.branch.name=$(Build.SourceBranchName) /d:sonar.host.url="https://sonarcloud.io" /d:sonar.token="$(SONAR_TOKEN)" /d:sonar.dotnet.excludeTestProjects=true /d:sonar.cs.vscoveragexml.reportsPaths=**/wiremock-coverage.xml /d:sonar.verbose=true
|
|
||||||
displayName: 'Begin analysis on SonarCloud'
|
|
||||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
inputs:
|
||||||
|
SonarCloud: SonarCloud
|
||||||
|
organization: wiremock-net
|
||||||
|
projectKey: 'WireMock-Net_WireMock.Net'
|
||||||
|
projectName: 'WireMock.Net'
|
||||||
|
extraProperties: |
|
||||||
|
sonar.cs.opencover.reportsPaths=**/coverage.net8.0.opencover.xml
|
||||||
|
|
||||||
- task: DotNetCoreCLI@2
|
- task: DotNetCoreCLI@2
|
||||||
displayName: 'Build Unit tests'
|
displayName: 'Build Unit tests'
|
||||||
inputs:
|
inputs:
|
||||||
command: 'build'
|
command: 'build'
|
||||||
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
|
||||||
arguments: '--configuration Debug --framework net8.0 --no-incremental'
|
arguments: '--configuration Debug --framework net8.0'
|
||||||
|
|
||||||
- task: CmdLine@2
|
- task: CmdLine@2
|
||||||
inputs:
|
inputs:
|
||||||
script: 'dotnet-coverage collect "dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration Debug --no-build --framework net8.0" -f xml -o "wiremock-coverage.xml"'
|
script: 'dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --no-build --configuration Debug --framework net8.0'
|
||||||
displayName: 'Execute Unit Tests with Coverage'
|
displayName: 'Execute Unit Tests with Coverage'
|
||||||
|
|
||||||
|
- task: SonarCloudAnalyze@1
|
||||||
|
displayName: 'SonarCloud: Run Code Analysis'
|
||||||
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
|
||||||
- script: |
|
- task: SonarCloudPublish@1
|
||||||
dotnet sonarscanner end /d:sonar.token="$(SONAR_TOKEN)"
|
displayName: 'SonarCloud: Publish Quality Gate Result'
|
||||||
displayName: 'End analysis on SonarCloud'
|
|
||||||
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
|
||||||
|
|
||||||
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19
|
||||||
|
|||||||
@@ -14,13 +14,10 @@ class Program
|
|||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
// Start WireMock.Net tool with Admin interface
|
|
||||||
// dotnet-wiremock --StartAdminInterface
|
|
||||||
|
|
||||||
// Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
|
// Create an implementation of the IWireMockAdminApi and pass in the base URL for the API.
|
||||||
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
|
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
|
||||||
|
|
||||||
await api.ResetMappingsAsync().ConfigureAwait(false);
|
// await api.ResetMappingsAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
var mappingBuilder = api.GetMappingBuilder();
|
var mappingBuilder = api.GetMappingBuilder();
|
||||||
mappingBuilder.Given(m => m
|
mappingBuilder.Given(m => m
|
||||||
@@ -54,32 +51,13 @@ class Program
|
|||||||
.WithPath("/bla3")
|
.WithPath("/bla3")
|
||||||
)
|
)
|
||||||
.WithResponse(rsp => rsp
|
.WithResponse(rsp => rsp
|
||||||
.WithBodyAsJson(new
|
.WithBodyAsJson(new
|
||||||
{
|
{
|
||||||
x = "test"
|
x = "test"
|
||||||
}, true)
|
}, true)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
mappingBuilder.Given(m => m
|
|
||||||
.WithRequest(req => req
|
|
||||||
.WithPath("/test1")
|
|
||||||
.UsingPost()
|
|
||||||
.WithBody(b => b
|
|
||||||
.WithJmesPathMatcher("things.name == 'RequiredThing'")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.WithResponse(rsp => rsp
|
|
||||||
.WithHeaders(h => h.Add("Content-Type", "application/json"))
|
|
||||||
.WithDelay(TimeSpan.FromMilliseconds(50))
|
|
||||||
.WithStatusCode(200)
|
|
||||||
.WithBodyAsJson(new
|
|
||||||
{
|
|
||||||
status = "ok"
|
|
||||||
}, true)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
|
var result = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
|
||||||
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");
|
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");
|
||||||
|
|
||||||
@@ -134,9 +112,6 @@ class Program
|
|||||||
var getFileResult = await api.GetFileAsync("1.cs");
|
var getFileResult = await api.GetFileAsync("1.cs");
|
||||||
Console.WriteLine($"getFileResult = {getFileResult}");
|
Console.WriteLine($"getFileResult = {getFileResult}");
|
||||||
|
|
||||||
Console.WriteLine("Press any key to reset mappings");
|
|
||||||
Console.ReadKey();
|
|
||||||
|
|
||||||
var resetMappingsAsync = await api.ResetMappingsAsync();
|
var resetMappingsAsync = await api.ResetMappingsAsync();
|
||||||
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");
|
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"WSL": {
|
||||||
|
"commandName": "WSL2",
|
||||||
|
"distributionName": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
using Greet;
|
|
||||||
using Grpc.Net.Client;
|
|
||||||
|
|
||||||
namespace WireMock.Net.Console.GrpcClient;
|
|
||||||
|
|
||||||
internal class Program
|
|
||||||
{
|
|
||||||
static async Task Main(string[] args)
|
|
||||||
{
|
|
||||||
var channel = GrpcChannel.ForAddress("http://localhost:9093/grpc3", new GrpcChannelOptions
|
|
||||||
{
|
|
||||||
Credentials = Grpc.Core.ChannelCredentials.Insecure
|
|
||||||
});
|
|
||||||
|
|
||||||
var client = new Greeter.GreeterClient(channel);
|
|
||||||
|
|
||||||
var reply = await client.SayHelloAsync(new HelloRequest { Name = "stef" });
|
|
||||||
|
|
||||||
System.Console.WriteLine("Greeting: " + reply.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.25.1" />
|
|
||||||
<PackageReference Include="Grpc.Net.Client" Version="2.59.0" />
|
|
||||||
<PackageReference Include="Grpc.Tools" Version="2.60.0">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Protobuf Include="greet.proto" GrpcServices="Client" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// Copyright 2019 The gRPC Authors
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package greet;
|
|
||||||
|
|
||||||
// The greeting service definition.
|
|
||||||
service Greeter {
|
|
||||||
// Sends a greeting
|
|
||||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The request message containing the user's name.
|
|
||||||
message HelloRequest {
|
|
||||||
string name = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The response message containing the greetings
|
|
||||||
message HelloReply {
|
|
||||||
string message = 1;
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using MimeKit;
|
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
@@ -20,90 +18,17 @@ internal class Program
|
|||||||
Logger = new WireMockConsoleLogger(),
|
Logger = new WireMockConsoleLogger(),
|
||||||
});
|
});
|
||||||
|
|
||||||
server
|
server.Given(Request.Create().UsingPost().WithPath("/some/endpoint"))
|
||||||
.Given(Request.Create()
|
.RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Created));
|
||||||
.UsingPost()
|
|
||||||
.WithPath("/test")
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithBody(requestMessage => requestMessage.BodyAsMimeMessage != null ?
|
|
||||||
"BodyAsMimeMessage is present" :
|
|
||||||
"BodyAsMimeMessage is not present")
|
|
||||||
);
|
|
||||||
|
|
||||||
server
|
var httpClient = new HttpClient { BaseAddress = new Uri(server.Url!) };
|
||||||
.Given(Request.Create()
|
var requestUri = new Uri(httpClient.BaseAddress!, "some/endpoint");
|
||||||
.UsingPost()
|
var content = new StringContent(string.Empty, Encoding.UTF8, "application/json");
|
||||||
.WithPath("/some/endpoint")
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithStatusCode(HttpStatusCode.Created)
|
|
||||||
);
|
|
||||||
|
|
||||||
var httpClient = server.CreateClient();
|
|
||||||
var content = new StringContent("abc", Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
await TestAsync(httpClient, content);
|
|
||||||
|
|
||||||
await TestNoMultiPartAsync(httpClient, content);
|
|
||||||
|
|
||||||
await TestMultiPartAsync(server);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task TestNoMultiPartAsync(HttpClient httpClient, StringContent content)
|
|
||||||
{
|
|
||||||
var response = await httpClient.PostAsync("/test", content);
|
|
||||||
|
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
||||||
(await response.Content.ReadAsStringAsync()).Should().Be("BodyAsMimeMessage is not present");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task TestAsync(HttpClient httpClient, StringContent content)
|
|
||||||
{
|
|
||||||
var response = await httpClient.PostAsync("some/endpoint", content);
|
|
||||||
|
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.Created);
|
|
||||||
(await response.Content.ReadAsStringAsync()).Should().BeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task TestMultiPartAsync(WireMockServer server)
|
|
||||||
{
|
|
||||||
var textPlainContent = "This is some plain text";
|
|
||||||
var textPlainContentType = "text/plain";
|
|
||||||
|
|
||||||
var textJson = "{ \"Key\" : \"Value\" }";
|
|
||||||
var textJsonContentType = "text/json";
|
|
||||||
|
|
||||||
var imagePngBytes = Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAgMAAAAP2OW3AAAADFBMVEX/tID/vpH/pWX/sHidUyjlAAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC");
|
|
||||||
|
|
||||||
server
|
|
||||||
.Given(
|
|
||||||
Request.Create()
|
|
||||||
.UsingPost()
|
|
||||||
.WithPath("/multipart")
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithBody(requestMessage => requestMessage.BodyAsMimeMessage is MimeMessage mm ?
|
|
||||||
"BodyAsMimeMessage is present: " + ((MimePart)mm.BodyParts.Last()).FileName :
|
|
||||||
"BodyAsMimeMessage is not present")
|
|
||||||
);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var formDataContent = new MultipartFormDataContent
|
var actual = await httpClient.PostAsync(requestUri, content);
|
||||||
{
|
|
||||||
{ new StringContent(textPlainContent, Encoding.UTF8, textPlainContentType), "text" },
|
|
||||||
{ new StringContent(textJson, Encoding.UTF8, textJsonContentType), "json" }
|
|
||||||
};
|
|
||||||
|
|
||||||
var fileContent = new ByteArrayContent(imagePngBytes);
|
// Assert
|
||||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
|
actual.StatusCode.Should().Be(HttpStatusCode.Created);
|
||||||
formDataContent.Add(fileContent, "somefile", "image.png");
|
|
||||||
|
|
||||||
var client = server.CreateClient();
|
|
||||||
|
|
||||||
var response = await client.PostAsync("/multipart", formDataContent);
|
|
||||||
|
|
||||||
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
||||||
(await response.Content.ReadAsStringAsync()).Should().Be("BodyAsMimeMessage is present: image.png");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,8 +8,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="FluentAssertions" Version="6.12.0" />
|
<PackageReference Include="FluentAssertions" Version="6.11.0" />
|
||||||
<PackageReference Include="WireMock.Net" Version="1.5.51" />
|
<PackageReference Include="WireMock.Net" Version="1.5.42" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF</DefineConstants>
|
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Globalization;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
@@ -43,24 +42,6 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
public static class MainApp
|
public static class MainApp
|
||||||
{
|
{
|
||||||
private const string ProtoDefinition = @"
|
|
||||||
syntax = ""proto3"";
|
|
||||||
|
|
||||||
package greet;
|
|
||||||
|
|
||||||
service Greeter {
|
|
||||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
message HelloRequest {
|
|
||||||
string name = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message HelloReply {
|
|
||||||
string message = 1;
|
|
||||||
}
|
|
||||||
";
|
|
||||||
|
|
||||||
private const string TestSchema = @"
|
private const string TestSchema = @"
|
||||||
scalar DateTime
|
scalar DateTime
|
||||||
scalar MyCustomScalar
|
scalar MyCustomScalar
|
||||||
@@ -95,48 +76,8 @@ message HelloReply {
|
|||||||
fullName:String
|
fullName:String
|
||||||
}";
|
}";
|
||||||
|
|
||||||
private static void RunOnLocal()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var server = WireMockServer.Start(new WireMockServerSettings
|
|
||||||
{
|
|
||||||
Port = 9091,
|
|
||||||
StartAdminInterface = true,
|
|
||||||
Logger = new WireMockConsoleLogger()
|
|
||||||
});
|
|
||||||
System.Console.WriteLine(string.Join(", ", server.Urls));
|
|
||||||
|
|
||||||
var requestJson = new { PricingContext = new { Market = "USA" } };
|
|
||||||
var responseJson = new { Market = "{{JsonPath.SelectToken request.body \"$.PricingContext.Market\"}}" };
|
|
||||||
server
|
|
||||||
.Given(Request.Create()
|
|
||||||
//.WithBody(new JsonMatcher(requestJson))
|
|
||||||
.WithBodyAsJson(requestJson)
|
|
||||||
.WithPath("/pricing")
|
|
||||||
.UsingPost()
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithHeader("Content-Type", "application/json")
|
|
||||||
.WithBodyAsJson(responseJson)
|
|
||||||
.WithTransformer(true)
|
|
||||||
);
|
|
||||||
|
|
||||||
System.Console.WriteLine("Press any key to stop...");
|
|
||||||
System.Console.ReadKey();
|
|
||||||
server.Stop();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
System.Console.WriteLine(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Run()
|
public static void Run()
|
||||||
{
|
{
|
||||||
RunOnLocal();
|
|
||||||
return;
|
|
||||||
|
|
||||||
var mappingBuilder = new MappingBuilder();
|
var mappingBuilder = new MappingBuilder();
|
||||||
mappingBuilder
|
mappingBuilder
|
||||||
.Given(Request
|
.Given(Request
|
||||||
@@ -174,14 +115,17 @@ message HelloReply {
|
|||||||
.WithBodyAsJson(rm => todos[int.Parse(rm.Query!["id"].ToString())])
|
.WithBodyAsJson(rm => todos[int.Parse(rm.Query!["id"].ToString())])
|
||||||
);
|
);
|
||||||
|
|
||||||
using var httpAndHttpsWithPort = WireMockServer.Start(new WireMockServerSettings
|
var httpClient = server.CreateClient();
|
||||||
|
//server.Stop();
|
||||||
|
|
||||||
|
var httpAndHttpsWithPort = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
HostingScheme = HostingScheme.HttpAndHttps,
|
HostingScheme = HostingScheme.HttpAndHttps,
|
||||||
Port = 12399
|
Port = 12399
|
||||||
});
|
});
|
||||||
httpAndHttpsWithPort.Stop();
|
httpAndHttpsWithPort.Stop();
|
||||||
|
|
||||||
using var httpAndHttpsFree = WireMockServer.Start(new WireMockServerSettings
|
var httpAndHttpsFree = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
HostingScheme = HostingScheme.HttpAndHttps
|
HostingScheme = HostingScheme.HttpAndHttps
|
||||||
});
|
});
|
||||||
@@ -190,14 +134,11 @@ message HelloReply {
|
|||||||
string url1 = "http://localhost:9091/";
|
string url1 = "http://localhost:9091/";
|
||||||
string url2 = "http://localhost:9092/";
|
string url2 = "http://localhost:9092/";
|
||||||
string url3 = "https://localhost:9443/";
|
string url3 = "https://localhost:9443/";
|
||||||
string urlGrpc = "grpc://localhost:9093/";
|
|
||||||
string urlGrpcSSL = "grpcs://localhost:9094/";
|
|
||||||
|
|
||||||
server = WireMockServer.Start(new WireMockServerSettings
|
server = WireMockServer.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
// CorsPolicyOptions = CorsPolicyOptions.AllowAll,
|
|
||||||
AllowCSharpCodeMatcher = true,
|
AllowCSharpCodeMatcher = true,
|
||||||
Urls = new[] { url1, url2, url3, urlGrpc, urlGrpcSSL },
|
Urls = new[] { url1, url2, url3 },
|
||||||
StartAdminInterface = true,
|
StartAdminInterface = true,
|
||||||
ReadStaticMappings = true,
|
ReadStaticMappings = true,
|
||||||
SaveUnmatchedRequests = true,
|
SaveUnmatchedRequests = true,
|
||||||
@@ -229,94 +170,18 @@ message HelloReply {
|
|||||||
server.SetBasicAuthentication("a", "b");
|
server.SetBasicAuthentication("a", "b");
|
||||||
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
|
||||||
|
|
||||||
//var http = new HttpClient();
|
// server.AllowPartialMapping();
|
||||||
//var response = await http.GetAsync($"{_wireMockServer.Url}/pricing");
|
|
||||||
//var value = await response.Content.ReadAsStringAsync();
|
|
||||||
|
|
||||||
#if PROTOBUF
|
|
||||||
var protoBufJsonMatcher = new JsonPartialWildcardMatcher(new { name = "*" });
|
|
||||||
server
|
|
||||||
.Given(Request.Create()
|
|
||||||
.UsingPost()
|
|
||||||
.WithHttpVersion("2")
|
|
||||||
.WithPath("/grpc/greet.Greeter/SayHello")
|
|
||||||
.WithBodyAsProtoBuf(ProtoDefinition, "greet.HelloRequest", protoBufJsonMatcher)
|
|
||||||
)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithHeader("Content-Type", "application/grpc")
|
|
||||||
.WithBodyAsProtoBuf(ProtoDefinition, "greet.HelloReply",
|
|
||||||
new
|
|
||||||
{
|
|
||||||
message = "hello {{request.BodyAsJson.name}}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.WithTrailingHeader("grpc-status", "0")
|
|
||||||
.WithTransformer()
|
|
||||||
);
|
|
||||||
|
|
||||||
server
|
|
||||||
.Given(Request.Create()
|
|
||||||
.UsingPost()
|
|
||||||
.WithHttpVersion("2")
|
|
||||||
.WithPath("/grpc2/greet.Greeter/SayHello")
|
|
||||||
.WithBodyAsProtoBuf("greet.HelloRequest", protoBufJsonMatcher)
|
|
||||||
)
|
|
||||||
.WithProtoDefinition(ProtoDefinition)
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithHeader("Content-Type", "application/grpc")
|
|
||||||
.WithBodyAsProtoBuf("greet.HelloReply",
|
|
||||||
new
|
|
||||||
{
|
|
||||||
message = "hello {{request.BodyAsJson.name}}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.WithTrailingHeader("grpc-status", "0")
|
|
||||||
.WithTransformer()
|
|
||||||
);
|
|
||||||
|
|
||||||
server
|
|
||||||
.AddProtoDefinition("my-greeter", ProtoDefinition)
|
|
||||||
.Given(Request.Create()
|
|
||||||
.UsingPost()
|
|
||||||
.WithPath("/grpc3/greet.Greeter/SayHello")
|
|
||||||
.WithBodyAsProtoBuf("greet.HelloRequest", protoBufJsonMatcher)
|
|
||||||
)
|
|
||||||
.WithProtoDefinition("my-greeter")
|
|
||||||
.RespondWith(Response.Create()
|
|
||||||
.WithHeader("Content-Type", "application/grpc")
|
|
||||||
.WithBodyAsProtoBuf("greet.HelloReply",
|
|
||||||
new
|
|
||||||
{
|
|
||||||
message = "hello {{request.BodyAsJson.name}}"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.WithTrailingHeader("grpc-status", "0")
|
|
||||||
.WithTransformer()
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if GRAPHQL
|
#if GRAPHQL
|
||||||
var customScalars = new Dictionary<string, Type> { { "MyCustomScalar", typeof(int) } };
|
var customScalars = new Dictionary<string, Type> { { "MyCustomScalar", typeof(int) } };
|
||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.WithPath("/graphql")
|
.WithPath("/graphql")
|
||||||
.UsingPost()
|
.UsingPost()
|
||||||
.WithBodyAsGraphQL(TestSchema, customScalars)
|
.WithGraphQLSchema(TestSchema, customScalars)
|
||||||
)
|
)
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithBody("GraphQL is ok")
|
.WithBody("GraphQL is ok")
|
||||||
);
|
);
|
||||||
|
|
||||||
//server
|
|
||||||
// .AddGraphQLSchema("my-graphql", TestSchema, customScalars)
|
|
||||||
// .Given(Request.Create()
|
|
||||||
// .WithPath("/graphql2")
|
|
||||||
// .UsingPost()
|
|
||||||
// )
|
|
||||||
// .WithGraphQLSchema("my-graphql")
|
|
||||||
// .RespondWith(Response.Create()
|
|
||||||
// .WithBody("GraphQL is ok")
|
|
||||||
// );
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if MIMEKIT
|
#if MIMEKIT
|
||||||
@@ -375,6 +240,7 @@ message HelloReply {
|
|||||||
.WithHeader("Content-Type", "text/plain")
|
.WithHeader("Content-Type", "text/plain")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create()
|
.Given(Request.Create()
|
||||||
.UsingMethod("GET")
|
.UsingMethod("GET")
|
||||||
@@ -470,8 +336,8 @@ message HelloReply {
|
|||||||
Url = "http://localhost:9999",
|
Url = "http://localhost:9999",
|
||||||
ReplaceSettings = new ProxyUrlReplaceSettings
|
ReplaceSettings = new ProxyUrlReplaceSettings
|
||||||
{
|
{
|
||||||
OldValue = "old",
|
OldValue = "old",
|
||||||
NewValue = "new"
|
NewValue = "new"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -39,17 +39,17 @@
|
|||||||
<Reference Include="AnyOf, Version=0.3.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
<Reference Include="AnyOf, Version=0.3.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\AnyOf.0.3.0\lib\net45\AnyOf.dll</HintPath>
|
<HintPath>..\..\packages\AnyOf.0.3.0\lib\net45\AnyOf.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars, Version=2.1.6.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.6\lib\net451\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.4\lib\net452\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.4.0.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.3\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.0\lib\net452\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.3\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.0\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="AnyOf" version="0.3.0" targetFramework="net452" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net" version="2.1.6" targetFramework="net452" />
|
<package id="Handlebars.Net" version="2.1.4" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.4.3" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers" version="2.4.0" targetFramework="net452" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.4.3" targetFramework="net452" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.4.0" targetFramework="net452" />
|
||||||
<package id="log4net" version="2.0.17" targetFramework="net452" />
|
<package id="log4net" version="2.0.15" targetFramework="net452" />
|
||||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net452" />
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net452" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
||||||
|
|||||||
@@ -38,17 +38,17 @@
|
|||||||
<Reference Include="AnyOf, Version=0.3.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
<Reference Include="AnyOf, Version=0.3.0.0, Culture=neutral, PublicKeyToken=b35e6abbb527c6b1, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\AnyOf.0.3.0\lib\net45\AnyOf.dll</HintPath>
|
<HintPath>..\..\packages\AnyOf.0.3.0\lib\net45\AnyOf.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars, Version=2.1.6.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.6\lib\net451\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.4\lib\net46\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.4.0.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.3\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.0\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.0.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.0\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="AnyOf" version="0.3.0" targetFramework="net461" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net" version="2.1.6" targetFramework="net461" />
|
<package id="Handlebars.Net" version="2.1.4" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.4.3" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers" version="2.4.0" targetFramework="net461" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.4.3" targetFramework="net461" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.4.0" targetFramework="net461" />
|
||||||
<package id="log4net" version="2.0.17" targetFramework="net461" />
|
<package id="log4net" version="2.0.15" targetFramework="net461" />
|
||||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net461" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
||||||
|
|||||||
@@ -46,32 +46,32 @@
|
|||||||
<Reference Include="Fare, Version=2.2.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
|
<Reference Include="Fare, Version=2.2.0.0, Culture=neutral, PublicKeyToken=ea68d375bf33a7c8, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Fare.2.2.1\lib\net35\Fare.dll</HintPath>
|
<HintPath>..\..\packages\Fare.2.2.1\lib\net35\Fare.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars, Version=2.1.6.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
<Reference Include="Handlebars, Version=2.1.4.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.2.1.6\lib\net451\Handlebars.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.2.1.4\lib\net46\Handlebars.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Handlebars.Net.Helpers, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="Handlebars.Net.Helpers, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.3\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.2.4.1.2\lib\net46\Handlebars.Net.Helpers.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.DynamicLinq, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.DynamicLinq, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.DynamicLinq.2.4.3\lib\net46\HandlebarsDotNet.Helpers.DynamicLinq.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.DynamicLinq.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.DynamicLinq.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Humanizer, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Humanizer, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Humanizer.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Humanizer.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Humanizer.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.Humanizer.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Json, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Json, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Json.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Json.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Json.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Random, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Random, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Random.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Random.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Random.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.Random.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.Xeger, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.Xeger, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Xeger.2.4.3\lib\net46\HandlebarsDotNet.Helpers.Xeger.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.Xeger.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.Xeger.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="HandlebarsDotNet.Helpers.XPath, Version=2.4.3.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
<Reference Include="HandlebarsDotNet.Helpers.XPath, Version=2.4.1.2, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.XPath.2.4.3\lib\net46\HandlebarsDotNet.Helpers.XPath.dll</HintPath>
|
<HintPath>..\..\packages\Handlebars.Net.Helpers.XPath.2.4.1.2\lib\net46\HandlebarsDotNet.Helpers.XPath.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Humanizer, Version=2.14.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e, processorArchitecture=MSIL">
|
<Reference Include="Humanizer, Version=2.14.0.0, Culture=neutral, PublicKeyToken=979442b78dfc278e, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Humanizer.Core.2.14.1\lib\netstandard2.0\Humanizer.dll</HintPath>
|
<HintPath>..\..\packages\Humanizer.Core.2.14.1\lib\netstandard2.0\Humanizer.dll</HintPath>
|
||||||
@@ -79,8 +79,8 @@
|
|||||||
<Reference Include="JmesPath.Net, Version=1.0.125.0, Culture=neutral, PublicKeyToken=b29d616b7f4faff0, processorArchitecture=MSIL">
|
<Reference Include="JmesPath.Net, Version=1.0.125.0, Culture=neutral, PublicKeyToken=b29d616b7f4faff0, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\JmesPath.Net.1.0.125\lib\net45\JmesPath.Net.dll</HintPath>
|
<HintPath>..\..\packages\JmesPath.Net.1.0.125\lib\net45\JmesPath.Net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="log4net, Version=2.0.17.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=2.0.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\log4net.2.0.17\lib\net45\log4net.dll</HintPath>
|
<HintPath>..\..\packages\log4net.2.0.15\lib\net45\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Microsoft.AspNetCore, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
<Reference Include="Microsoft.AspNetCore, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\Microsoft.AspNetCore.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.dll</HintPath>
|
<HintPath>..\..\packages\Microsoft.AspNetCore.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.dll</HintPath>
|
||||||
@@ -307,8 +307,8 @@
|
|||||||
<Reference Include="System.IO.Pipelines, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
<Reference Include="System.IO.Pipelines, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\System.IO.Pipelines.4.5.3\lib\netstandard2.0\System.IO.Pipelines.dll</HintPath>
|
<HintPath>..\..\packages\System.IO.Pipelines.4.5.3\lib\netstandard2.0\System.IO.Pipelines.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Linq.Dynamic.Core, Version=1.3.14.0, Culture=neutral, PublicKeyToken=0f07ec44de6ac832, processorArchitecture=MSIL">
|
<Reference Include="System.Linq.Dynamic.Core, Version=1.3.1.0, Culture=neutral, PublicKeyToken=0f07ec44de6ac832, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\System.Linq.Dynamic.Core.1.3.14\lib\net46\System.Linq.Dynamic.Core.dll</HintPath>
|
<HintPath>..\..\packages\System.Linq.Dynamic.Core.1.3.1\lib\net46\System.Linq.Dynamic.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
|
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
|
||||||
<HintPath>..\..\packages/System.Memory.4.5.5/lib/net461/System.Memory.dll</HintPath>
|
<HintPath>..\..\packages/System.Memory.4.5.5/lib/net461/System.Memory.dll</HintPath>
|
||||||
@@ -358,11 +358,11 @@
|
|||||||
<Reference Include="TinyMapper, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="TinyMapper, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\TinyMapper.3.0.3\lib\net40\TinyMapper.dll</HintPath>
|
<HintPath>..\..\packages\TinyMapper.3.0.3\lib\net40\TinyMapper.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="XPath2, Version=1.1.5.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
<Reference Include="XPath2, Version=1.1.4.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\XPath2.1.1.5\lib\net452\XPath2.dll</HintPath>
|
<HintPath>..\..\packages\XPath2.1.1.4\lib\net452\XPath2.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="XPath2.Extensions, Version=1.1.5.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
<Reference Include="XPath2.Extensions, Version=1.1.4.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\XPath2.Extensions.1.1.5\lib\net452\XPath2.Extensions.dll</HintPath>
|
<HintPath>..\..\packages\XPath2.Extensions.1.1.4\lib\net452\XPath2.Extensions.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
<packages>
|
<packages>
|
||||||
<package id="AnyOf" version="0.3.0" targetFramework="net472" />
|
<package id="AnyOf" version="0.3.0" targetFramework="net472" />
|
||||||
<package id="Fare" version="2.2.1" targetFramework="net472" />
|
<package id="Fare" version="2.2.1" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net" version="2.1.6" targetFramework="net472" />
|
<package id="Handlebars.Net" version="2.1.4" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Core" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Core" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.DynamicLinq" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.DynamicLinq" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Humanizer" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Humanizer" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Json" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Json" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Random" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Random" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.Xeger" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.Xeger" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Handlebars.Net.Helpers.XPath" version="2.4.3" targetFramework="net472" />
|
<package id="Handlebars.Net.Helpers.XPath" version="2.4.1.2" targetFramework="net472" />
|
||||||
<package id="Humanizer" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="Humanizer.Core" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="Humanizer.Core.af" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core.af" version="2.14.1" targetFramework="net472" />
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
<package id="Humanizer.Core.zh-Hans" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core.zh-Hans" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="Humanizer.Core.zh-Hant" version="2.14.1" targetFramework="net472" />
|
<package id="Humanizer.Core.zh-Hant" version="2.14.1" targetFramework="net472" />
|
||||||
<package id="JmesPath.Net" version="1.0.125" targetFramework="net472" />
|
<package id="JmesPath.Net" version="1.0.125" targetFramework="net472" />
|
||||||
<package id="log4net" version="2.0.17" targetFramework="net472" />
|
<package id="log4net" version="2.0.15" targetFramework="net472" />
|
||||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.8" targetFramework="net472" />
|
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.8" targetFramework="net472" />
|
||||||
<package id="Microsoft.AspNetCore" version="2.2.0" targetFramework="net472" />
|
<package id="Microsoft.AspNetCore" version="2.2.0" targetFramework="net472" />
|
||||||
<package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.2.0" targetFramework="net472" />
|
<package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.2.0" targetFramework="net472" />
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
<package id="System.Diagnostics.DiagnosticSource" version="4.5.0" targetFramework="net472" />
|
<package id="System.Diagnostics.DiagnosticSource" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.IdentityModel.Tokens.Jwt" version="6.34.0" targetFramework="net472" />
|
<package id="System.IdentityModel.Tokens.Jwt" version="6.34.0" targetFramework="net472" />
|
||||||
<package id="System.IO.Pipelines" version="4.5.3" targetFramework="net472" />
|
<package id="System.IO.Pipelines" version="4.5.3" targetFramework="net472" />
|
||||||
<package id="System.Linq.Dynamic.Core" version="1.3.14" targetFramework="net472" />
|
<package id="System.Linq.Dynamic.Core" version="1.3.1" targetFramework="net472" />
|
||||||
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
|
<package id="System.Memory" version="4.5.5" targetFramework="net472" />
|
||||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net472" />
|
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net472" />
|
||||||
@@ -151,6 +151,6 @@
|
|||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net472" />
|
||||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||||
<package id="TinyMapper" version="3.0.3" targetFramework="net472" />
|
<package id="TinyMapper" version="3.0.3" targetFramework="net472" />
|
||||||
<package id="XPath2" version="1.1.5" targetFramework="net472" />
|
<package id="XPath2" version="1.1.4" targetFramework="net472" />
|
||||||
<package id="XPath2.Extensions" version="1.1.5" targetFramework="net472" />
|
<package id="XPath2.Extensions" version="1.1.4" targetFramework="net472" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -18,5 +18,6 @@ public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
|
|||||||
Pattern = $"[0-9A-Z]{{{maxLength}}}"
|
Pattern = $"[0-9A-Z]{{{maxLength}}}"
|
||||||
}).Generate() ?? "example-string";
|
}).Generate() ?? "example-string";
|
||||||
}
|
}
|
||||||
|
set { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,9 +98,4 @@ public class MappingModel
|
|||||||
/// The probability when this request should be matched. Value is between 0 and 1. [Optional]
|
/// The probability when this request should be matched. Value is between 0 and 1. [Optional]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? Probability { get; set; }
|
public double? Probability { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Grpc ProtoDefinition which is used for this mapping (request and response). [Optional]
|
|
||||||
/// </summary>
|
|
||||||
public string? ProtoDefinition { get; set; }
|
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ public class MatcherModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? MatchOperator { get; set; }
|
public string? MatchOperator { get; set; }
|
||||||
|
|
||||||
#region JsonMatcher, JsonPartialMatcher and JsonPartialWildcardMatcher
|
#region JsonPartialMatcher and JsonPartialWildcardMatcher
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Support Regex.
|
/// Support Regex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -70,22 +70,13 @@ public class MatcherModel
|
|||||||
/// ContentTransferEncoding Matcher (base64)
|
/// ContentTransferEncoding Matcher (base64)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MatcherModel? ContentTransferEncodingMatcher { get; set; }
|
public MatcherModel? ContentTransferEncodingMatcher { get; set; }
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region MimePartMatcher + ProtoBufMatcher
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Content Matcher
|
/// Content Matcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MatcherModel? ContentMatcher { get; set; }
|
public MatcherModel? ContentMatcher { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ProtoBufMatcher
|
|
||||||
/// <summary>
|
|
||||||
/// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
|
|
||||||
/// </summary>
|
|
||||||
public string? ProtoBufMessageType { get; set; }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region XPathMatcher
|
#region XPathMatcher
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Array of namespace prefix and uri. (optional)
|
/// Array of namespace prefix and uri. (optional)
|
||||||
@@ -95,7 +86,7 @@ public class MatcherModel
|
|||||||
|
|
||||||
#region GraphQLMatcher
|
#region GraphQLMatcher
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Mapping of custom GraphQL Scalar name to ClrType. (optional)
|
/// Mapping of custom GraphQL Scalar name to ClrType. (optional)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, Type>? CustomScalars { get; set; }
|
public IDictionary<string, Type>? CustomScalars { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ public class RequestModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string[]? Methods { get; set; }
|
public string[]? Methods { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The HTTP Version
|
|
||||||
/// </summary>
|
|
||||||
public string? HttpVersion { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reject on match for Methods.
|
/// Reject on match for Methods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class ResponseModel
|
|||||||
public bool? BodyAsJsonIndented { get; set; }
|
public bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the body (as byte array).
|
/// Gets or sets the body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[]? BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
@@ -84,11 +84,6 @@ public class ResponseModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? HeadersRaw { get; set; }
|
public string? HeadersRaw { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the Trailing Headers.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, object>? TrailingHeaders { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the delay in milliseconds.
|
/// Gets or sets the delay in milliseconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -128,16 +123,4 @@ public class ResponseModel
|
|||||||
/// Gets or sets the WebProxy settings.
|
/// Gets or sets the WebProxy settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WebProxyModel? WebProxy { get; set; }
|
public WebProxyModel? WebProxy { get; set; }
|
||||||
|
|
||||||
#region ProtoBuf
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the proto definition.
|
|
||||||
/// </summary>
|
|
||||||
public string? ProtoDefinition { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
|
|
||||||
/// </summary>
|
|
||||||
public string? ProtoBufMessageType { get; set; }
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
@@ -55,11 +55,6 @@ public class LogRequestModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Method { get; set; }
|
public string Method { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The HTTP Version.
|
|
||||||
/// </summary>
|
|
||||||
public string HttpVersion { get; set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Headers.
|
/// The Headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using JetBrains.Annotations;
|
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
@@ -116,11 +114,6 @@ public class SettingsModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public QueryParameterMultipleValueSupport? QueryParameterMultipleValueSupport { get; set; }
|
public QueryParameterMultipleValueSupport? QueryParameterMultipleValueSupport { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A list of Grpc ProtoDefinitions which can be used.
|
|
||||||
/// </summary>
|
|
||||||
public Dictionary<string, string>? ProtoDefinitions { get; set; }
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3_OR_GREATER || NET461
|
#if NETSTANDARD1_3_OR_GREATER || NET461
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Server client certificate mode
|
/// Server client certificate mode
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.Admin.Mappings;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// BodyModelBuilder
|
|
||||||
/// </summary>
|
|
||||||
public partial class BodyModelBuilder
|
|
||||||
{
|
|
||||||
public BodyModelBuilder WithNotNullOrEmptyMatcher(bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("NotNullOrEmptyMatcher")
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithCSharpCodeMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("CSharpCodeMatcher", pattern, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithLinqMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("LinqMatcher", pattern, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithExactMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("ExactMatcher", pattern, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithExactObjectMatcher(object value, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("ExactObjectMatcher", value, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithGraphQLMatcher(string pattern, IDictionary<string, Type>? customScalars = null, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("GraphQLMatcher")
|
|
||||||
.WithCustomScalars(customScalars)
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithProtoBufMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("ProtoBufMatcher")
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithRegexMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("RegexMatcher")
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithIgnoreCase(ignoreCase)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithJsonMatcher(string pattern, bool ignoreCase = false, bool useRegex = false, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("JsonMatcher")
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithIgnoreCase(ignoreCase)
|
|
||||||
.WithRegex(useRegex)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithJsonPartialMatcher(string pattern, bool ignoreCase = false, bool useRegex = false, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("JsonPartialMatcher")
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithIgnoreCase(ignoreCase)
|
|
||||||
.WithRegex(useRegex)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithJsonPathMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("JsonPathMatcher", pattern, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithJmesPathMatcher(string pattern, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("JmesPathMatcher", pattern, rejectOnMatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithXPathMatcher(string pattern, XmlNamespace[]? xmlNamespaceMap = null, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName("PathMatcher")
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithXmlNamespaceMap(xmlNamespaceMap)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithWildcardMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("WildcardMatcher", pattern, rejectOnMatch, ignoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyModelBuilder WithSimMetricsMatcher(string pattern, bool ignoreCase = false, bool rejectOnMatch = false)
|
|
||||||
{
|
|
||||||
return WithMatcher("SimMetricsMatcher", pattern, rejectOnMatch, ignoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
private BodyModelBuilder WithMatcher(string name, object pattern, bool rejectOnMatch, bool ignoreCase = false)
|
|
||||||
{
|
|
||||||
return WithMatcher(mb => mb
|
|
||||||
.WithName(name)
|
|
||||||
.WithPattern(pattern)
|
|
||||||
.WithRejectOnMatch(rejectOnMatch)
|
|
||||||
.WithIgnoreCase(ignoreCase)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -63,11 +63,6 @@ public interface IRequestMessage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
string Method { get; }
|
string Method { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the HTTP Version.
|
|
||||||
/// </summary>
|
|
||||||
string HttpVersion { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the headers.
|
/// Gets the headers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -99,27 +94,23 @@ public interface IRequestMessage
|
|||||||
IBodyData? BodyData { get; }
|
IBodyData? BodyData { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The original body as string.
|
/// The original body as string. Convenience getter for Handlebars and WireMockAssertions.
|
||||||
/// Convenience getter for Handlebars and WireMockAssertions.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string? Body { get; }
|
string? Body { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as JSON object).
|
/// The body (as JSON object). Convenience getter for Handlebars and WireMockAssertions.
|
||||||
/// Convenience getter for Handlebars and WireMockAssertions.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object? BodyAsJson { get; }
|
object? BodyAsJson { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as bytearray).
|
/// The body (as bytearray). Convenience getter for Handlebars and WireMockAssertions.
|
||||||
/// Convenience getter for Handlebars and WireMockAssertions.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
byte[]? BodyAsBytes { get; }
|
byte[]? BodyAsBytes { get; }
|
||||||
|
|
||||||
#if MIMEKIT
|
#if MIMEKIT
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The original body as MimeMessage.
|
/// The original body as MimeMessage. Convenience getter for Handlebars and WireMockAssertions.
|
||||||
/// Convenience getter for Handlebars and WireMockAssertions.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object? BodyAsMimeMessage { get; }
|
object? BodyAsMimeMessage { get; }
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,16 +40,11 @@ public interface IResponseMessage
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IDictionary<string, WireMockList<string>>? Headers { get; }
|
IDictionary<string, WireMockList<string>>? Headers { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the trailing headers.
|
|
||||||
/// </summary>
|
|
||||||
IDictionary<string, WireMockList<string>>? TrailingHeaders { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the status code.
|
/// Gets or sets the status code.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object? StatusCode { get; }
|
object? StatusCode { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the header.
|
/// Adds the header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -57,24 +52,10 @@ public interface IResponseMessage
|
|||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
void AddHeader(string name, string value);
|
void AddHeader(string name, string value);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the trailing header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="values">The values.</param>
|
|
||||||
void AddHeader(string name, params string[] values);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds the trailing header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
void AddTrailingHeader(string name, string value);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the header.
|
/// Adds the header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
void AddTrailingHeader(string name, params string[] values);
|
void AddHeader(string name, params string[] values);
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using WireMock.Models;
|
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.Util;
|
namespace WireMock.Util;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -13,7 +10,7 @@ namespace WireMock.Util;
|
|||||||
public interface IBodyData
|
public interface IBodyData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as byte array).
|
/// The body (as bytearray).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
byte[]? BodyAsBytes { get; set; }
|
byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
@@ -29,7 +26,6 @@ public interface IBodyData
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The body (as JSON object).
|
/// The body (as JSON object).
|
||||||
/// Also used for ProtoBuf.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object? BodyAsJson { get; set; }
|
object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
@@ -72,16 +68,4 @@ public interface IBodyData
|
|||||||
/// Defines if this BodyData is the result of a dynamically created response-string. (
|
/// Defines if this BodyData is the result of a dynamically created response-string. (
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? IsFuncUsed { get; set; }
|
public string? IsFuncUsed { get; set; }
|
||||||
|
|
||||||
#region ProtoBuf
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the proto definition.
|
|
||||||
/// </summary>
|
|
||||||
public Func<IdOrText>? ProtoDefinition { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
|
|
||||||
/// </summary>
|
|
||||||
public string? ProtoBufMessageType { get; set; }
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
namespace WireMock.Models;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A structure defining an (optional) Id and a Text.
|
|
||||||
/// </summary>
|
|
||||||
public readonly struct IdOrText
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The Id [optional].
|
|
||||||
/// </summary>
|
|
||||||
public string? Id { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Text.
|
|
||||||
/// </summary>
|
|
||||||
public string Text { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// When Id is defined, return the Id, else the Text.
|
|
||||||
/// </summary>
|
|
||||||
public string Value => Id ?? Text;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a IdOrText
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="id">The Id [optional]</param>
|
|
||||||
/// <param name="text">The Text.</param>
|
|
||||||
public IdOrText(string? id, string text)
|
|
||||||
{
|
|
||||||
Id = id;
|
|
||||||
Text = text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,10 +38,5 @@ public enum BodyType
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Body is a String which is x-www-form-urlencoded.
|
/// Body is a String which is x-www-form-urlencoded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
FormUrlEncoded,
|
FormUrlEncoded
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Body is a ProtoBuf Byte array
|
|
||||||
/// </summary>
|
|
||||||
ProtoBuf
|
|
||||||
}
|
}
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
|
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
|
||||||
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF</DefineConstants>
|
<DefineConstants>$(DefineConstants);GRAPHQL;MIMEKIT</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,34 +2,22 @@ using Stef.Validation;
|
|||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions;
|
namespace WireMock.FluentAssertions
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides assertion methods to verify the number of calls made to a WireMock server.
|
|
||||||
/// This class is used in the context of FluentAssertions.
|
|
||||||
/// </summary>
|
|
||||||
public class WireMockANumberOfCallsAssertions
|
|
||||||
{
|
{
|
||||||
private readonly IWireMockServer _server;
|
public class WireMockANumberOfCallsAssertions
|
||||||
private readonly int _callsCount;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="WireMockANumberOfCallsAssertions"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="server">The WireMock server to assert against.</param>
|
|
||||||
/// <param name="callsCount">The expected number of calls to assert.</param>
|
|
||||||
public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount)
|
|
||||||
{
|
{
|
||||||
_server = Guard.NotNull(server);
|
private readonly IWireMockServer _server;
|
||||||
_callsCount = callsCount;
|
private readonly int _callsCount;
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
public WireMockANumberOfCallsAssertions(IWireMockServer server, int callsCount)
|
||||||
/// Returns an instance of <see cref="WireMockAssertions"/> which can be used to assert the expected number of calls.
|
{
|
||||||
/// </summary>
|
_server = Guard.NotNull(server);
|
||||||
/// <returns>A <see cref="WireMockAssertions"/> instance for asserting the number of calls to the server.</returns>
|
_callsCount = callsCount;
|
||||||
public WireMockAssertions Calls()
|
}
|
||||||
{
|
|
||||||
return new WireMockAssertions(_server, _callsCount);
|
public WireMockAssertions Calls()
|
||||||
|
{
|
||||||
|
return new WireMockAssertions(_server, _callsCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
using System;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.FluentAssertions;
|
|
||||||
|
|
||||||
public partial class WireMockAssertions
|
|
||||||
{
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl(string absoluteUrl, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
|
||||||
absoluteUrl
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but didn't find it among the calls to {1}.",
|
|
||||||
_ => absoluteUrl,
|
|
||||||
requests => requests.Select(request => request.AbsoluteUrl)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndWhichConstraint<WireMockAssertions, string>(this, absoluteUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndWhichConstraint<WireMockAssertions, string> AtUrl(string url, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.Url, url, StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but no calls were made.",
|
|
||||||
url
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but didn't find it among the calls to {1}.",
|
|
||||||
_ => url,
|
|
||||||
requests => requests.Select(request => request.Url)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndWhichConstraint<WireMockAssertions, string>(this, url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
using System;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.FluentAssertions;
|
|
||||||
|
|
||||||
public partial class WireMockAssertions
|
|
||||||
{
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndWhichConstraint<WireMockAssertions, string> FromClientIP(string clientIP, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.ClientIP, clientIP, StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but no calls were made.",
|
|
||||||
clientIP
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but didn't find it among the calls from IP(s) {1}.",
|
|
||||||
_ => clientIP, requests => requests.Select(request => request.ClientIP)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndWhichConstraint<WireMockAssertions, string>(this, clientIP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -58,8 +58,8 @@ public partial class WireMockAssertions
|
|||||||
|
|
||||||
Execute.Assertion
|
Execute.Assertion
|
||||||
.BecauseOf(because, becauseArgs)
|
.BecauseOf(because, becauseArgs)
|
||||||
.Given(() => RequestMessages)
|
.Given(() => _requestMessages)
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
.FailWith(
|
.FailWith(
|
||||||
"Expected {context:wiremockserver} to have been called using method {0}{reason}, but no calls were made.",
|
"Expected {context:wiremockserver} to have been called using method {0}{reason}, but no calls were made.",
|
||||||
method
|
method
|
||||||
@@ -72,7 +72,7 @@ public partial class WireMockAssertions
|
|||||||
requests => requests.Select(request => request.Method)
|
requests => requests.Select(request => request.Method)
|
||||||
);
|
);
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using AnyOfTypes;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using WireMock.Extensions;
|
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Models;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions;
|
namespace WireMock.FluentAssertions;
|
||||||
@@ -14,7 +9,7 @@ namespace WireMock.FluentAssertions;
|
|||||||
public partial class WireMockAssertions
|
public partial class WireMockAssertions
|
||||||
{
|
{
|
||||||
private const string MessageFormatNoCalls = "Expected {context:wiremockserver} to have been called using body {0}{reason}, but no calls were made.";
|
private const string MessageFormatNoCalls = "Expected {context:wiremockserver} to have been called using body {0}{reason}, but no calls were made.";
|
||||||
private const string MessageFormat = "Expected {context:wiremockserver} to have been called using body {0}{reason}, but didn't find it among the body/bodies {1}.";
|
private const string MessageFormat = "Expected {context:wiremockserver} to have been called using body {0}{reason}, but didn't find it among the body {1}.";
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> WithBody(string body, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> WithBody(string body, string because = "", params object[] becauseArgs)
|
||||||
@@ -49,11 +44,11 @@ public partial class WireMockAssertions
|
|||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> WithBodyAsJson(IObjectMatcher matcher, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> WithBodyAsJson(IValueMatcher matcher, string because = "", params object[] becauseArgs)
|
||||||
{
|
{
|
||||||
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsJson, matcher);
|
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsJson, matcher);
|
||||||
|
|
||||||
return ExecuteAssertionWithBodyAsIObjectMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsJson);
|
return ExecuteAssertionWithBodyAsJsonValueMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
@@ -61,7 +56,7 @@ public partial class WireMockAssertions
|
|||||||
{
|
{
|
||||||
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsBytes, matcher);
|
var (filter, condition) = BuildFilterAndCondition(r => r.BodyAsBytes, matcher);
|
||||||
|
|
||||||
return ExecuteAssertionWithBodyAsIObjectMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsBytes);
|
return ExecuteAssertionWithBodyAsBytesExactObjectMatcher(matcher, because, becauseArgs, condition, filter, r => r.BodyAsBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyStringMatcher(
|
private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyStringMatcher(
|
||||||
@@ -75,27 +70,27 @@ public partial class WireMockAssertions
|
|||||||
{
|
{
|
||||||
Execute.Assertion
|
Execute.Assertion
|
||||||
.BecauseOf(because, becauseArgs)
|
.BecauseOf(because, becauseArgs)
|
||||||
.Given(() => RequestMessages)
|
.Given(() => _requestMessages)
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
.FailWith(
|
.FailWith(
|
||||||
MessageFormatNoCalls,
|
MessageFormatNoCalls,
|
||||||
FormatBody(matcher.GetPatterns())
|
matcher.GetPatterns()
|
||||||
)
|
)
|
||||||
.Then
|
.Then
|
||||||
.ForCondition(condition)
|
.ForCondition(condition)
|
||||||
.FailWith(
|
.FailWith(
|
||||||
MessageFormat,
|
MessageFormat,
|
||||||
_ => FormatBody(matcher.GetPatterns()),
|
_ => matcher.GetPatterns(),
|
||||||
requests => FormatBodies(requests.Select(expression))
|
requests => requests.Select(expression)
|
||||||
);
|
);
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyAsIObjectMatcher(
|
private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyAsJsonValueMatcher(
|
||||||
IObjectMatcher matcher,
|
IValueMatcher matcher,
|
||||||
string because,
|
string because,
|
||||||
object[] becauseArgs,
|
object[] becauseArgs,
|
||||||
Func<IReadOnlyList<IRequestMessage>, bool> condition,
|
Func<IReadOnlyList<IRequestMessage>, bool> condition,
|
||||||
@@ -105,41 +100,52 @@ public partial class WireMockAssertions
|
|||||||
{
|
{
|
||||||
Execute.Assertion
|
Execute.Assertion
|
||||||
.BecauseOf(because, becauseArgs)
|
.BecauseOf(because, becauseArgs)
|
||||||
.Given(() => RequestMessages)
|
.Given(() => _requestMessages)
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
.FailWith(
|
.FailWith(
|
||||||
MessageFormatNoCalls,
|
MessageFormatNoCalls,
|
||||||
FormatBody(matcher.Value)
|
matcher.Value
|
||||||
)
|
)
|
||||||
.Then
|
.Then
|
||||||
.ForCondition(condition)
|
.ForCondition(condition)
|
||||||
.FailWith(
|
.FailWith(
|
||||||
MessageFormat,
|
MessageFormat,
|
||||||
_ => FormatBody(matcher.Value),
|
_ => matcher.Value,
|
||||||
requests => FormatBodies(requests.Select(expression))
|
requests => requests.Select(expression)
|
||||||
);
|
);
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string? FormatBody(object? body)
|
private AndConstraint<WireMockAssertions> ExecuteAssertionWithBodyAsBytesExactObjectMatcher(
|
||||||
|
ExactObjectMatcher matcher,
|
||||||
|
string because,
|
||||||
|
object[] becauseArgs,
|
||||||
|
Func<IReadOnlyList<IRequestMessage>, bool> condition,
|
||||||
|
Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> filter,
|
||||||
|
Func<IRequestMessage, object?> expression
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return body switch
|
Execute.Assertion
|
||||||
{
|
.BecauseOf(because, becauseArgs)
|
||||||
null => null,
|
.Given(() => _requestMessages)
|
||||||
string str => str,
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
AnyOf<string, StringPattern>[] stringPatterns => FormatBodies(stringPatterns.Select(p => p.GetPattern())),
|
.FailWith(
|
||||||
byte[] bytes => $"byte[{bytes.Length}] {{...}}",
|
MessageFormatNoCalls,
|
||||||
JToken jToken => jToken.ToString(Formatting.None),
|
matcher.ValueAsObject ?? matcher.ValueAsBytes
|
||||||
_ => JToken.FromObject(body).ToString(Formatting.None)
|
)
|
||||||
};
|
.Then
|
||||||
}
|
.ForCondition(condition)
|
||||||
|
.FailWith(
|
||||||
|
MessageFormat,
|
||||||
|
_ => matcher.ValueAsObject ?? matcher.ValueAsBytes,
|
||||||
|
requests => requests.Select(expression)
|
||||||
|
);
|
||||||
|
|
||||||
private static string? FormatBodies(IEnumerable<object?> bodies)
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
{
|
|
||||||
var valueAsArray = bodies as object[] ?? bodies.ToArray();
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
return valueAsArray.Length == 1 ? FormatBody(valueAsArray.First()) : $"[ {string.Join(", ", valueAsArray.Select(FormatBody))} ]";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using WireMock.Types;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.FluentAssertions;
|
|
||||||
|
|
||||||
public partial class WireMockAssertions
|
|
||||||
{
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndWhichConstraint<WireMockAssertions, string> WitHeaderKey(string expectedKey, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request =>
|
|
||||||
{
|
|
||||||
return request.Headers?.Any(h => h.Key == expectedKey) == true;
|
|
||||||
});
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with Header {0}{reason}.",
|
|
||||||
expectedKey
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with Header {0}{reason}, but didn't find it among the calls with Header(s) {1}.",
|
|
||||||
_ => expectedKey,
|
|
||||||
requests => requests.Select(request => request.Headers)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndWhichConstraint<WireMockAssertions, string>(this, expectedKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value, string because = "", params object[] becauseArgs)
|
|
||||||
=> WithHeader(expectedKey, new[] { value }, because, becauseArgs);
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request =>
|
|
||||||
{
|
|
||||||
var headers = request.Headers?.ToArray() ?? new KeyValuePair<string, WireMockList<string>>[0];
|
|
||||||
|
|
||||||
var matchingHeaderValues = headers.Where(h => h.Key == expectedKey).SelectMany(h => h.Value.ToArray()).ToArray();
|
|
||||||
|
|
||||||
if (expectedValues.Length == 1 && matchingHeaderValues.Length == 1)
|
|
||||||
{
|
|
||||||
return matchingHeaderValues[0] == expectedValues[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var trimmedHeaderValues = string.Join(",", matchingHeaderValues.Select(x => x)).Split(',').Select(x => x.Trim()).ToArray();
|
|
||||||
return expectedValues.Any(trimmedHeaderValues.Contains);
|
|
||||||
});
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with Header {0} and Values {1}{reason}.",
|
|
||||||
expectedKey,
|
|
||||||
expectedValues
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with Header {0} and Values {1}{reason}, but didn't find it among the calls with Header(s) {2}.",
|
|
||||||
_ => expectedKey,
|
|
||||||
_ => expectedValues,
|
|
||||||
requests => requests.Select(request => request.Headers)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndConstraint<WireMockAssertions> WithoutHeaderKey(string unexpectedKey, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request =>
|
|
||||||
{
|
|
||||||
return request.Headers?.Any(h => h.Key == unexpectedKey) != true;
|
|
||||||
});
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} not to have been called with Header {0}{reason}.",
|
|
||||||
unexpectedKey
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} not to have been called with Header {0}{reason}, but found it among the calls with Header(s) {1}.",
|
|
||||||
_ => unexpectedKey,
|
|
||||||
requests => requests.Select(request => request.Headers)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndConstraint<WireMockAssertions> WithoutHeader(string unexpectedKey, string value, string because = "", params object[] becauseArgs)
|
|
||||||
=> WithoutHeader(unexpectedKey, new[] { value }, because, becauseArgs);
|
|
||||||
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndConstraint<WireMockAssertions> WithoutHeader(string unexpectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request =>
|
|
||||||
{
|
|
||||||
var headers = request.Headers?.ToArray() ?? new KeyValuePair<string, WireMockList<string>>[0];
|
|
||||||
|
|
||||||
var matchingHeaderValues = headers.Where(h => h.Key == unexpectedKey).SelectMany(h => h.Value.ToArray()).ToArray();
|
|
||||||
|
|
||||||
if (expectedValues.Length == 1 && matchingHeaderValues.Length == 1)
|
|
||||||
{
|
|
||||||
return matchingHeaderValues[0] != expectedValues[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
var trimmedHeaderValues = string.Join(",", matchingHeaderValues.Select(x => x)).Split(',').Select(x => x.Trim()).ToArray();
|
|
||||||
return !expectedValues.Any(trimmedHeaderValues.Contains);
|
|
||||||
});
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} not to have been called with Header {0} and Values {1}{reason}.",
|
|
||||||
unexpectedKey,
|
|
||||||
expectedValues
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} not to have been called with Header {0} and Values {1}{reason}, but found it among the calls with Header(s) {2}.",
|
|
||||||
_ => unexpectedKey,
|
|
||||||
_ => expectedValues,
|
|
||||||
requests => requests.Select(request => request.Headers)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
using System;
|
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.FluentAssertions;
|
|
||||||
|
|
||||||
public partial class WireMockAssertions
|
|
||||||
{
|
|
||||||
[CustomAssertion]
|
|
||||||
public AndWhichConstraint<WireMockAssertions, string> WithProxyUrl(string proxyUrl, string because = "", params object[] becauseArgs)
|
|
||||||
{
|
|
||||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.ProxyUrl, proxyUrl, StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
Execute.Assertion
|
|
||||||
.BecauseOf(because, becauseArgs)
|
|
||||||
.Given(() => RequestMessages)
|
|
||||||
.ForCondition(requests => CallsCount == 0 || requests.Any())
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but no calls were made.",
|
|
||||||
proxyUrl
|
|
||||||
)
|
|
||||||
.Then
|
|
||||||
.ForCondition(condition)
|
|
||||||
.FailWith(
|
|
||||||
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but didn't find it among the calls with {1}.",
|
|
||||||
_ => proxyUrl,
|
|
||||||
requests => requests.Select(request => request.ProxyUrl)
|
|
||||||
);
|
|
||||||
|
|
||||||
FilterRequestMessages(filter);
|
|
||||||
|
|
||||||
return new AndWhichConstraint<WireMockAssertions, string>(this, proxyUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,42 +3,220 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
|
using WireMock.Types;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions;
|
namespace WireMock.FluentAssertions;
|
||||||
|
|
||||||
public partial class WireMockAssertions
|
public partial class WireMockAssertions
|
||||||
{
|
{
|
||||||
public const string Any = "*";
|
private const string Any = "*";
|
||||||
|
private readonly int? _callsCount;
|
||||||
public int? CallsCount { get; }
|
private IReadOnlyList<IRequestMessage> _requestMessages;
|
||||||
public IReadOnlyList<IRequestMessage> RequestMessages { get; private set; }
|
private readonly IReadOnlyList<KeyValuePair<string, WireMockList<string>>> _headers;
|
||||||
|
|
||||||
public WireMockAssertions(IWireMockServer subject, int? callsCount)
|
public WireMockAssertions(IWireMockServer subject, int? callsCount)
|
||||||
{
|
{
|
||||||
CallsCount = callsCount;
|
_callsCount = callsCount;
|
||||||
RequestMessages = subject.LogEntries.Select(logEntry => logEntry.RequestMessage).ToList();
|
_requestMessages = subject.LogEntries.Select(logEntry => logEntry.RequestMessage).ToList();
|
||||||
|
_headers = _requestMessages.SelectMany(req => req.Headers).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, bool> predicate)
|
[CustomAssertion]
|
||||||
|
public AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl(string absoluteUrl, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Execute.Assertion
|
||||||
|
.BecauseOf(because, becauseArgs)
|
||||||
|
.Given(() => _requestMessages)
|
||||||
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
||||||
|
absoluteUrl
|
||||||
|
)
|
||||||
|
.Then
|
||||||
|
.ForCondition(condition)
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but didn't find it among the calls to {1}.",
|
||||||
|
_ => absoluteUrl, requests => requests.Select(request => request.AbsoluteUrl)
|
||||||
|
);
|
||||||
|
|
||||||
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
|
return new AndWhichConstraint<WireMockAssertions, string>(this, absoluteUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndWhichConstraint<WireMockAssertions, string> AtUrl(string url, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Execute.Assertion
|
||||||
|
.BecauseOf(because, becauseArgs)
|
||||||
|
.Given(() => _requestMessages)
|
||||||
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but no calls were made.",
|
||||||
|
url
|
||||||
|
)
|
||||||
|
.Then
|
||||||
|
.ForCondition(condition)
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called at address matching the url {0}{reason}, but didn't find it among the calls to {1}.",
|
||||||
|
_ => url,
|
||||||
|
requests => requests.Select(request => request.Url)
|
||||||
|
);
|
||||||
|
|
||||||
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
|
return new AndWhichConstraint<WireMockAssertions, string>(this, url);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndWhichConstraint<WireMockAssertions, string> WithProxyUrl(string proxyUrl, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.ProxyUrl, proxyUrl, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Execute.Assertion
|
||||||
|
.BecauseOf(because, becauseArgs)
|
||||||
|
.Given(() => _requestMessages)
|
||||||
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but no calls were made.",
|
||||||
|
proxyUrl
|
||||||
|
)
|
||||||
|
.Then
|
||||||
|
.ForCondition(condition)
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called with proxy url {0}{reason}, but didn't find it among the calls with {1}.",
|
||||||
|
_ => proxyUrl,
|
||||||
|
requests => requests.Select(request => request.ProxyUrl)
|
||||||
|
);
|
||||||
|
|
||||||
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
|
return new AndWhichConstraint<WireMockAssertions, string>(this, proxyUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndWhichConstraint<WireMockAssertions, string> FromClientIP(string clientIP, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.ClientIP, clientIP, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
Execute.Assertion
|
||||||
|
.BecauseOf(because, becauseArgs)
|
||||||
|
.Given(() => _requestMessages)
|
||||||
|
.ForCondition(requests => _callsCount == 0 || requests.Any())
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but no calls were made.",
|
||||||
|
clientIP
|
||||||
|
)
|
||||||
|
.Then
|
||||||
|
.ForCondition(condition)
|
||||||
|
.FailWith(
|
||||||
|
"Expected {context:wiremockserver} to have been called from client IP {0}{reason}, but didn't find it among the calls from IP(s) {1}.",
|
||||||
|
_ => clientIP, requests => requests.Select(request => request.ClientIP)
|
||||||
|
);
|
||||||
|
|
||||||
|
_requestMessages = filter(_requestMessages).ToList();
|
||||||
|
|
||||||
|
return new AndWhichConstraint<WireMockAssertions, string>(this, clientIP);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WitHeaderKey(string expectedKey, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
using (new AssertionScope("headers from requests sent"))
|
||||||
|
{
|
||||||
|
_headers.Select(h => h.Key).Should().Contain(expectedKey, because, becauseArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value, string because = "", params object[] becauseArgs)
|
||||||
|
=> WithHeader(expectedKey, new[] { value }, because, becauseArgs);
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
using (new AssertionScope($"header \"{expectedKey}\" from requests sent with value(s)"))
|
||||||
|
{
|
||||||
|
var matchingHeaderValues = _headers.Where(h => h.Key == expectedKey).SelectMany(h => h.Value.ToArray())
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (expectedValues.Length == 1)
|
||||||
|
{
|
||||||
|
matchingHeaderValues.Should().Contain(expectedValues.First(), because, becauseArgs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var trimmedHeaderValues = string.Join(",", matchingHeaderValues.Select(x => x)).Split(',').Select(x => x.Trim()).ToList();
|
||||||
|
foreach (var expectedValue in expectedValues)
|
||||||
|
{
|
||||||
|
trimmedHeaderValues.Should().Contain(expectedValue, because, becauseArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithoutHeaderKey(string unexpectedKey, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
using (new AssertionScope("headers from requests sent"))
|
||||||
|
{
|
||||||
|
_headers.Select(h => h.Key).Should().NotContain(unexpectedKey, because, becauseArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithoutHeader(string unexpectedKey, string value, string because = "", params object[] becauseArgs)
|
||||||
|
=> WithoutHeader(unexpectedKey, new[] { value }, because, becauseArgs);
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithoutHeader(string unexpectedKey, string[] expectedValues, string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
using (new AssertionScope($"header \"{unexpectedKey}\" from requests sent with value(s)"))
|
||||||
|
{
|
||||||
|
var matchingHeaderValues = _headers.Where(h => h.Key == unexpectedKey).SelectMany(h => h.Value.ToArray()).ToArray();
|
||||||
|
|
||||||
|
if (expectedValues.Length == 1)
|
||||||
|
{
|
||||||
|
matchingHeaderValues.Should().NotContain(expectedValues.First(), because, becauseArgs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var trimmedHeaderValues = string.Join(",", matchingHeaderValues.Select(x => x)).Split(',').Select(x => x.Trim()).ToList();
|
||||||
|
foreach (var expectedValue in expectedValues)
|
||||||
|
{
|
||||||
|
trimmedHeaderValues.Should().NotContain(expectedValue, because, becauseArgs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, bool> predicate)
|
||||||
{
|
{
|
||||||
Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> filter = requests => requests.Where(predicate).ToList();
|
Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> filter = requests => requests.Where(predicate).ToList();
|
||||||
|
|
||||||
return (filter, requests => (CallsCount is null && filter(requests).Any()) || CallsCount == filter(requests).Count);
|
return (filter, requests => (_callsCount is null && filter(requests).Any()) || _callsCount == filter(requests).Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, string?> expression, IStringMatcher matcher)
|
private (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, string?> expression, IStringMatcher matcher)
|
||||||
{
|
{
|
||||||
return BuildFilterAndCondition(r => matcher.IsMatch(expression(r)).IsPerfect());
|
return BuildFilterAndCondition(r => matcher.IsMatch(expression(r)).IsPerfect());
|
||||||
}
|
}
|
||||||
|
|
||||||
public (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, object?> expression, IObjectMatcher matcher)
|
private (Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> Filter, Func<IReadOnlyList<IRequestMessage>, bool> Condition) BuildFilterAndCondition(Func<IRequestMessage, object?> expression, IObjectMatcher matcher)
|
||||||
{
|
{
|
||||||
return BuildFilterAndCondition(r => matcher.IsMatch(expression(r)).IsPerfect());
|
return BuildFilterAndCondition(r => matcher.IsMatch(expression(r)).IsPerfect());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FilterRequestMessages(Func<IReadOnlyList<IRequestMessage>, IReadOnlyList<IRequestMessage>> filter)
|
|
||||||
{
|
|
||||||
RequestMessages = filter(RequestMessages).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,49 +2,50 @@ using FluentAssertions.Primitives;
|
|||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
// ReSharper disable once CheckNamespace
|
||||||
namespace WireMock.FluentAssertions;
|
namespace WireMock.FluentAssertions
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
|
|
||||||
/// </summary>
|
|
||||||
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a WireMockReceivedAssertions.
|
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
|
public class WireMockReceivedAssertions : ReferenceTypeAssertions<IWireMockServer, WireMockReceivedAssertions>
|
||||||
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
|
|
||||||
{
|
{
|
||||||
}
|
/// <summary>
|
||||||
|
/// Create a WireMockReceivedAssertions.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="server">The <see cref="IWireMockServer"/>.</param>
|
||||||
|
public WireMockReceivedAssertions(IWireMockServer server) : base(server)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asserts if <see cref="IWireMockServer"/> has received no calls.
|
/// Asserts if <see cref="IWireMockServer"/> has received no calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><see cref="WireMockAssertions"/></returns>
|
/// <returns><see cref="WireMockAssertions"/></returns>
|
||||||
public WireMockAssertions HaveReceivedNoCalls()
|
public WireMockAssertions HaveReceivedNoCalls()
|
||||||
{
|
{
|
||||||
return new WireMockAssertions(Subject, 0);
|
return new WireMockAssertions(Subject, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asserts if <see cref="IWireMockServer"/> has received a call.
|
/// Asserts if <see cref="IWireMockServer"/> has received a call.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><see cref="WireMockAssertions"/></returns>
|
/// <returns><see cref="WireMockAssertions"/></returns>
|
||||||
public WireMockAssertions HaveReceivedACall()
|
public WireMockAssertions HaveReceivedACall()
|
||||||
{
|
{
|
||||||
return new WireMockAssertions(Subject, null);
|
return new WireMockAssertions(Subject, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
|
/// Asserts if <see cref="IWireMockServer"/> has received n-calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="callsCount"></param>
|
/// <param name="callsCount"></param>
|
||||||
/// <returns><see cref="WireMockANumberOfCallsAssertions"/></returns>
|
/// <returns><see cref="WireMockANumberOfCallsAssertions"/></returns>
|
||||||
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
|
public WireMockANumberOfCallsAssertions HaveReceived(int callsCount)
|
||||||
{
|
{
|
||||||
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
|
return new WireMockANumberOfCallsAssertions(Subject, callsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override string Identifier => "wiremockserver";
|
protected override string Identifier => "wiremockserver";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -33,9 +33,6 @@ internal class CSharpCodeMatcher : ICSharpCodeMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Value { get; }
|
|
||||||
|
|
||||||
private readonly AnyOf<string, StringPattern>[] _patterns;
|
private readonly AnyOf<string, StringPattern>[] _patterns;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -57,7 +54,6 @@ internal class CSharpCodeMatcher : ICSharpCodeMatcher
|
|||||||
_patterns = Guard.NotNull(patterns);
|
_patterns = Guard.NotNull(patterns);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
MatchOperator = matchOperator;
|
MatchOperator = matchOperator;
|
||||||
Value = patterns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MatchResult IsMatch(string? input)
|
public MatchResult IsMatch(string? input)
|
||||||
@@ -164,34 +160,34 @@ internal class CSharpCodeMatcher : ICSharpCodeMatcher
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0_OR_GREATER)
|
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1 || NET5_0_OR_GREATER)
|
||||||
Assembly assembly;
|
Assembly assembly;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source);
|
assembly = CSScriptLib.CSScript.Evaluator.CompileCode(source);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new WireMockException($"CSharpCodeMatcher: Unable to compile code `{source}` for WireMock.CodeHelper", ex);
|
throw new WireMockException($"CSharpCodeMatcher: Unable to compile code `{source}` for WireMock.CodeHelper", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
dynamic script;
|
dynamic script;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
script = CSScripting.ReflectionExtensions.CreateObject(assembly, "*");
|
script = CSScripting.ReflectionExtensions.CreateObject(assembly, "*");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new WireMockException("CSharpCodeMatcher: Unable to create object from assembly", ex);
|
throw new WireMockException("CSharpCodeMatcher: Unable to create object from assembly", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result = script.IsMatch(inputValue);
|
result = script.IsMatch(inputValue);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
|
throw new NotSupportedException("The 'CSharpCodeMatcher' cannot be used in netstandard 1.3");
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp3.1' or '$(TargetFramework)' == 'net5.0' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0'">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netcoreapp3.1' or '$(TargetFramework)' == 'net5.0' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0'">
|
||||||
<PackageReference Include="CS-Script" Version="4.8.13" />
|
<PackageReference Include="CS-Script" Version="4.4.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -11,47 +11,47 @@ public interface IWireMockOpenApiParserExampleValues
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a Boolean.
|
/// An example value for a Boolean.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool Boolean { get; }
|
bool Boolean { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for an Integer.
|
/// An example value for an Integer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int Integer { get; }
|
int Integer { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a Float.
|
/// An example value for a Float.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
float Float { get; }
|
float Float { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a Double.
|
/// An example value for a Double.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
double Double { get; }
|
double Double { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a Date.
|
/// An example value for a Date.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Func<DateTime> Date { get; }
|
Func<DateTime> Date { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a DateTime.
|
/// An example value for a DateTime.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Func<DateTime> DateTime { get; }
|
Func<DateTime> DateTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for Bytes.
|
/// An example value for Bytes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
byte[] Bytes { get; }
|
byte[] Bytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a Object.
|
/// An example value for a Object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
object Object { get; }
|
object Object { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An example value for a String.
|
/// An example value for a String.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string String { get; }
|
string String { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// OpenApi Schema to generate dynamic examples more accurate
|
/// OpenApi Schema to generate dynamic examples more accurate
|
||||||
|
|||||||
@@ -11,31 +11,31 @@ namespace WireMock.Net.OpenApiParser.Settings;
|
|||||||
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
|
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual bool Boolean => RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true;
|
public virtual bool Boolean { get => RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual int Integer => RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42;
|
public virtual int Integer { get => RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42; set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual float Float => RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f;
|
public virtual float Float { get => RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f; set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual double Double => RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d;
|
public virtual double Double { get => RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d; set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Func<DateTime> Date => () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date;
|
public virtual Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Func<DateTime> DateTime => () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow;
|
public virtual Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual byte[] Bytes => RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate();
|
public virtual byte[] Bytes { get => RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate(); set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual object Object => "example-object";
|
public virtual object Object { get; set; } = "example-object";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string String => RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string";
|
public virtual string String { get => RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; set { } }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual OpenApiSchema? Schema { get; set; }
|
public virtual OpenApiSchema? Schema { get; set; }
|
||||||
|
|||||||
@@ -9,31 +9,31 @@ namespace WireMock.Net.OpenApiParser.Settings;
|
|||||||
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
|
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual bool Boolean => true;
|
public virtual bool Boolean { get; set; } = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual int Integer => 42;
|
public virtual int Integer { get; set; } = 42;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual float Float => 4.2f;
|
public virtual float Float { get; set; } = 4.2f;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual double Double => 4.2d;
|
public virtual double Double { get; set; } = 4.2d;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Func<DateTime> Date { get; } = () => System.DateTime.UtcNow.Date;
|
public virtual Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual Func<DateTime> DateTime { get; } = () => System.DateTime.UtcNow;
|
public virtual Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual byte[] Bytes { get; } = { 48, 49, 50 };
|
public virtual byte[] Bytes { get; set; } = { 48, 49, 50 };
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual object Object => "example-object";
|
public virtual object Object { get; set; } = "example-object";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string String => "example-string";
|
public virtual string String { get; set; } = "example-string";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual OpenApiSchema? Schema { get; set; } = new();
|
public virtual OpenApiSchema? Schema { get; set; } = new();
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
using System;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Stef.Validation;
|
|
||||||
using WireMock.Client.Builders;
|
using WireMock.Client.Builders;
|
||||||
|
|
||||||
namespace WireMock.Client.Extensions;
|
namespace WireMock.Client.Extensions;
|
||||||
@@ -13,77 +7,13 @@ namespace WireMock.Client.Extensions;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class WireMockAdminApiExtensions
|
public static class WireMockAdminApiExtensions
|
||||||
{
|
{
|
||||||
private const int MaxRetries = 5;
|
|
||||||
private const int InitialWaitingTimeInMilliSeconds = 500;
|
|
||||||
private const string HealthStatusHealthy = "Healthy";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
/// <param name="api">See <see cref="IWireMockAdminApi"/>.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi adminApi)
|
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi api)
|
||||||
{
|
{
|
||||||
return new AdminApiMappingBuilder(adminApi);
|
return new AdminApiMappingBuilder(api);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set basic authentication to access the <see cref="IWireMockAdminApi"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
|
||||||
/// <param name="username">The admin username.</param>
|
|
||||||
/// <param name="password">The admin password.</param>
|
|
||||||
/// <returns><see cref="IWireMockAdminApi"/></returns>
|
|
||||||
public static IWireMockAdminApi WithAuthorization(this IWireMockAdminApi adminApi, string username, string password)
|
|
||||||
{
|
|
||||||
Guard.NotNull(adminApi);
|
|
||||||
Guard.NotNullOrEmpty(username);
|
|
||||||
Guard.NotNullOrEmpty(password);
|
|
||||||
|
|
||||||
adminApi.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes($"{username}:{password}")));
|
|
||||||
return adminApi;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wait for the WireMock.Net server to be healthy. (The "/__admin/health" returns "Healthy").
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
|
|
||||||
/// <param name="maxRetries">The maximum number of retries. Default is <c>5</c>.</param>
|
|
||||||
/// <param name="cancellationToken">The optional <see cref="CancellationToken"/>.</param>
|
|
||||||
/// <returns>A completed Task in case the health endpoint is available, else throws a <see cref="InvalidOperationException"/>.</returns>
|
|
||||||
public static async Task WaitForHealthAsync(this IWireMockAdminApi adminApi, int maxRetries = MaxRetries, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
Guard.NotNull(adminApi);
|
|
||||||
|
|
||||||
var retries = 0;
|
|
||||||
var waitTime = InitialWaitingTimeInMilliSeconds;
|
|
||||||
var totalWaitTime = waitTime;
|
|
||||||
var isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
|
||||||
while (!isHealthy && retries < MaxRetries && !cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
waitTime = (int)(InitialWaitingTimeInMilliSeconds * Math.Pow(2, retries));
|
|
||||||
await Task.Delay(waitTime, cancellationToken);
|
|
||||||
isHealthy = await IsHealthyAsync(adminApi, cancellationToken);
|
|
||||||
retries++;
|
|
||||||
totalWaitTime += waitTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (retries >= MaxRetries)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"The /__admin/health endpoint did not return 'Healthy' after {MaxRetries} retries and {totalWaitTime / 1000.0:0.0} seconds.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static async Task<bool> IsHealthyAsync(IWireMockAdminApi adminApi, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var status = await adminApi.GetHealthAsync(cancellationToken);
|
|
||||||
return string.Equals(status, HealthStatusHealthy, StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,24 +24,12 @@ public interface IWireMockAdminApi
|
|||||||
[Header("Authorization")]
|
[Header("Authorization")]
|
||||||
AuthenticationHeaderValue Authorization { get; set; }
|
AuthenticationHeaderValue Authorization { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get health status.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns HttpStatusCode <c>200</c> with a value <c>Healthy</c> to indicate that WireMock.Net is healthy.
|
|
||||||
/// Else it returns HttpStatusCode <c>404</c>.
|
|
||||||
/// </returns>
|
|
||||||
[Get("health")]
|
|
||||||
[AllowAnyStatusCode]
|
|
||||||
Task<string> GetHealthAsync(CancellationToken cancellationToken = default);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the settings.
|
/// Get the settings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>SettingsModel</returns>
|
/// <returns>SettingsModel</returns>
|
||||||
[Get("settings")]
|
[Get("settings")]
|
||||||
Task<SettingsModel> GetSettingsAsync(CancellationToken cancellationToken = default);
|
Task<SettingsModel> GetSettingsAsync();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the settings.
|
/// Update the settings.
|
||||||
|
|||||||
@@ -29,7 +29,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.1.1" />
|
<PackageReference Include="Stef.Validation" Version="0.1.1" />
|
||||||
<PackageReference Include="Testcontainers" Version="[3.9.0]" />
|
<PackageReference Include="Testcontainers" Version="[3.7.0]" />
|
||||||
<PackageReference Include="JetBrains.Annotations" VersionOverride="2022.3.1" PrivateAssets="All" Version="2023.3.0" />
|
<PackageReference Include="JetBrains.Annotations" VersionOverride="2022.3.1" PrivateAssets="All" Version="2023.3.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ using System.Net.Http.Headers;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using DotNet.Testcontainers.Containers;
|
using DotNet.Testcontainers.Containers;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using RestEase;
|
using RestEase;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Client;
|
using WireMock.Client;
|
||||||
using WireMock.Client.Extensions;
|
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
|
|
||||||
namespace WireMock.Net.Testcontainers;
|
namespace WireMock.Net.Testcontainers;
|
||||||
@@ -25,7 +25,8 @@ public sealed class WireMockContainer : DockerContainer
|
|||||||
/// Initializes a new instance of the <see cref="WireMockContainer" /> class.
|
/// Initializes a new instance of the <see cref="WireMockContainer" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="configuration">The container configuration.</param>
|
/// <param name="configuration">The container configuration.</param>
|
||||||
public WireMockContainer(WireMockConfiguration configuration) : base(configuration)
|
/// <param name="logger">The logger.</param>
|
||||||
|
public WireMockContainer(WireMockConfiguration configuration, ILogger logger) : base(configuration, logger)
|
||||||
{
|
{
|
||||||
_configuration = Guard.NotNull(configuration);
|
_configuration = Guard.NotNull(configuration);
|
||||||
}
|
}
|
||||||
@@ -46,7 +47,13 @@ public sealed class WireMockContainer : DockerContainer
|
|||||||
ValidateIfRunning();
|
ValidateIfRunning();
|
||||||
|
|
||||||
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
|
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
|
||||||
return _configuration.HasBasicAuthentication ? api.WithAuthorization(_configuration.Username!, _configuration.Password!) : api;
|
|
||||||
|
if (_configuration.HasBasicAuthentication)
|
||||||
|
{
|
||||||
|
api.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_configuration.Username}:{_configuration.Password}")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
|||||||
{ true, new ContainerInfo("sheyenrath/wiremock.net-windows:latest", @"c:\app\__admin\mappings") }
|
{ true, new ContainerInfo("sheyenrath/wiremock.net-windows:latest", @"c:\app\__admin\mappings") }
|
||||||
};
|
};
|
||||||
|
|
||||||
private const string DefaultLogger = "WireMockConsoleLogger";
|
private const string DefaultLogger = "WireMockNoNewLinesConsoleLogger";
|
||||||
|
|
||||||
private readonly Lazy<Task<bool>> _isWindowsAsLazy = new(async () =>
|
private readonly Lazy<Task<bool>> _isWindowsAsLazy = new(async () =>
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
|||||||
{
|
{
|
||||||
Validate();
|
Validate();
|
||||||
|
|
||||||
return new WireMockContainer(DockerResourceConfiguration);
|
return new WireMockContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -157,7 +157,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
|
|||||||
return builder
|
return builder
|
||||||
.WithPortBinding(WireMockContainer.ContainerPort, true)
|
.WithPortBinding(WireMockContainer.ContainerPort, true)
|
||||||
.WithCommand($"--WireMockLogger {DefaultLogger}")
|
.WithCommand($"--WireMockLogger {DefaultLogger}")
|
||||||
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("By Stef Heyenrath"));
|
.WithWaitStrategy(waitForContainerOS.UntilMessageIsLogged("WireMock.Net server running"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -5,36 +5,18 @@ using WireMock.Models;
|
|||||||
|
|
||||||
namespace WireMock.Extensions;
|
namespace WireMock.Extensions;
|
||||||
|
|
||||||
/// <summary>
|
internal static class AnyOfExtensions
|
||||||
/// Some extensions for AnyOf.
|
|
||||||
/// </summary>
|
|
||||||
public static class AnyOfExtensions
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets the pattern.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="value">AnyOf type</param>
|
|
||||||
/// <returns>string value</returns>
|
|
||||||
public static string GetPattern(this AnyOf<string, StringPattern> value)
|
public static string GetPattern(this AnyOf<string, StringPattern> value)
|
||||||
{
|
{
|
||||||
return value.IsFirst ? value.First : value.Second.Pattern;
|
return value.IsFirst ? value.First : value.Second.Pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a string-patterns to AnyOf patterns.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="patterns">The string patterns</param>
|
|
||||||
/// <returns>The AnyOf patterns</returns>
|
|
||||||
public static AnyOf<string, StringPattern>[] ToAnyOfPatterns(this IEnumerable<string> patterns)
|
public static AnyOf<string, StringPattern>[] ToAnyOfPatterns(this IEnumerable<string> patterns)
|
||||||
{
|
{
|
||||||
return patterns.Select(p => p.ToAnyOfPattern()).ToArray();
|
return patterns.Select(p => p.ToAnyOfPattern()).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts a string-pattern to AnyOf pattern.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pattern">The string pattern</param>
|
|
||||||
/// <returns>The AnyOf pattern</returns>
|
|
||||||
public static AnyOf<string, StringPattern> ToAnyOfPattern(this string pattern)
|
public static AnyOf<string, StringPattern> ToAnyOfPattern(this string pattern)
|
||||||
{
|
{
|
||||||
return new AnyOf<string, StringPattern>(pattern);
|
return new AnyOf<string, StringPattern>(pattern);
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ public interface IMapping
|
|||||||
int? StateTimes { get; }
|
int? StateTimes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The RequestMatcher.
|
/// The Request matcher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IRequestMatcher RequestMatcher { get; }
|
IRequestMatcher RequestMatcher { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ResponseProvider.
|
/// The Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IResponseProvider Provider { get; }
|
IResponseProvider Provider { get; }
|
||||||
|
|
||||||
@@ -136,11 +136,6 @@ public interface IMapping
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
double? Probability { get; }
|
double? Probability { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Grpc ProtoDefinition which is used for this mapping (request and response). [Optional]
|
|
||||||
/// </summary>
|
|
||||||
IdOrText? ProtoDefinition { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ProvideResponseAsync
|
/// ProvideResponseAsync
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -155,44 +150,4 @@ public interface IMapping
|
|||||||
/// <param name="nextState">The Next State.</param>
|
/// <param name="nextState">The Next State.</param>
|
||||||
/// <returns>The <see cref="IRequestMatchResult"/>.</returns>
|
/// <returns>The <see cref="IRequestMatchResult"/>.</returns>
|
||||||
IRequestMatchResult GetRequestMatchResult(IRequestMessage requestMessage, string? nextState);
|
IRequestMatchResult GetRequestMatchResult(IRequestMessage requestMessage, string? nextState);
|
||||||
|
}
|
||||||
/// <summary>
|
|
||||||
/// Define the scenario.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="scenario">The scenario.</param>
|
|
||||||
/// <returns>The <see cref="IMapping"/>.</returns>
|
|
||||||
IMapping WithScenario(string scenario);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Define the probability when this request should be matched. [Optional]
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="probability">The probability.</param>
|
|
||||||
/// <returns>The <see cref="IMapping"/>.</returns>
|
|
||||||
IMapping WithProbability(double probability);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Define a Grpc ProtoDefinition which is used for this mapping (request and response).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="protoDefinition">The proto definition as text.</param>
|
|
||||||
/// <returns>The <see cref="IMapping"/>.</returns>
|
|
||||||
IMapping WithProtoDefinition(IdOrText protoDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
executionConditionState">State in which the current mapping can occur. [Optional]
|
|
||||||
nextState">The next state which will occur after the current mapping execution. [Optional]
|
|
||||||
stateTimes">Only when the current state is executed this number, the next state which will occur. [Optional]
|
|
||||||
webhooks">The Webhooks. [Optional]
|
|
||||||
useWebhooksFireAndForget">Use Fire and Forget for the defined webhook(s). [Optional]
|
|
||||||
timeSettings">The TimeSettings. [Optional]
|
|
||||||
data">The data object. [Optional]
|
|
||||||
|
|
||||||
|
|
||||||
string? executionConditionState,
|
|
||||||
string? nextState,
|
|
||||||
int? stateTimes,
|
|
||||||
IWebhook[]? webhooks,
|
|
||||||
bool? useWebhooksFireAndForget,
|
|
||||||
ITimeSettings? timeSettings,
|
|
||||||
object? data,
|
|
||||||
*/
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
|
|
||||||
namespace WireMock.Logging;
|
namespace WireMock.Logging;
|
||||||
@@ -10,62 +10,65 @@ namespace WireMock.Logging;
|
|||||||
/// <seealso cref="IWireMockLogger" />
|
/// <seealso cref="IWireMockLogger" />
|
||||||
public class WireMockConsoleLogger : IWireMockLogger
|
public class WireMockConsoleLogger : IWireMockLogger
|
||||||
{
|
{
|
||||||
|
private const string NewlineWindows = "\r\n";
|
||||||
|
private const string NewlineUnix = "\n";
|
||||||
|
|
||||||
|
private readonly bool _removeNewLines;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class.
|
/// Initializes a new instance of the <see cref="WireMockConsoleLogger"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public WireMockConsoleLogger()
|
public WireMockConsoleLogger(bool removeNewLines = false)
|
||||||
{
|
{
|
||||||
try
|
_removeNewLines = removeNewLines;
|
||||||
{
|
|
||||||
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Debug"/>
|
/// <inheritdoc />
|
||||||
public void Debug(string formatString, params object[] args)
|
public void Debug(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Debug", formatString, args));
|
WriteLine(Format("Debug", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Info"/>
|
/// <inheritdoc />
|
||||||
public void Info(string formatString, params object[] args)
|
public void Info(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Info", formatString, args));
|
WriteLine(Format("Info", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Warn"/>
|
/// <inheritdoc />
|
||||||
public void Warn(string formatString, params object[] args)
|
public void Warn(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Warn", formatString, args));
|
WriteLine(Format("Warn", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Error(string, object[])"/>
|
/// <inheritdoc />
|
||||||
public void Error(string formatString, params object[] args)
|
public void Error(string formatString, params object[] args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Error", formatString, args));
|
WriteLine(Format("Error", formatString, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.Error(string, Exception)"/>
|
/// <inheritdoc />
|
||||||
public void Error(string formatString, Exception exception)
|
public void Error(string formatString, Exception exception)
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Error", formatString, exception.Message));
|
WriteLine(Format("Error", formatString, exception.Message));
|
||||||
|
|
||||||
if (exception is AggregateException ae)
|
if (exception is AggregateException ae)
|
||||||
{
|
{
|
||||||
ae.Handle(ex =>
|
ae.Handle(ex =>
|
||||||
{
|
{
|
||||||
Console.WriteLine(Format("Error", "Exception {0}", ex.Message));
|
WriteLine(Format("Error", "Exception {0}", ex.Message));
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
|
/// <inheritdoc />
|
||||||
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
|
||||||
{
|
{
|
||||||
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
string message = JsonConvert.SerializeObject(logEntryModel, Formatting.Indented);
|
||||||
Console.WriteLine(Format("DebugRequestResponse", "Admin[{0}] {1}", isAdminRequest, message));
|
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)
|
||||||
@@ -74,4 +77,13 @@ public class WireMockConsoleLogger : IWireMockLogger
|
|||||||
|
|
||||||
return $"{DateTime.UtcNow} [{level}] : {message}";
|
return $"{DateTime.UtcNow} [{level}] : {message}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The value to write.</param>
|
||||||
|
private void WriteLine(string value)
|
||||||
|
{
|
||||||
|
Console.WriteLine(!_removeNewLines ? value : value.Replace(NewlineWindows, string.Empty).Replace(NewlineUnix, string.Empty));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Stef.Validation;
|
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.Models;
|
using WireMock.Models;
|
||||||
using WireMock.ResponseProviders;
|
using WireMock.ResponseProviders;
|
||||||
@@ -32,7 +31,7 @@ public class Mapping : IMapping
|
|||||||
public int Priority { get; }
|
public int Priority { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string? Scenario { get; private set; }
|
public string? Scenario { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string? ExecutionConditionState { get; }
|
public string? ExecutionConditionState { get; }
|
||||||
@@ -77,10 +76,7 @@ public class Mapping : IMapping
|
|||||||
public object? Data { get; }
|
public object? Data { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public double? Probability { get; private set; }
|
public double? Probability { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IdOrText? ProtoDefinition { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
||||||
@@ -102,8 +98,8 @@ public class Mapping : IMapping
|
|||||||
/// <param name="useWebhooksFireAndForget">Use Fire and Forget for the defined webhook(s). [Optional]</param>
|
/// <param name="useWebhooksFireAndForget">Use Fire and Forget for the defined webhook(s). [Optional]</param>
|
||||||
/// <param name="timeSettings">The TimeSettings. [Optional]</param>
|
/// <param name="timeSettings">The TimeSettings. [Optional]</param>
|
||||||
/// <param name="data">The data object. [Optional]</param>
|
/// <param name="data">The data object. [Optional]</param>
|
||||||
public Mapping
|
/// <param name="probability">Define the probability when this request should be matched. [Optional]</param>
|
||||||
(
|
public Mapping(
|
||||||
Guid guid,
|
Guid guid,
|
||||||
DateTime updatedAt,
|
DateTime updatedAt,
|
||||||
string? title,
|
string? title,
|
||||||
@@ -120,8 +116,8 @@ public class Mapping : IMapping
|
|||||||
IWebhook[]? webhooks,
|
IWebhook[]? webhooks,
|
||||||
bool? useWebhooksFireAndForget,
|
bool? useWebhooksFireAndForget,
|
||||||
ITimeSettings? timeSettings,
|
ITimeSettings? timeSettings,
|
||||||
object? data
|
object? data,
|
||||||
)
|
double? probability)
|
||||||
{
|
{
|
||||||
Guid = guid;
|
Guid = guid;
|
||||||
UpdatedAt = updatedAt;
|
UpdatedAt = updatedAt;
|
||||||
@@ -140,6 +136,7 @@ public class Mapping : IMapping
|
|||||||
UseWebhooksFireAndForget = useWebhooksFireAndForget;
|
UseWebhooksFireAndForget = useWebhooksFireAndForget;
|
||||||
TimeSettings = timeSettings;
|
TimeSettings = timeSettings;
|
||||||
Data = data;
|
Data = data;
|
||||||
|
Probability = probability;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -171,25 +168,4 @@ public class Mapping : IMapping
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IMapping WithProbability(double probability)
|
|
||||||
{
|
|
||||||
Probability = Guard.NotNull(probability);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IMapping WithScenario(string scenario)
|
|
||||||
{
|
|
||||||
Scenario = Guard.NotNullOrWhiteSpace(scenario);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public IMapping WithProtoDefinition(IdOrText protoDefinition)
|
|
||||||
{
|
|
||||||
ProtoDefinition = protoDefinition;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,6 @@ using Stef.Validation;
|
|||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
using WireMock.Owin;
|
using WireMock.Owin;
|
||||||
using WireMock.RequestBuilders;
|
|
||||||
using WireMock.ResponseBuilders;
|
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using WireMock.Settings;
|
using WireMock.Settings;
|
||||||
@@ -148,15 +146,6 @@ public class MappingBuilder : IMappingBuilder
|
|||||||
{
|
{
|
||||||
_mappingToFileSaver.SaveMappingToFile(mapping);
|
_mappingToFileSaver.SaveMappingToFile(mapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link this mapping to the Request
|
|
||||||
((Request)mapping.RequestMatcher).Mapping = mapping;
|
|
||||||
|
|
||||||
// Link this mapping to the Response
|
|
||||||
if (mapping.Provider is Response response)
|
|
||||||
{
|
|
||||||
response.Mapping = mapping;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ToJson(object value)
|
private static string ToJson(object value)
|
||||||
|
|||||||
@@ -10,15 +10,20 @@ namespace WireMock.Matchers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Support Regex
|
||||||
|
/// </summary>
|
||||||
|
public bool Regex { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="AbstractJsonPartialMatcher"/> class.
|
/// Initializes a new instance of the <see cref="AbstractJsonPartialMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The string value to check for equality.</param>
|
/// <param name="value">The string value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
/// <param name="regex">Support Regex.</param>
|
||||||
protected AbstractJsonPartialMatcher(string value, bool ignoreCase = false, bool regex = false) :
|
protected AbstractJsonPartialMatcher(string value, bool ignoreCase = false, bool regex = false) : base(value, ignoreCase)
|
||||||
base(value, ignoreCase, regex)
|
|
||||||
{
|
{
|
||||||
|
Regex = regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -27,9 +32,9 @@ public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
|||||||
/// <param name="value">The object value to check for equality.</param>
|
/// <param name="value">The object value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
/// <param name="regex">Support Regex.</param>
|
||||||
protected AbstractJsonPartialMatcher(object value, bool ignoreCase = false, bool regex = false) :
|
protected AbstractJsonPartialMatcher(object value, bool ignoreCase = false, bool regex = false) : base(value, ignoreCase)
|
||||||
base(value, ignoreCase, regex)
|
|
||||||
{
|
{
|
||||||
|
Regex = regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,15 +44,15 @@ public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
|||||||
/// <param name="value">The value to check for equality.</param>
|
/// <param name="value">The value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
/// <param name="regex">Support Regex.</param>
|
||||||
protected AbstractJsonPartialMatcher(MatchBehaviour matchBehaviour, object value, bool ignoreCase = false, bool regex = false) :
|
protected AbstractJsonPartialMatcher(MatchBehaviour matchBehaviour, object value, bool ignoreCase = false, bool regex = false) : base(matchBehaviour, value, ignoreCase)
|
||||||
base(matchBehaviour, value, ignoreCase, regex)
|
|
||||||
{
|
{
|
||||||
|
Regex = regex;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override bool IsMatch(JToken value, JToken? input)
|
protected override bool IsMatch(JToken? value, JToken? input)
|
||||||
{
|
{
|
||||||
if (value == input)
|
if (value == null || value == input)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -67,7 +72,7 @@ public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
|||||||
((value.Type == JTokenType.Guid && input.Type == JTokenType.String) ||
|
((value.Type == JTokenType.Guid && input.Type == JTokenType.String) ||
|
||||||
(value.Type == JTokenType.String && input.Type == JTokenType.Guid)))
|
(value.Type == JTokenType.String && input.Type == JTokenType.Guid)))
|
||||||
{
|
{
|
||||||
return IsMatch(value.ToString().ToUpperInvariant(), input.ToString().ToUpperInvariant());
|
return IsMatch(value.ToString(), input.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == null || value.Type != input.Type)
|
if (input == null || value.Type != input.Type)
|
||||||
|
|||||||
@@ -17,15 +17,6 @@ public class ExactMatcher : IStringMatcher, IIgnoreCaseMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <param name="value">The string value.</param>
|
|
||||||
public ExactMatcher(MatchBehaviour matchBehaviour, string value) : this(matchBehaviour, true, MatchOperator.Or, new AnyOf<string, StringPattern>(value))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,8 +9,15 @@ namespace WireMock.Matchers;
|
|||||||
/// <seealso cref="IObjectMatcher" />
|
/// <seealso cref="IObjectMatcher" />
|
||||||
public class ExactObjectMatcher : IObjectMatcher
|
public class ExactObjectMatcher : IObjectMatcher
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public object Value { get; }
|
/// Gets the value as object.
|
||||||
|
/// </summary>
|
||||||
|
public object? ValueAsObject { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value as byte[].
|
||||||
|
/// </summary>
|
||||||
|
public byte[]? ValueAsBytes { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
@@ -30,7 +37,7 @@ public class ExactObjectMatcher : IObjectMatcher
|
|||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public ExactObjectMatcher(MatchBehaviour matchBehaviour, object value)
|
public ExactObjectMatcher(MatchBehaviour matchBehaviour, object value)
|
||||||
{
|
{
|
||||||
Value = Guard.NotNull(value);
|
ValueAsObject = Guard.NotNull(value);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,21 +56,21 @@ public class ExactObjectMatcher : IObjectMatcher
|
|||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public ExactObjectMatcher(MatchBehaviour matchBehaviour, byte[] value)
|
public ExactObjectMatcher(MatchBehaviour matchBehaviour, byte[] value)
|
||||||
{
|
{
|
||||||
Value = Guard.NotNull(value);
|
ValueAsBytes = Guard.NotNull(value);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchResult IsMatch(object? input)
|
public MatchResult IsMatch(object? input)
|
||||||
{
|
{
|
||||||
bool equals;
|
bool equals = false;
|
||||||
if (Value is byte[] valueAsBytes && input is byte[] inputAsBytes)
|
if (ValueAsObject != null)
|
||||||
{
|
{
|
||||||
equals = valueAsBytes.SequenceEqual(inputAsBytes);
|
equals = Equals(ValueAsObject, input);
|
||||||
}
|
}
|
||||||
else
|
else if (input != null)
|
||||||
{
|
{
|
||||||
equals = Equals(Value, input);
|
equals = ValueAsBytes?.SequenceEqual((byte[])input) == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(equals));
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(equals));
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IBytesMatcher
|
|
||||||
/// </summary>
|
|
||||||
public interface IBytesMatcher : IMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the specified input is match.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">The input byte array.</param>
|
|
||||||
/// <param name="cancellationToken">The CancellationToken [optional].</param>
|
|
||||||
/// <returns>MatchResult</returns>
|
|
||||||
Task<MatchResult> IsMatchAsync(byte[]? input, CancellationToken cancellationToken = default);
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IDecodeBytesMatcher
|
|
||||||
/// </summary>
|
|
||||||
public interface IDecodeBytesMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Decode byte array to an object.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">The byte array</param>
|
|
||||||
/// <param name="cancellationToken">The CancellationToken [optional].</param>
|
|
||||||
/// <returns>object</returns>
|
|
||||||
Task<object?> DecodeAsync(byte[]? input, CancellationToken cancellationToken = default);
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace WireMock.Matchers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IJsonMatcher
|
|
||||||
/// <seealso cref="IObjectMatcher"/> and <seealso cref="IIgnoreCaseMatcher"/>.
|
|
||||||
/// </summary>
|
|
||||||
public interface IJsonMatcher : IObjectMatcher, IIgnoreCaseMatcher
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -5,12 +5,6 @@ namespace WireMock.Matchers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IObjectMatcher : IMatcher
|
public interface IObjectMatcher : IMatcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets the value (can be a string or an object).
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Value</returns>
|
|
||||||
object Value { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines whether the specified input is match.
|
/// Determines whether the specified input is match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace WireMock.Matchers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IProtoBufMatcher
|
|
||||||
/// </summary>
|
|
||||||
public interface IProtoBufMatcher : IDecodeBytesMatcher, IBytesMatcher
|
|
||||||
{
|
|
||||||
}
|
|
||||||
14
src/WireMock.Net/Matchers/IValueMatcher.cs
Normal file
14
src/WireMock.Net/Matchers/IValueMatcher.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace WireMock.Matchers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// IValueMatcher
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="IObjectMatcher" />
|
||||||
|
public interface IValueMatcher : IObjectMatcher
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the value (can be a string or an object).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Value</returns>
|
||||||
|
object Value { get; }
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ namespace WireMock.Matchers;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// JsonPathMatcher
|
/// JsonPathMatcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="IStringMatcher" />
|
/// <seealso cref="IMatcher" />
|
||||||
/// <seealso cref="IObjectMatcher" />
|
/// <seealso cref="IObjectMatcher" />
|
||||||
public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
||||||
{
|
{
|
||||||
@@ -20,9 +20,6 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Value { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -55,7 +52,6 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
_patterns = Guard.NotNull(patterns);
|
_patterns = Guard.NotNull(patterns);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
MatchOperator = matchOperator;
|
MatchOperator = matchOperator;
|
||||||
Value = patterns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -123,7 +119,7 @@ public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
// The SelectToken method can accept a string path to a child token ( i.e. "Manufacturers[0].Products[0].Price").
|
// The SelectToken method can accept a string path to a child token ( i.e. "Manufacturers[0].Products[0].Price").
|
||||||
// In that case it will return a JValue (some type) which does not implement the IEnumerable interface.
|
// In that case it will return a JValue (some type) which does not implement the IEnumerable interface.
|
||||||
var values = _patterns.Select(pattern => array.SelectToken(pattern.GetPattern()) != null).ToArray();
|
var values = _patterns.Select(pattern => array.SelectToken(pattern.GetPattern()) != null).ToArray();
|
||||||
|
|
||||||
return MatchScores.ToScore(values, MatchOperator);
|
return MatchScores.ToScore(values, MatchOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ public class JmesPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
{
|
{
|
||||||
private readonly AnyOf<string, StringPattern>[] _patterns;
|
private readonly AnyOf<string, StringPattern>[] _patterns;
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Value { get; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
@@ -62,7 +59,6 @@ public class JmesPathMatcher : IStringMatcher, IObjectMatcher
|
|||||||
_patterns = Guard.NotNull(patterns);
|
_patterns = Guard.NotNull(patterns);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
MatchOperator = matchOperator;
|
MatchOperator = matchOperator;
|
||||||
Value = patterns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using JsonUtils = WireMock.Util.JsonUtils;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
namespace WireMock.Matchers;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// JsonMatcher
|
/// JsonMatcher
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonMatcher : IJsonMatcher
|
public class JsonMatcher : IValueMatcher, IIgnoreCaseMatcher
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual string Name => nameof(JsonMatcher);
|
public virtual string Name => "JsonMatcher";
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IValueMatcher.Value"/>
|
||||||
public object Value { get; }
|
public object Value { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -25,20 +24,15 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
||||||
public bool IgnoreCase { get; }
|
public bool IgnoreCase { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Support Regex
|
|
||||||
/// </summary>
|
|
||||||
public bool Regex { get; }
|
|
||||||
|
|
||||||
private readonly JToken _valueAsJToken;
|
private readonly JToken _valueAsJToken;
|
||||||
|
private readonly Func<JToken, JToken> _jTokenConverter;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The string value to check for equality.</param>
|
/// <param name="value">The string value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
public JsonMatcher(string value, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase)
|
||||||
public JsonMatcher(string value, bool ignoreCase = false, bool regex = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase, regex)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +41,7 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The object value to check for equality.</param>
|
/// <param name="value">The object value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
public JsonMatcher(object value, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase)
|
||||||
public JsonMatcher(object value, bool ignoreCase = false, bool regex = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase, regex)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,17 +51,16 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="value">The value to check for equality.</param>
|
/// <param name="value">The value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
/// <param name="regex">Support Regex.</param>
|
public JsonMatcher(MatchBehaviour matchBehaviour, object value, bool ignoreCase = false)
|
||||||
public JsonMatcher(MatchBehaviour matchBehaviour, object value, bool ignoreCase = false, bool regex = false)
|
|
||||||
{
|
{
|
||||||
Guard.NotNull(value);
|
Guard.NotNull(value);
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
IgnoreCase = ignoreCase;
|
IgnoreCase = ignoreCase;
|
||||||
Regex = regex;
|
|
||||||
|
|
||||||
Value = value;
|
Value = value;
|
||||||
_valueAsJToken = JsonUtils.ConvertValueToJToken(value);
|
_valueAsJToken = ConvertValueToJToken(value);
|
||||||
|
_jTokenConverter = ignoreCase ? Rename : jToken => jToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -82,9 +74,9 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var inputAsJToken = JsonUtils.ConvertValueToJToken(input);
|
var inputAsJToken = ConvertValueToJToken(input);
|
||||||
|
|
||||||
var match = IsMatch(RenameJToken(_valueAsJToken), RenameJToken(inputAsJToken));
|
var match = IsMatch(_jTokenConverter(_valueAsJToken), _jTokenConverter(inputAsJToken));
|
||||||
score = MatchScores.ToScore(match);
|
score = MatchScores.ToScore(match);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -102,134 +94,62 @@ public class JsonMatcher : IJsonMatcher
|
|||||||
/// <param name="value">Matcher value</param>
|
/// <param name="value">Matcher value</param>
|
||||||
/// <param name="input">Input value</param>
|
/// <param name="input">Input value</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected virtual bool IsMatch(JToken value, JToken? input)
|
protected virtual bool IsMatch(JToken value, JToken input)
|
||||||
{
|
{
|
||||||
// If equal, return true.
|
return JToken.DeepEquals(value, input);
|
||||||
if (input == value)
|
}
|
||||||
|
|
||||||
|
private static JToken ConvertValueToJToken(object value)
|
||||||
|
{
|
||||||
|
// Check if JToken, string, IEnumerable or object
|
||||||
|
switch (value)
|
||||||
{
|
{
|
||||||
return true;
|
case JToken tokenValue:
|
||||||
}
|
return tokenValue;
|
||||||
|
|
||||||
// If input is null, return false.
|
case string stringValue:
|
||||||
if (input == null)
|
return JsonUtils.Parse(stringValue);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If using Regex and the value is a string, use the MatchRegex method.
|
case IEnumerable enumerableValue:
|
||||||
if (Regex && value.Type == JTokenType.String)
|
return JArray.FromObject(enumerableValue);
|
||||||
{
|
|
||||||
var valueAsString = value.ToString();
|
|
||||||
|
|
||||||
var (valid, result) = RegexUtils.MatchRegex(valueAsString, input.ToString());
|
|
||||||
if (valid)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the value is a Guid and the input is a string, or vice versa, convert them to strings and compare the string values.
|
|
||||||
if ((value.Type == JTokenType.Guid && input.Type == JTokenType.String) || (value.Type == JTokenType.String && input.Type == JTokenType.Guid))
|
|
||||||
{
|
|
||||||
return JToken.DeepEquals(value.ToString().ToUpperInvariant(), input.ToString().ToUpperInvariant());
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (value.Type)
|
|
||||||
{
|
|
||||||
// If the value is an object, compare all properties.
|
|
||||||
case JTokenType.Object:
|
|
||||||
var valueProperties = value.ToObject<Dictionary<string, JToken>>() ?? new Dictionary<string, JToken>();
|
|
||||||
var inputProperties = input.ToObject<Dictionary<string, JToken>>() ?? new Dictionary<string, JToken>();
|
|
||||||
|
|
||||||
// If the number of properties is different, return false.
|
|
||||||
if (valueProperties.Count != inputProperties.Count)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare all properties. The input must match all properties of the value.
|
|
||||||
foreach (var pair in valueProperties)
|
|
||||||
{
|
|
||||||
if (!IsMatch(pair.Value, inputProperties[pair.Key]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// If the value is an array, compare all elements.
|
|
||||||
case JTokenType.Array:
|
|
||||||
var valueArray = value.ToObject<JToken[]>() ?? EmptyArray<JToken>.Value;
|
|
||||||
var inputArray = input.ToObject<JToken[]>() ?? EmptyArray<JToken>.Value;
|
|
||||||
|
|
||||||
// If the number of elements is different, return false.
|
|
||||||
if (valueArray.Length != inputArray.Length)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return !valueArray.Where((valueToken, index) => !IsMatch(valueToken, inputArray[index])).Any();
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Use JToken.DeepEquals() for all other types.
|
return JObject.FromObject(value);
|
||||||
return JToken.DeepEquals(value, input);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/11679804/json-net-rename-properties
|
|
||||||
private JToken RenameJToken(JToken input)
|
|
||||||
{
|
|
||||||
if (!IgnoreCase)
|
|
||||||
{
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
return input switch
|
|
||||||
{
|
|
||||||
JProperty property => RenameJProperty(property),
|
|
||||||
JArray array => RenameJArray(array),
|
|
||||||
JObject obj => RenameJObject(obj),
|
|
||||||
_ => input
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private JProperty RenameJProperty(JProperty property)
|
|
||||||
{
|
|
||||||
if (!IgnoreCase)
|
|
||||||
{
|
|
||||||
return property;
|
|
||||||
}
|
|
||||||
|
|
||||||
var propertyValue = property.Value;
|
|
||||||
if (propertyValue.Type == JTokenType.String && !Regex)
|
|
||||||
{
|
|
||||||
var stringValue = propertyValue.Value<string>()!;
|
|
||||||
propertyValue = ToUpper(stringValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JProperty(ToUpper(property.Name)!, RenameJToken(propertyValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
private JArray RenameJArray(JArray array)
|
|
||||||
{
|
|
||||||
if (Regex)
|
|
||||||
{
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
var renamedValues = array.Select(RenameJToken);
|
|
||||||
return new JArray(renamedValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JObject RenameJObject(JObject obj)
|
|
||||||
{
|
|
||||||
var renamedProperties = obj.Properties().Select(RenameJProperty);
|
|
||||||
return new JObject(renamedProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string? ToUpper(string? input)
|
private static string? ToUpper(string? input)
|
||||||
{
|
{
|
||||||
return input?.ToUpperInvariant();
|
return input?.ToUpperInvariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/11679804/json-net-rename-properties
|
||||||
|
private static JToken Rename(JToken json)
|
||||||
|
{
|
||||||
|
if (json is JProperty property)
|
||||||
|
{
|
||||||
|
JToken propertyValue = property.Value;
|
||||||
|
if (propertyValue.Type == JTokenType.String)
|
||||||
|
{
|
||||||
|
string stringValue = propertyValue.Value<string>()!;
|
||||||
|
propertyValue = ToUpper(stringValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JProperty(ToUpper(property.Name)!, Rename(propertyValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json is JArray array)
|
||||||
|
{
|
||||||
|
var renamedValues = array.Select(Rename);
|
||||||
|
return new JArray(renamedValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json is JObject obj)
|
||||||
|
{
|
||||||
|
var renamedProperties = obj.Properties().Select(Rename);
|
||||||
|
return new JObject(renamedProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -22,9 +22,6 @@ public class LinqMatcher : IObjectMatcher, IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Value { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -64,7 +61,6 @@ public class LinqMatcher : IObjectMatcher, IStringMatcher
|
|||||||
_patterns = Guard.NotNull(patterns);
|
_patterns = Guard.NotNull(patterns);
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
MatchOperator = matchOperator;
|
MatchOperator = matchOperator;
|
||||||
Value = patterns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -23,11 +23,4 @@ internal static class MatchBehaviourHelper
|
|||||||
|
|
||||||
return match <= MatchScores.Tolerance ? MatchScores.Perfect : MatchScores.Mismatch;
|
return match <= MatchScores.Tolerance ? MatchScores.Perfect : MatchScores.Mismatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static MatchResult Convert(MatchBehaviour matchBehaviour, MatchResult result)
|
|
||||||
{
|
|
||||||
return matchBehaviour == MatchBehaviour.AcceptOnMatch ?
|
|
||||||
result :
|
|
||||||
new MatchResult(Convert(matchBehaviour, result.Score), result.Exception);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -17,9 +17,6 @@ public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public object Value { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="NotNullOrEmptyMatcher"/> class.
|
/// Initializes a new instance of the <see cref="NotNullOrEmptyMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -27,7 +24,6 @@ public class NotNullOrEmptyMatcher : IObjectMatcher, IStringMatcher
|
|||||||
public NotNullOrEmptyMatcher(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
public NotNullOrEmptyMatcher(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
Value = string.Empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
#if PROTOBUF
|
|
||||||
using System;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ProtoBufJsonConverter;
|
|
||||||
using ProtoBufJsonConverter.Models;
|
|
||||||
using Stef.Validation;
|
|
||||||
using WireMock.Models;
|
|
||||||
using WireMock.Util;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Grpc ProtoBuf Matcher
|
|
||||||
/// </summary>
|
|
||||||
/// <inheritdoc cref="IProtoBufMatcher"/>
|
|
||||||
public class ProtoBufMatcher : IProtoBufMatcher
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string Name => nameof(ProtoBufMatcher);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Func to define The proto definition as text.
|
|
||||||
/// </summary>
|
|
||||||
public Func<IdOrText> ProtoDefinition { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".
|
|
||||||
/// </summary>
|
|
||||||
public string MessageType { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Matcher to use (optional).
|
|
||||||
/// </summary>
|
|
||||||
public IObjectMatcher? Matcher { get; }
|
|
||||||
|
|
||||||
private static readonly Converter ProtoBufToJsonConverter = SingletonFactory<Converter>.GetInstance();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="ProtoBufMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="protoDefinition">The proto definition.</param>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <param name="matcher">The optional jsonMatcher to use to match the ProtoBuf as (json) object.</param>
|
|
||||||
public ProtoBufMatcher(
|
|
||||||
Func<IdOrText> protoDefinition,
|
|
||||||
string messageType,
|
|
||||||
MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch,
|
|
||||||
IObjectMatcher? matcher = null
|
|
||||||
)
|
|
||||||
{
|
|
||||||
ProtoDefinition = Guard.NotNull(protoDefinition);
|
|
||||||
MessageType = Guard.NotNullOrWhiteSpace(messageType);
|
|
||||||
Matcher = matcher;
|
|
||||||
MatchBehaviour = matchBehaviour;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public async Task<MatchResult> IsMatchAsync(byte[]? input, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
var result = new MatchResult();
|
|
||||||
|
|
||||||
if (input != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var instance = await DecodeAsync(input, true, cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
result = Matcher?.IsMatch(instance) ?? new MatchResult(MatchScores.Perfect);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
result = new MatchResult(MatchScores.Mismatch, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Task<object?> DecodeAsync(byte[]? input, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return DecodeAsync(input, false, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<object?> DecodeAsync(byte[]? input, bool throwException, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
if (input == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var request = new ConvertToObjectRequest(ProtoDefinition().Text, MessageType, input);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await ProtoBufToJsonConverter.ConvertAsync(request, cancellationToken).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
if (throwException)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -26,8 +26,10 @@ public abstract class RequestMessageCompositeMatcher : IRequestMatcher
|
|||||||
/// <param name="type">The CompositeMatcherType type (Defaults to 'And')</param>
|
/// <param name="type">The CompositeMatcherType type (Defaults to 'And')</param>
|
||||||
protected RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And)
|
protected RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And)
|
||||||
{
|
{
|
||||||
RequestMatchers = Guard.NotNull(requestMatchers);
|
Guard.NotNull(requestMatchers);
|
||||||
|
|
||||||
_type = type;
|
_type = type;
|
||||||
|
RequestMatchers = requestMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="schema">The schema.</param>
|
/// <param name="schema">The schema.</param>
|
||||||
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. [optional]</param>
|
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
|
||||||
public RequestMessageGraphQLMatcher(MatchBehaviour matchBehaviour, string schema, IDictionary<string, Type>? customScalars = null) :
|
public RequestMessageGraphQLMatcher(MatchBehaviour matchBehaviour, string schema, IDictionary<string, Type>? customScalars = null) :
|
||||||
this(CreateMatcherArray(matchBehaviour, schema, customScalars))
|
this(CreateMatcherArray(matchBehaviour, schema, customScalars))
|
||||||
{
|
{
|
||||||
@@ -38,7 +38,7 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="schema">The schema.</param>
|
/// <param name="schema">The schema.</param>
|
||||||
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. [optional]</param>
|
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
|
||||||
public RequestMessageGraphQLMatcher(MatchBehaviour matchBehaviour, GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars = null) :
|
public RequestMessageGraphQLMatcher(MatchBehaviour matchBehaviour, GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars = null) :
|
||||||
this(CreateMatcherArray(matchBehaviour, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern, GraphQL.Types.ISchema>(schema), customScalars))
|
this(CreateMatcherArray(matchBehaviour, new AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern, GraphQL.Types.ISchema>(schema), customScalars))
|
||||||
{
|
{
|
||||||
@@ -94,7 +94,8 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher
|
|||||||
#if GRAPHQL
|
#if GRAPHQL
|
||||||
private static IMatcher[] CreateMatcherArray(
|
private static IMatcher[] CreateMatcherArray(
|
||||||
MatchBehaviour matchBehaviour,
|
MatchBehaviour matchBehaviour,
|
||||||
AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern, GraphQL.Types.ISchema> schema,
|
AnyOfTypes.AnyOf<string, WireMock.Models.StringPattern,
|
||||||
|
GraphQL.Types.ISchema> schema,
|
||||||
IDictionary<string, Type>? customScalars
|
IDictionary<string, Type>? customScalars
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using Stef.Validation;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The request HTTP Version matcher.
|
|
||||||
/// </summary>
|
|
||||||
public class RequestMessageHttpVersionMatcher : IRequestMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The matcher.
|
|
||||||
/// </summary>
|
|
||||||
public IStringMatcher? Matcher { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The func.
|
|
||||||
/// </summary>
|
|
||||||
public Func<string, bool>? Func { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The <see cref="MatchBehaviour"/>
|
|
||||||
/// </summary>
|
|
||||||
public MatchBehaviour Behaviour { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The HTTP Version
|
|
||||||
/// </summary>
|
|
||||||
public string? HttpVersion { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageHttpVersionMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <param name="httpVersion">The HTTP Version.</param>
|
|
||||||
public RequestMessageHttpVersionMatcher(MatchBehaviour matchBehaviour, string httpVersion) :
|
|
||||||
this(matchBehaviour, new ExactMatcher(matchBehaviour, httpVersion))
|
|
||||||
{
|
|
||||||
HttpVersion = httpVersion;
|
|
||||||
Behaviour = matchBehaviour;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <param name="matcher">The matcher.</param>
|
|
||||||
public RequestMessageHttpVersionMatcher(MatchBehaviour matchBehaviour, IStringMatcher matcher)
|
|
||||||
{
|
|
||||||
Matcher = Guard.NotNull(matcher);
|
|
||||||
Behaviour = matchBehaviour;
|
|
||||||
HttpVersion = matcher.GetPatterns().FirstOrDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="func">The function.</param>
|
|
||||||
public RequestMessageHttpVersionMatcher(Func<string, bool> func)
|
|
||||||
{
|
|
||||||
Func = Guard.NotNull(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
|
||||||
{
|
|
||||||
var (score, exception) = GetMatchResult(requestMessage).Expand();
|
|
||||||
return requestMatchResult.AddScore(GetType(), score, exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatchResult GetMatchResult(IRequestMessage requestMessage)
|
|
||||||
{
|
|
||||||
if (Matcher != null)
|
|
||||||
{
|
|
||||||
return Matcher.IsMatch(requestMessage.HttpVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Func != null)
|
|
||||||
{
|
|
||||||
return MatchScores.ToScore(Func(requestMessage.HttpVersion));
|
|
||||||
}
|
|
||||||
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using WireMock.Models;
|
|
||||||
|
|
||||||
namespace WireMock.Matchers.Request;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The request body Grpc ProtoBuf matcher.
|
|
||||||
/// </summary>
|
|
||||||
public class RequestMessageProtoBufMatcher : IRequestMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The ProtoBufMatcher.
|
|
||||||
/// </summary>
|
|
||||||
public IProtoBufMatcher? Matcher { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageProtoBufMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <param name="protoDefinition">The Func to define The proto definition as text.</param>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matcher">The optional matcher to use to match the ProtoBuf as (json) object.</param>
|
|
||||||
public RequestMessageProtoBufMatcher(MatchBehaviour matchBehaviour, Func<IdOrText> protoDefinition, string messageType, IObjectMatcher? matcher = null)
|
|
||||||
{
|
|
||||||
#if PROTOBUF
|
|
||||||
Matcher = new ProtoBufMatcher(protoDefinition, messageType, matchBehaviour, matcher);
|
|
||||||
#else
|
|
||||||
throw new System.NotSupportedException("The ProtoBufMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower.");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult)
|
|
||||||
{
|
|
||||||
var (score, exception) = GetMatchResult(requestMessage).Expand();
|
|
||||||
return requestMatchResult.AddScore(GetType(), score, exception);
|
|
||||||
}
|
|
||||||
|
|
||||||
private MatchResult GetMatchResult(IRequestMessage requestMessage)
|
|
||||||
{
|
|
||||||
return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,7 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using WireMock.Models;
|
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|
||||||
// ReSharper disable once CheckNamespace
|
|
||||||
namespace WireMock.Util;
|
namespace WireMock.Util;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -12,7 +9,7 @@ namespace WireMock.Util;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BodyData : IBodyData
|
public class BodyData : IBodyData
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.Encoding" />
|
||||||
public Encoding? Encoding { get; set; }
|
public Encoding? Encoding { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -21,38 +18,30 @@ public class BodyData : IBodyData
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IDictionary<string, string>? BodyAsFormUrlEncoded { get; set; }
|
public IDictionary<string, string>? BodyAsFormUrlEncoded { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.BodyAsJson" />
|
||||||
public object? BodyAsJson { get; set; }
|
public object? BodyAsJson { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.BodyAsBytes" />
|
||||||
public byte[]? BodyAsBytes { get; set; }
|
public byte[]? BodyAsBytes { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.BodyAsJsonIndented" />
|
||||||
public bool? BodyAsJsonIndented { get; set; }
|
public bool? BodyAsJsonIndented { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.BodyAsFile" />
|
||||||
public string? BodyAsFile { get; set; }
|
public string? BodyAsFile { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.BodyAsFileIsCached" />
|
||||||
public bool? BodyAsFileIsCached { get; set; }
|
public bool? BodyAsFileIsCached { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.DetectedBodyType" />
|
||||||
public BodyType? DetectedBodyType { get; set; }
|
public BodyType? DetectedBodyType { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IBodyData.DetectedBodyTypeFromContentType" />
|
||||||
public BodyType? DetectedBodyTypeFromContentType { get; set; }
|
public BodyType? DetectedBodyTypeFromContentType { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc cref="IRequestMessage.DetectedCompression" />
|
||||||
public string? DetectedCompression { get; set; }
|
public string? DetectedCompression { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public string? IsFuncUsed { get; set; }
|
public string? IsFuncUsed { get; set; }
|
||||||
|
|
||||||
#region ProtoBuf
|
|
||||||
/// <inheritdoc />
|
|
||||||
public Func<IdOrText>? ProtoDefinition { get; set; }
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public string? ProtoBufMessageType { get; set; }
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using AnyOfTypes;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace WireMock.Models;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// GraphQLSchemaDetails
|
|
||||||
/// </summary>
|
|
||||||
public class GraphQLSchemaDetails
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The GraphQL schema as a string.
|
|
||||||
/// </summary>
|
|
||||||
public string? SchemaAsString { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The GraphQL schema as a StringPattern.
|
|
||||||
/// </summary>
|
|
||||||
public StringPattern? SchemaAsStringPattern { get; set; }
|
|
||||||
|
|
||||||
#if GRAPHQL
|
|
||||||
/// <summary>
|
|
||||||
/// The GraphQL schema as a <seealso cref="GraphQL.Types.ISchema"/>.
|
|
||||||
/// </summary>
|
|
||||||
public GraphQL.Types.ISchema? SchemaAsISchema { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The GraphQL Schema.
|
|
||||||
/// </summary>
|
|
||||||
[JsonIgnore]
|
|
||||||
public AnyOf<string, StringPattern, GraphQL.Types.ISchema>? Schema
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (SchemaAsString != null)
|
|
||||||
{
|
|
||||||
return SchemaAsString;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SchemaAsStringPattern != null)
|
|
||||||
{
|
|
||||||
return SchemaAsStringPattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SchemaAsISchema != null)
|
|
||||||
{
|
|
||||||
return new AnyOf<string, StringPattern, GraphQL.Types.ISchema>(SchemaAsISchema);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The custom Scalars to define for this schema.
|
|
||||||
/// </summary>
|
|
||||||
public IDictionary<string, Type>? CustomScalars { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#if USE_ASPNETCORE && !NETSTANDARD1_3
|
#if USE_ASPNETCORE && !NETSTANDARD1_3
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Https;
|
using Microsoft.AspNetCore.Server.Kestrel.Https;
|
||||||
@@ -27,7 +25,7 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
if (urlDetail.IsHttps)
|
if (urlDetail.IsHttps)
|
||||||
{
|
{
|
||||||
Listen(kestrelOptions, urlDetail, listenOptions =>
|
kestrelOptions.ListenAnyIP(urlDetail.Port, listenOptions =>
|
||||||
{
|
{
|
||||||
listenOptions.UseHttps(options =>
|
listenOptions.UseHttps(options =>
|
||||||
{
|
{
|
||||||
@@ -39,57 +37,23 @@ namespace WireMock.Owin
|
|||||||
wireMockMiddlewareOptions.X509ThumbprintOrSubjectName,
|
wireMockMiddlewareOptions.X509ThumbprintOrSubjectName,
|
||||||
wireMockMiddlewareOptions.X509CertificateFilePath,
|
wireMockMiddlewareOptions.X509CertificateFilePath,
|
||||||
wireMockMiddlewareOptions.X509CertificatePassword,
|
wireMockMiddlewareOptions.X509CertificatePassword,
|
||||||
urlDetail.Host
|
urlDetail.Host);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
options.ClientCertificateMode = (ClientCertificateMode)wireMockMiddlewareOptions.ClientCertificateMode;
|
options.ClientCertificateMode = (ClientCertificateMode) wireMockMiddlewareOptions.ClientCertificateMode;
|
||||||
if (wireMockMiddlewareOptions.AcceptAnyClientCertificate)
|
if (wireMockMiddlewareOptions.AcceptAnyClientCertificate)
|
||||||
{
|
{
|
||||||
options.ClientCertificateValidation = (_, _, _) => true;
|
options.ClientCertificateValidation = (_, _, _) => true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (urlDetail.IsHttp2)
|
|
||||||
{
|
|
||||||
listenOptions.Protocols = HttpProtocols.Http2;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (urlDetail.IsHttp2)
|
|
||||||
{
|
{
|
||||||
Listen(kestrelOptions, urlDetail, listenOptions =>
|
kestrelOptions.ListenAnyIP(urlDetail.Port);
|
||||||
{
|
|
||||||
listenOptions.Protocols = HttpProtocols.Http2;
|
|
||||||
});
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Listen(kestrelOptions, urlDetail, _ => { });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Listen(KestrelServerOptions kestrelOptions, HostUrlDetails urlDetail, Action<ListenOptions> configure)
|
|
||||||
{
|
|
||||||
// Listens on ::1 and 127.0.0.1 with the given port.
|
|
||||||
if (urlDetail is { Port: > 0, Host: "localhost" or "127.0.0.1" or "0.0.0.0" or "::1" })
|
|
||||||
{
|
|
||||||
kestrelOptions.ListenLocalhost(urlDetail.Port, configure);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try to parse the host as a valid IP address and bind to the given IP address and port.
|
|
||||||
if (IPAddress.TryParse(urlDetail.Host, out var ipAddress))
|
|
||||||
{
|
|
||||||
kestrelOptions.Listen(ipAddress, urlDetail.Port, configure);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, listen on all IPs.
|
|
||||||
kestrelOptions.ListenAnyIP(urlDetail.Port, configure);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class IWebHostBuilderExtensions
|
internal static class IWebHostBuilderExtensions
|
||||||
|
|||||||
@@ -14,174 +14,171 @@ using WireMock.Owin.Mappers;
|
|||||||
using WireMock.Services;
|
using WireMock.Services;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
|
|
||||||
namespace WireMock.Owin;
|
namespace WireMock.Owin
|
||||||
|
|
||||||
internal partial class AspNetCoreSelfHost : IOwinSelfHost
|
|
||||||
{
|
{
|
||||||
private const string CorsPolicyName = "WireMock.Net - Policy";
|
internal partial class AspNetCoreSelfHost : IOwinSelfHost
|
||||||
|
|
||||||
private readonly CancellationTokenSource _cts = new();
|
|
||||||
private readonly IWireMockMiddlewareOptions _wireMockMiddlewareOptions;
|
|
||||||
private readonly IWireMockLogger _logger;
|
|
||||||
private readonly HostUrlOptions _urlOptions;
|
|
||||||
|
|
||||||
private Exception _runningException;
|
|
||||||
private IWebHost _host;
|
|
||||||
|
|
||||||
public bool IsStarted { get; private set; }
|
|
||||||
|
|
||||||
public List<string> Urls { get; } = new();
|
|
||||||
|
|
||||||
public List<int> Ports { get; } = new();
|
|
||||||
|
|
||||||
public Exception RunningException => _runningException;
|
|
||||||
|
|
||||||
public AspNetCoreSelfHost(IWireMockMiddlewareOptions wireMockMiddlewareOptions, HostUrlOptions urlOptions)
|
|
||||||
{
|
{
|
||||||
Guard.NotNull(wireMockMiddlewareOptions);
|
private const string CorsPolicyName = "WireMock.Net - Policy";
|
||||||
Guard.NotNull(urlOptions);
|
|
||||||
|
|
||||||
_logger = wireMockMiddlewareOptions.Logger ?? new WireMockConsoleLogger();
|
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||||
|
private readonly IWireMockMiddlewareOptions _wireMockMiddlewareOptions;
|
||||||
|
private readonly IWireMockLogger _logger;
|
||||||
|
private readonly HostUrlOptions _urlOptions;
|
||||||
|
|
||||||
_wireMockMiddlewareOptions = wireMockMiddlewareOptions;
|
private Exception _runningException;
|
||||||
_urlOptions = urlOptions;
|
private IWebHost _host;
|
||||||
}
|
|
||||||
|
|
||||||
public Task StartAsync()
|
public bool IsStarted { get; private set; }
|
||||||
{
|
|
||||||
var builder = new WebHostBuilder();
|
|
||||||
|
|
||||||
// Workaround for https://github.com/WireMock-Net/WireMock.Net/issues/292
|
public List<string> Urls { get; } = new();
|
||||||
// On some platforms, AppContext.BaseDirectory is null, which causes WebHostBuilder to fail if ContentRoot is not
|
|
||||||
// specified (even though we don't actually use that base path mechanism, since we have our own way of configuring
|
public List<int> Ports { get; } = new();
|
||||||
// a filesystem handler).
|
|
||||||
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
public Exception RunningException => _runningException;
|
||||||
|
|
||||||
|
public AspNetCoreSelfHost(IWireMockMiddlewareOptions wireMockMiddlewareOptions, HostUrlOptions urlOptions)
|
||||||
{
|
{
|
||||||
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
Guard.NotNull(wireMockMiddlewareOptions);
|
||||||
|
Guard.NotNull(urlOptions);
|
||||||
|
|
||||||
|
_logger = wireMockMiddlewareOptions.Logger ?? new WireMockConsoleLogger();
|
||||||
|
|
||||||
|
_wireMockMiddlewareOptions = wireMockMiddlewareOptions;
|
||||||
|
_urlOptions = urlOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
_host = builder
|
public Task StartAsync()
|
||||||
.UseSetting("suppressStatusMessages", "True") // https://andrewlock.net/suppressing-the-startup-and-shutdown-messages-in-asp-net-core/
|
{
|
||||||
.ConfigureAppConfigurationUsingEnvironmentVariables()
|
var builder = new WebHostBuilder();
|
||||||
.ConfigureServices(services =>
|
|
||||||
|
// Workaround for https://github.com/WireMock-Net/WireMock.Net/issues/292
|
||||||
|
// On some platforms, AppContext.BaseDirectory is null, which causes WebHostBuilder to fail if ContentRoot is not
|
||||||
|
// specified (even though we don't actually use that base path mechanism, since we have our own way of configuring
|
||||||
|
// a filesystem handler).
|
||||||
|
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
||||||
{
|
{
|
||||||
services.AddSingleton(_wireMockMiddlewareOptions);
|
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||||
services.AddSingleton<IMappingMatcher, MappingMatcher>();
|
}
|
||||||
services.AddSingleton<IRandomizerDoubleBetween0And1, RandomizerDoubleBetween0And1>();
|
|
||||||
services.AddSingleton<IOwinRequestMapper, OwinRequestMapper>();
|
_host = builder
|
||||||
services.AddSingleton<IOwinResponseMapper, OwinResponseMapper>();
|
.UseSetting("suppressStatusMessages", "True") // https://andrewlock.net/suppressing-the-startup-and-shutdown-messages-in-asp-net-core/
|
||||||
services.AddSingleton<IGuidUtils, GuidUtils>();
|
.ConfigureAppConfigurationUsingEnvironmentVariables()
|
||||||
|
.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
services.AddSingleton(_wireMockMiddlewareOptions);
|
||||||
|
services.AddSingleton<IMappingMatcher, MappingMatcher>();
|
||||||
|
services.AddSingleton<IRandomizerDoubleBetween0And1, RandomizerDoubleBetween0And1>();
|
||||||
|
services.AddSingleton<IOwinRequestMapper, OwinRequestMapper>();
|
||||||
|
services.AddSingleton<IOwinResponseMapper, OwinResponseMapper>();
|
||||||
|
services.AddSingleton<IGuidUtils, GuidUtils>();
|
||||||
|
|
||||||
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
|
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
|
||||||
AddCors(services);
|
AddCors(services);
|
||||||
#endif
|
#endif
|
||||||
_wireMockMiddlewareOptions.AdditionalServiceRegistration?.Invoke(services);
|
_wireMockMiddlewareOptions.AdditionalServiceRegistration?.Invoke(services);
|
||||||
})
|
})
|
||||||
.Configure(appBuilder =>
|
.Configure(appBuilder =>
|
||||||
{
|
{
|
||||||
appBuilder.UseMiddleware<GlobalExceptionMiddleware>();
|
appBuilder.UseMiddleware<GlobalExceptionMiddleware>();
|
||||||
|
|
||||||
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
|
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
|
||||||
UseCors(appBuilder);
|
UseCors(appBuilder);
|
||||||
#endif
|
#endif
|
||||||
_wireMockMiddlewareOptions.PreWireMockMiddlewareInit?.Invoke(appBuilder);
|
_wireMockMiddlewareOptions.PreWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||||
|
|
||||||
appBuilder.UseMiddleware<WireMockMiddleware>();
|
appBuilder.UseMiddleware<WireMockMiddleware>();
|
||||||
|
|
||||||
_wireMockMiddlewareOptions.PostWireMockMiddlewareInit?.Invoke(appBuilder);
|
_wireMockMiddlewareOptions.PostWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||||
})
|
})
|
||||||
.UseKestrel(options =>
|
.UseKestrel(options =>
|
||||||
{
|
{
|
||||||
SetKestrelOptionsLimits(options);
|
SetKestrelOptionsLimits(options);
|
||||||
|
|
||||||
SetHttpsAndUrls(options, _wireMockMiddlewareOptions, _urlOptions.GetDetails());
|
SetHttpsAndUrls(options, _wireMockMiddlewareOptions, _urlOptions.GetDetails());
|
||||||
})
|
})
|
||||||
.ConfigureKestrelServerOptions()
|
.ConfigureKestrelServerOptions()
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
.UseUrls(_urlOptions.GetDetails().Select(u => u.Url).ToArray())
|
.UseUrls(_urlOptions.GetDetails().Select(u => u.Url).ToArray())
|
||||||
#endif
|
#endif
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return RunHost(_cts.Token);
|
return RunHost(_cts.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task RunHost(CancellationToken token)
|
private Task RunHost(CancellationToken token)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
#if NETCOREAPP3_1 || NET5_0_OR_GREATER
|
|
||||||
var appLifetime = _host.Services.GetRequiredService<Microsoft.Extensions.Hosting.IHostApplicationLifetime>();
|
|
||||||
#else
|
|
||||||
var appLifetime = _host.Services.GetRequiredService<IApplicationLifetime>();
|
var appLifetime = _host.Services.GetRequiredService<IApplicationLifetime>();
|
||||||
#endif
|
|
||||||
appLifetime.ApplicationStarted.Register(() =>
|
appLifetime.ApplicationStarted.Register(() =>
|
||||||
{
|
{
|
||||||
var addresses = _host.ServerFeatures
|
var addresses = _host.ServerFeatures
|
||||||
.Get<Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature>()!
|
.Get<Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature>()
|
||||||
.Addresses;
|
.Addresses;
|
||||||
|
|
||||||
foreach (var address in addresses)
|
foreach (string address in addresses)
|
||||||
{
|
{
|
||||||
Urls.Add(address.Replace("0.0.0.0", "localhost").Replace("[::]", "localhost"));
|
Urls.Add(address.Replace("0.0.0.0", "localhost").Replace("[::]", "localhost"));
|
||||||
|
|
||||||
PortUtils.TryExtract(address, out _, out _, out _, out _, out var port);
|
PortUtils.TryExtract(address, out _, out _, out _, out int port);
|
||||||
Ports.Add(port);
|
Ports.Add(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
IsStarted = true;
|
IsStarted = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
_logger.Info("Server using netstandard1.3");
|
_logger.Info("Server using netstandard1.3");
|
||||||
#elif NETSTANDARD2_0
|
#elif NETSTANDARD2_0
|
||||||
_logger.Info("Server using netstandard2.0");
|
_logger.Info("Server using netstandard2.0");
|
||||||
#elif NETSTANDARD2_1
|
#elif NETSTANDARD2_1
|
||||||
_logger.Info("Server using netstandard2.1");
|
_logger.Info("Server using netstandard2.1");
|
||||||
#elif NETCOREAPP3_1
|
#elif NETCOREAPP3_1
|
||||||
_logger.Info("Server using .NET Core App 3.1");
|
_logger.Info("Server using .NET Core App 3.1");
|
||||||
#elif NET5_0
|
#elif NET5_0
|
||||||
_logger.Info("Server using .NET 5.0");
|
_logger.Info("Server using .NET 5.0");
|
||||||
#elif NET6_0
|
#elif NET6_0
|
||||||
_logger.Info("Server using .NET 6.0");
|
_logger.Info("Server using .NET 6.0");
|
||||||
#elif NET7_0
|
#elif NET7_0
|
||||||
_logger.Info("Server using .NET 7.0");
|
_logger.Info("Server using .NET 7.0");
|
||||||
#elif NET8_0
|
#elif NET8_0
|
||||||
_logger.Info("Server using .NET 8.0");
|
_logger.Info("Server using .NET 8.0");
|
||||||
#elif NET46
|
#elif NET46
|
||||||
_logger.Info("Server using .NET Framework 4.6.1 or higher");
|
_logger.Info("Server using .NET Framework 4.6.1 or higher");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
_host.Run(token);
|
_host.Run(token);
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
return _host.RunAsync(token);
|
return _host.RunAsync(token);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_runningException = e;
|
||||||
|
_logger.Error(e.ToString());
|
||||||
|
|
||||||
|
IsStarted = false;
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
|
public Task StopAsync()
|
||||||
{
|
{
|
||||||
_runningException = e;
|
_cts.Cancel();
|
||||||
_logger.Error(e.ToString());
|
|
||||||
|
|
||||||
IsStarted = false;
|
IsStarted = false;
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync()
|
|
||||||
{
|
|
||||||
_cts.Cancel();
|
|
||||||
|
|
||||||
IsStarted = false;
|
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_3
|
||||||
return Task.CompletedTask;
|
return Task.FromResult(true);
|
||||||
#else
|
#else
|
||||||
return _host.StopAsync();
|
return _host.StopAsync();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -7,8 +7,6 @@ internal struct HostUrlDetails
|
|||||||
{
|
{
|
||||||
public bool IsHttps { get; set; }
|
public bool IsHttps { get; set; }
|
||||||
|
|
||||||
public bool IsHttp2 { get; set; }
|
|
||||||
|
|
||||||
public string Url { get; set; }
|
public string Url { get; set; }
|
||||||
|
|
||||||
public string Scheme { get; set; }
|
public string Scheme { get; set; }
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace WireMock.Owin;
|
|||||||
|
|
||||||
internal class HostUrlOptions
|
internal class HostUrlOptions
|
||||||
{
|
{
|
||||||
private const string Star = "*";
|
private const string Localhost = "localhost";
|
||||||
|
|
||||||
public ICollection<string>? Urls { get; set; }
|
public ICollection<string>? Urls { get; set; }
|
||||||
|
|
||||||
@@ -14,8 +14,6 @@ internal class HostUrlOptions
|
|||||||
|
|
||||||
public HostingScheme HostingScheme { get; set; }
|
public HostingScheme HostingScheme { get; set; }
|
||||||
|
|
||||||
public bool? UseHttp2 { get; set; }
|
|
||||||
|
|
||||||
public IReadOnlyList<HostUrlDetails> GetDetails()
|
public IReadOnlyList<HostUrlDetails> GetDetails()
|
||||||
{
|
{
|
||||||
var list = new List<HostUrlDetails>();
|
var list = new List<HostUrlDetails>();
|
||||||
@@ -25,25 +23,25 @@ internal class HostUrlOptions
|
|||||||
{
|
{
|
||||||
var port = Port > 0 ? Port.Value : FindFreeTcpPort();
|
var port = Port > 0 ? Port.Value : FindFreeTcpPort();
|
||||||
var scheme = HostingScheme == HostingScheme.Https ? "https" : "http";
|
var scheme = HostingScheme == HostingScheme.Https ? "https" : "http";
|
||||||
list.Add(new HostUrlDetails { IsHttps = HostingScheme == HostingScheme.Https, IsHttp2 = UseHttp2 == true, Url = $"{scheme}://{Star}:{port}", Scheme = scheme, Host = Star, Port = port });
|
list.Add(new HostUrlDetails { IsHttps = HostingScheme == HostingScheme.Https, Url = $"{scheme}://{Localhost}:{port}", Scheme = scheme, Host = Localhost, Port = port });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HostingScheme == HostingScheme.HttpAndHttps)
|
if (HostingScheme == HostingScheme.HttpAndHttps)
|
||||||
{
|
{
|
||||||
var httpPort = Port > 0 ? Port.Value : FindFreeTcpPort();
|
var httpPort = Port > 0 ? Port.Value : FindFreeTcpPort();
|
||||||
list.Add(new HostUrlDetails { IsHttps = false, IsHttp2 = UseHttp2 == true, Url = $"http://{Star}:{httpPort}", Scheme = "http", Host = Star, Port = httpPort });
|
list.Add(new HostUrlDetails { IsHttps = false, Url = $"http://{Localhost}:{httpPort}", Scheme = "http", Host = Localhost, Port = httpPort });
|
||||||
|
|
||||||
var httpsPort = FindFreeTcpPort(); // In this scenario, always get a free port for https.
|
var httpsPort = FindFreeTcpPort(); // In this scenario, always get a free port for https.
|
||||||
list.Add(new HostUrlDetails { IsHttps = true, IsHttp2 = UseHttp2 == true, Url = $"https://{Star}:{httpsPort}", Scheme = "https", Host = Star, Port = httpsPort });
|
list.Add(new HostUrlDetails { IsHttps = true, Url = $"https://{Localhost}:{httpsPort}", Scheme = "https", Host = Localhost, Port = httpsPort });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
foreach (var url in Urls)
|
foreach (string url in Urls)
|
||||||
{
|
{
|
||||||
if (PortUtils.TryExtract(url, out var isHttps, out var isGrpc, out var protocol, out var host, out var port))
|
if (PortUtils.TryExtract(url, out var isHttps, out var protocol, out var host, out var port))
|
||||||
{
|
{
|
||||||
list.Add(new HostUrlDetails { IsHttps = isHttps, IsHttp2 = isGrpc, Url = url, Scheme = protocol, Host = host, Port = port });
|
list.Add(new HostUrlDetails { IsHttps = isHttps, Url = url, Scheme = protocol, Host = host, Port = port });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,18 @@ using IResponse = Microsoft.Owin.IOwinResponse;
|
|||||||
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace WireMock.Owin.Mappers;
|
namespace WireMock.Owin.Mappers
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// IOwinResponseMapper
|
|
||||||
/// </summary>
|
|
||||||
internal interface IOwinResponseMapper
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Map ResponseMessage to IResponse.
|
/// IOwinResponseMapper
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="responseMessage">The ResponseMessage</param>
|
internal interface IOwinResponseMapper
|
||||||
/// <param name="response">The OwinResponse/HttpResponse</param>
|
{
|
||||||
Task MapAsync(IResponseMessage? responseMessage, IResponse response);
|
/// <summary>
|
||||||
}
|
/// Map ResponseMessage to IResponse.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="responseMessage">The ResponseMessage</param>
|
||||||
|
/// <param name="response">The OwinResponse/HttpResponse</param>
|
||||||
|
Task MapAsync(IResponseMessage? responseMessage, IResponse response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,102 +8,103 @@ using WireMock.Util;
|
|||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using IRequest = Microsoft.Owin.IOwinRequest;
|
using IRequest = Microsoft.Owin.IOwinRequest;
|
||||||
#else
|
#else
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Http.Extensions;
|
using Microsoft.AspNetCore.Http.Extensions;
|
||||||
using IRequest = Microsoft.AspNetCore.Http.HttpRequest;
|
using IRequest = Microsoft.AspNetCore.Http.HttpRequest;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace WireMock.Owin.Mappers;
|
namespace WireMock.Owin.Mappers
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// OwinRequestMapper
|
|
||||||
/// </summary>
|
|
||||||
internal class OwinRequestMapper : IOwinRequestMapper
|
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <summary>
|
||||||
public async Task<RequestMessage> MapAsync(IRequest request, IWireMockMiddlewareOptions options)
|
/// OwinRequestMapper
|
||||||
|
/// </summary>
|
||||||
|
internal class OwinRequestMapper : IOwinRequestMapper
|
||||||
{
|
{
|
||||||
var (urlDetails, clientIP) = ParseRequest(request);
|
/// <inheritdoc cref="IOwinRequestMapper.MapAsync"/>
|
||||||
|
public async Task<RequestMessage> MapAsync(IRequest request, IWireMockMiddlewareOptions options)
|
||||||
var method = request.Method;
|
|
||||||
var httpVersion = HttpVersionParser.Parse(request.Protocol);
|
|
||||||
|
|
||||||
var headers = new Dictionary<string, string[]>();
|
|
||||||
IEnumerable<string>? contentEncodingHeader = null;
|
|
||||||
foreach (var header in request.Headers)
|
|
||||||
{
|
{
|
||||||
headers.Add(header.Key, header.Value!);
|
var (urlDetails, clientIP) = ParseRequest(request);
|
||||||
|
|
||||||
if (string.Equals(header.Key, HttpKnownHeaderNames.ContentEncoding, StringComparison.OrdinalIgnoreCase))
|
string method = request.Method;
|
||||||
|
|
||||||
|
var headers = new Dictionary<string, string[]>();
|
||||||
|
IEnumerable<string>? contentEncodingHeader = null;
|
||||||
|
foreach (var header in request.Headers)
|
||||||
{
|
{
|
||||||
contentEncodingHeader = header.Value;
|
headers.Add(header.Key, header.Value!);
|
||||||
|
|
||||||
|
if (string.Equals(header.Key, HttpKnownHeaderNames.ContentEncoding, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
contentEncodingHeader = header.Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var cookies = new Dictionary<string, string>();
|
var cookies = new Dictionary<string, string>();
|
||||||
if (request.Cookies.Any())
|
if (request.Cookies.Any())
|
||||||
{
|
|
||||||
foreach (var cookie in request.Cookies)
|
|
||||||
{
|
{
|
||||||
cookies.Add(cookie.Key, cookie.Value);
|
cookies = new Dictionary<string, string>();
|
||||||
|
foreach (var cookie in request.Cookies)
|
||||||
|
{
|
||||||
|
cookies.Add(cookie.Key, cookie.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
IBodyData? body = null;
|
IBodyData? body = null;
|
||||||
if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
|
if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
|
||||||
{
|
|
||||||
var bodyParserSettings = new BodyParserSettings
|
|
||||||
{
|
{
|
||||||
Stream = request.Body,
|
var bodyParserSettings = new BodyParserSettings
|
||||||
ContentType = request.ContentType,
|
{
|
||||||
DeserializeJson = !options.DisableJsonBodyParsing.GetValueOrDefault(false),
|
Stream = request.Body,
|
||||||
ContentEncoding = contentEncodingHeader?.FirstOrDefault(),
|
ContentType = request.ContentType,
|
||||||
DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
|
DeserializeJson = !options.DisableJsonBodyParsing.GetValueOrDefault(false),
|
||||||
};
|
ContentEncoding = contentEncodingHeader?.FirstOrDefault(),
|
||||||
|
DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
|
||||||
|
};
|
||||||
|
|
||||||
body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RequestMessage(
|
return new RequestMessage(
|
||||||
options,
|
options,
|
||||||
urlDetails,
|
urlDetails,
|
||||||
method,
|
method,
|
||||||
clientIP,
|
clientIP,
|
||||||
body,
|
body,
|
||||||
headers,
|
headers,
|
||||||
cookies,
|
cookies
|
||||||
httpVersion
|
|
||||||
#if USE_ASPNETCORE
|
#if USE_ASPNETCORE
|
||||||
, await request.HttpContext.Connection.GetClientCertificateAsync()
|
, await request.HttpContext.Connection.GetClientCertificateAsync()
|
||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
DateTime = DateTime.UtcNow
|
DateTime = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
private static (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||||
{
|
{
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
var urlDetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
var urlDetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
||||||
var clientIP = request.RemoteIpAddress;
|
var clientIP = request.RemoteIpAddress;
|
||||||
#else
|
#else
|
||||||
var urlDetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
var urlDetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
||||||
|
|
||||||
var connection = request.HttpContext.Connection;
|
var connection = request.HttpContext.Connection;
|
||||||
string clientIP;
|
string clientIP;
|
||||||
if (connection.RemoteIpAddress is null)
|
if (connection.RemoteIpAddress is null)
|
||||||
{
|
{
|
||||||
clientIP = string.Empty;
|
clientIP = string.Empty;
|
||||||
}
|
}
|
||||||
else if (connection.RemoteIpAddress.IsIPv4MappedToIPv6)
|
else if (connection.RemoteIpAddress.IsIPv4MappedToIPv6)
|
||||||
{
|
{
|
||||||
clientIP = connection.RemoteIpAddress.MapToIPv4().ToString();
|
clientIP = connection.RemoteIpAddress.MapToIPv4().ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
clientIP = connection.RemoteIpAddress.ToString();
|
clientIP = connection.RemoteIpAddress.ToString();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return (urlDetails, clientIP);
|
return (urlDetails, clientIP);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,6 @@ using WireMock.Http;
|
|||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Util;
|
|
||||||
|
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||||
#else
|
#else
|
||||||
@@ -64,11 +62,11 @@ namespace WireMock.Owin.Mappers
|
|||||||
switch (responseMessage.FaultType)
|
switch (responseMessage.FaultType)
|
||||||
{
|
{
|
||||||
case FaultType.EMPTY_RESPONSE:
|
case FaultType.EMPTY_RESPONSE:
|
||||||
bytes = IsFault(responseMessage) ? EmptyArray<byte>.Value : await GetNormalBodyAsync(responseMessage).ConfigureAwait(false);
|
bytes = IsFault(responseMessage) ? EmptyArray<byte>.Value : GetNormalBody(responseMessage);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FaultType.MALFORMED_RESPONSE_CHUNK:
|
case FaultType.MALFORMED_RESPONSE_CHUNK:
|
||||||
bytes = await GetNormalBodyAsync(responseMessage).ConfigureAwait(false) ?? EmptyArray<byte>.Value;
|
bytes = GetNormalBody(responseMessage) ?? EmptyArray<byte>.Value;
|
||||||
if (IsFault(responseMessage))
|
if (IsFault(responseMessage))
|
||||||
{
|
{
|
||||||
bytes = bytes.Take(bytes.Length / 2).Union(_randomizerBytes.Generate()).ToArray();
|
bytes = bytes.Take(bytes.Length / 2).Union(_randomizerBytes.Generate()).ToArray();
|
||||||
@@ -76,18 +74,18 @@ namespace WireMock.Owin.Mappers
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bytes = await GetNormalBodyAsync(responseMessage).ConfigureAwait(false);
|
bytes = GetNormalBody(responseMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var statusCodeType = responseMessage.StatusCode?.GetType();
|
var statusCodeType = responseMessage.StatusCode?.GetType();
|
||||||
switch (statusCodeType)
|
switch (statusCodeType)
|
||||||
{
|
{
|
||||||
case { } when statusCodeType == typeof(int) || statusCodeType == typeof(int?) || statusCodeType.GetTypeInfo().IsEnum:
|
case { } typeAsIntOrEnum when typeAsIntOrEnum == typeof(int) || typeAsIntOrEnum == typeof(int?) || typeAsIntOrEnum.GetTypeInfo().IsEnum:
|
||||||
response.StatusCode = MapStatusCode((int)responseMessage.StatusCode!);
|
response.StatusCode = MapStatusCode((int)responseMessage.StatusCode!);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case { } when statusCodeType == typeof(string):
|
case { } typeAsString when typeAsString == typeof(string):
|
||||||
// Note: this case will also match on null
|
// Note: this case will also match on null
|
||||||
int.TryParse(responseMessage.StatusCode as string, out var result);
|
int.TryParse(responseMessage.StatusCode as string, out var result);
|
||||||
response.StatusCode = MapStatusCode(result);
|
response.StatusCode = MapStatusCode(result);
|
||||||
@@ -110,8 +108,6 @@ namespace WireMock.Owin.Mappers
|
|||||||
_options.Logger.Warn("Error writing response body. Exception : {0}", ex);
|
_options.Logger.Warn("Error writing response body. Exception : {0}", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SetResponseTrailingHeaders(responseMessage, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int MapStatusCode(int code)
|
private int MapStatusCode(int code)
|
||||||
@@ -129,7 +125,7 @@ namespace WireMock.Owin.Mappers
|
|||||||
return responseMessage.FaultPercentage == null || _randomizerDouble.Generate() <= responseMessage.FaultPercentage;
|
return responseMessage.FaultPercentage == null || _randomizerDouble.Generate() <= responseMessage.FaultPercentage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<byte[]?> GetNormalBodyAsync(IResponseMessage responseMessage)
|
private byte[]? GetNormalBody(IResponseMessage responseMessage)
|
||||||
{
|
{
|
||||||
switch (responseMessage.BodyData?.DetectedBodyType)
|
switch (responseMessage.BodyData?.DetectedBodyType)
|
||||||
{
|
{
|
||||||
@@ -142,12 +138,6 @@ namespace WireMock.Owin.Mappers
|
|||||||
var jsonBody = JsonConvert.SerializeObject(responseMessage.BodyData.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
|
var jsonBody = JsonConvert.SerializeObject(responseMessage.BodyData.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
|
||||||
return (responseMessage.BodyData.Encoding ?? _utf8NoBom).GetBytes(jsonBody);
|
return (responseMessage.BodyData.Encoding ?? _utf8NoBom).GetBytes(jsonBody);
|
||||||
|
|
||||||
#if PROTOBUF
|
|
||||||
case BodyType.ProtoBuf:
|
|
||||||
var protoDefinition = responseMessage.BodyData.ProtoDefinition?.Invoke().Text;
|
|
||||||
return await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(protoDefinition, responseMessage.BodyData.ProtoBufMessageType, responseMessage.BodyData.BodyAsJson).ConfigureAwait(false);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
case BodyType.Bytes:
|
case BodyType.Bytes:
|
||||||
return responseMessage.BodyData.BodyAsBytes;
|
return responseMessage.BodyData.BodyAsBytes;
|
||||||
|
|
||||||
@@ -167,17 +157,16 @@ namespace WireMock.Owin.Mappers
|
|||||||
new[]
|
new[]
|
||||||
{
|
{
|
||||||
DateTime.UtcNow.ToString(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.InvariantCulture)
|
DateTime.UtcNow.ToString(CultureInfo.InvariantCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.InvariantCulture)
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Set other headers
|
// Set other headers
|
||||||
foreach (var item in responseMessage.Headers!)
|
foreach (var item in responseMessage.Headers!)
|
||||||
{
|
{
|
||||||
var headerName = item.Key;
|
var headerName = item.Key;
|
||||||
var value = item.Value;
|
var value = item.Value;
|
||||||
if (ResponseHeadersToFix.TryGetValue(headerName, out var action))
|
if (ResponseHeadersToFix.ContainsKey(headerName))
|
||||||
{
|
{
|
||||||
action?.Invoke(response, value);
|
ResponseHeadersToFix[headerName]?.Invoke(response, value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -190,34 +179,6 @@ namespace WireMock.Owin.Mappers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SetResponseTrailingHeaders(IResponseMessage responseMessage, IResponse response)
|
|
||||||
{
|
|
||||||
if (responseMessage.TrailingHeaders == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if TRAILINGHEADERS
|
|
||||||
foreach (var item in responseMessage.TrailingHeaders)
|
|
||||||
{
|
|
||||||
var headerName = item.Key;
|
|
||||||
var value = item.Value;
|
|
||||||
if (ResponseHeadersToFix.TryGetValue(headerName, out var action))
|
|
||||||
{
|
|
||||||
action?.Invoke(response, value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Check if this trailing header can be added to the response
|
|
||||||
if (response.SupportsTrailers() && !HttpKnownHeaderNames.IsRestrictedResponseHeader(headerName))
|
|
||||||
{
|
|
||||||
response.AppendTrailer(headerName, new Microsoft.Extensions.Primitives.StringValues(value.ToArray()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void AppendResponseHeader(IResponse response, string headerName, string[] values)
|
private static void AppendResponseHeader(IResponse response, string headerName, string[] values)
|
||||||
{
|
{
|
||||||
#if !USE_ASPNETCORE
|
#if !USE_ASPNETCORE
|
||||||
|
|||||||
56
src/WireMock.Net/Plugin/PluginLoader.cs
Normal file
56
src/WireMock.Net/Plugin/PluginLoader.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace WireMock.Plugin;
|
||||||
|
|
||||||
|
internal static class PluginLoader
|
||||||
|
{
|
||||||
|
private static readonly ConcurrentDictionary<Type, Type> Assemblies = new();
|
||||||
|
|
||||||
|
public static T Load<T>(params object[] args) where T : class
|
||||||
|
{
|
||||||
|
var foundType = Assemblies.GetOrAdd(typeof(T), (type) =>
|
||||||
|
{
|
||||||
|
var files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll");
|
||||||
|
|
||||||
|
Type? pluginType = null;
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var assembly = Assembly.Load(new AssemblyName
|
||||||
|
{
|
||||||
|
Name = Path.GetFileNameWithoutExtension(file)
|
||||||
|
});
|
||||||
|
|
||||||
|
pluginType = GetImplementationTypeByInterface<T>(assembly);
|
||||||
|
if (pluginType != null)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// no-op: just try next .dll
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pluginType != null)
|
||||||
|
{
|
||||||
|
return pluginType;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new DllNotFoundException($"No dll found which implements type '{type}'");
|
||||||
|
});
|
||||||
|
|
||||||
|
return (T)Activator.CreateInstance(foundType, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Type? GetImplementationTypeByInterface<T>(Assembly assembly)
|
||||||
|
{
|
||||||
|
return assembly.GetTypes().FirstOrDefault(t => typeof(T).IsAssignableFrom(t) && !t.GetTypeInfo().IsInterface);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ namespace WireMock.RequestBuilders;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The BodyRequestBuilder interface.
|
/// The BodyRequestBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IBodyRequestBuilder : IProtoBufRequestBuilder
|
public interface IBodyRequestBuilder : IGraphQLRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody: IMatcher
|
/// WithBody: IMatcher
|
||||||
@@ -51,13 +51,23 @@ public interface IBodyRequestBuilder : IProtoBufRequestBuilder
|
|||||||
IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBodyAsJson: A <see cref="JsonMatcher"/> will be used to match this object.
|
/// WithBody : Body as a string response based on a object (which will be converted to a JSON string using NewtonSoft.Json).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">The body.</param>
|
/// <param name="body">The body.</param>
|
||||||
/// <param name="matchBehaviour">The match behaviour [default is AcceptOnMatch].</param>
|
/// <param name="matchBehaviour">The match behaviour [default is AcceptOnMatch].</param>
|
||||||
/// <returns>A <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>A <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithBody : Body as a string response based on a object (which will be converted to a JSON string using the <see cref="IJsonConverter"/>).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="body">The body.</param>
|
||||||
|
/// <param name="converter">The JsonConverter.</param>
|
||||||
|
/// <param name="options">The <see cref="JsonConverterOptions"/> [optional].</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour [default is AcceptOnMatch].</param>
|
||||||
|
/// <returns>A <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithBodyAsJson(object body, IJsonConverter converter, JsonConverterOptions? options = null, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithBody: func (string)
|
/// WithBody: func (string)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -26,23 +26,6 @@ public interface IGraphQLRequestBuilder : IMultiPartRequestBuilder
|
|||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithGraphQLSchema(string schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithGraphQLSchema(string schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithBodyAsGraphQL: The GraphQL schema as a string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="schema">The GraphQL schema.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsGraphQL(string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithBodyAsGraphQL: The GraphQL schema as a string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="schema">The GraphQL schema.</param>
|
|
||||||
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsGraphQL(string schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
#if GRAPHQL
|
#if GRAPHQL
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithGraphQLSchema: The GraphQL schema as a ISchema.
|
/// WithGraphQLSchema: The GraphQL schema as a ISchema.
|
||||||
@@ -60,22 +43,5 @@ public interface IGraphQLRequestBuilder : IMultiPartRequestBuilder
|
|||||||
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithBodyAsGraphQL: The GraphQL schema as a ISchema.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="schema">The GraphQL schema.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithBodyAsGraphQL: The GraphQL schema as a ISchema.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="schema">The GraphQL schema.</param>
|
|
||||||
/// <param name="customScalars">A dictionary defining the custom scalars used in this schema. (optional)</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (Default is <c>MatchBehaviour.AcceptOnMatch</c>).</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, IDictionary<string, Type>? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
using WireMock.Matchers;
|
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The HttpVersionBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IHttpVersionBuilder : IRequestMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// WithHttpVersion
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="version">The HTTP Version to match.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithHttpVersion(string version, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@ namespace WireMock.RequestBuilders;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The MultiPartRequestBuilder interface.
|
/// The MultiPartRequestBuilder interface.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IMultiPartRequestBuilder : IHttpVersionBuilder
|
public interface IMultiPartRequestBuilder : IRequestMatcher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithMultiPart: IMatcher
|
/// WithMultiPart: IMatcher
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
using WireMock.Matchers;
|
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The ProtoBufRequestBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IProtoBufRequestBuilder : IGraphQLRequestBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// WithGrpcProto
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="protoDefinition">The proto definition as text.</param>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithGrpcProto
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="protoDefinition">The proto definition as text.</param>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matcher">The matcher to use to match the ProtoBuf as (json) object.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithGrpcProto
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsProtoBuf(string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WithGrpcProto
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="messageType">The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}".</param>
|
|
||||||
/// <param name="matcher">The matcher to use to match the ProtoBuf as (json) object.</param>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour. (default = "AcceptOnMatch")</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder WithBodyAsProtoBuf(string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
}
|
|
||||||
@@ -23,17 +23,17 @@ public partial class Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRequestBuilder WithClientIP(params string[] clientIPs)
|
public IRequestBuilder WithClientIP(params string[] paths)
|
||||||
{
|
{
|
||||||
return WithClientIP(MatchOperator.Or, clientIPs);
|
return WithClientIP(MatchOperator.Or, paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRequestBuilder WithClientIP(MatchOperator matchOperator, params string[] clientIPs)
|
public IRequestBuilder WithClientIP(MatchOperator matchOperator, params string[] paths)
|
||||||
{
|
{
|
||||||
Guard.NotNullOrEmpty(clientIPs);
|
Guard.NotNullOrEmpty(paths);
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, matchOperator, clientIPs));
|
_requestMatchers.Add(new RequestMessageClientIPMatcher(MatchBehaviour.AcceptOnMatch, matchOperator, paths));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
// 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;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using JsonConverter.Abstractions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Stef.Validation;
|
using Stef.Validation;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Matchers.Request;
|
using WireMock.Matchers.Request;
|
||||||
@@ -35,7 +37,19 @@ public partial class Request
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
public IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
return WithBody(new IMatcher[] { new JsonMatcher(matchBehaviour, body) });
|
var bodyAsJsonString = JsonConvert.SerializeObject(body);
|
||||||
|
_requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, bodyAsJsonString));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IRequestBuilder WithBodyAsJson(object body, IJsonConverter converter, JsonConverterOptions? options = null, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
Guard.NotNull(converter);
|
||||||
|
|
||||||
|
var bodyAsJsonString = converter.Serialize(body, options);
|
||||||
|
_requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, bodyAsJsonString));
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user