Compare commits

...

21 Commits

Author SHA1 Message Date
Stef Heyenrath
b367299643 1.5.60 2024-07-09 18:45:37 +02:00
rmeshksar
2179df7b44 Multipart Matcher Fix (#1132)
* Add unit tests for AdminApiMappingBuilder (#1131)

* Multipart Matcher Fix

---------

Co-authored-by: Stef Heyenrath <Stef.Heyenrath@gmail.com>
2024-07-09 18:42:07 +02:00
Stef Heyenrath
8788d9ba4a Add AdminPath to WireMockServerSettings (#1130)
* Make admin endpoint configurable

* Add AdminPath to WireMockServerSettings

* sealed

* foo

* WireMockServer_CreateClient_And_CallAdminSettingsEndpoint
2024-07-09 07:06:38 +02:00
Stef Heyenrath
d96ae9b063 Remove some files and folders (#1134) 2024-07-08 22:00:03 +02:00
Stef Heyenrath
ecb8e620ed Add unit tests for AdminApiMappingBuilder (#1133) 2024-07-08 21:41:05 +02:00
Stef Heyenrath
780c233ef3 Add Handlebars.Net.Helpers.Xslt (#1128) 2024-07-03 17:32:13 +02:00
Stef Heyenrath
4d83d82b91 1.5.59 2024-06-26 19:30:08 +02:00
Eric Dugas
bf28ba79b5 Made changes to accommodate breaking change in testcontainers-dotnet v3.9. (#1127)
Ref: https://github.com/testcontainers/testcontainers-dotnet/pull/1100
2024-06-26 19:26:27 +02:00
Stef Heyenrath
90e017b79a Use dotnet sonar scanner (part 2) (#1125)
* ddd

* ---ddd

* f

* revert

* /d:sonar.branch.name=$(Build.SourceBranchName)

* FIX

* coverlet

* coverlet - 1 line

* dotnet-coverage

* --configuration Debug --no-build --framework net8.0

* script

* /d:

* collect?

* "wiremock-coverage.xml"

* see

* tests
2024-06-20 15:35:37 +02:00
Stef Heyenrath
2602db566b Revert Sonar to old way (#1124) 2024-06-19 18:21:37 +02:00
Stef Heyenrath
61937db0b3 Fix SonarCloud integration (#1123)
* Use sonarscanner global dotnet tool

* io

* jdk?

* JAVA_HOME_17_X64

* /d:sonar.pullrequest.base=master

* /d:sonar.pullrequest.branch=$(Build.SourceBranch)

* /d:sonar.pullrequest.key=$(Build.BuildNumber)

* /d:sonar.pullrequest.branch=$(Build.SourceBranchName)

* ...

* $(System.PullRequest.PullRequestId)

* ---

* PR?

* cleanup
2024-06-19 17:07:52 +02:00
Stef Heyenrath
8a60950620 Fix link to ci.yml 2024-06-18 21:54:42 +02:00
Stef Heyenrath
90747462eb 1.5.58 2024-06-08 09:49:52 +02:00
Stef Heyenrath
8b03307a94 Add some methods to the BodyModelBuilder (#1116)
* Add some methods to the BodyModelBuilder

* .
2024-06-08 09:26:21 +02:00
Stef Heyenrath
86f8877039 Fix JsonMatcher if IgnoreCase and Regex are used 2024-06-08 09:11:22 +02:00
Stef Heyenrath
4538f6cd27 1.5.57 2024-06-04 14:31:01 +02:00
Stef Heyenrath
43746631e1 Add some Extension methods to IWireMockAdminApi (#1113) 2024-06-04 14:28:07 +02:00
Stef Heyenrath
8eda46ffc7 1.5.56 2024-06-03 11:01:46 +02:00
Stef Heyenrath
17f5ab5145 Add "/__admin/health" endpoint (#1112) 2024-06-03 10:59:44 +02:00
Stef Heyenrath
f76ea1d8ec Update Unit Test Response_ProvideResponse_Transformer_WithBodyAsFile_JsonPath 2024-05-25 09:31:39 +02:00
Stef Heyenrath
ea4ea95866 Fix Request.Create().WithBodyAsJson(...) (#1111)
* Fix Request.Create().WithBodyAsJson(...)

* [CodeFactor] Apply fixes

---------

Co-authored-by: codefactor-io <support@codefactor.io>
2024-05-25 09:09:03 +02:00
48 changed files with 952 additions and 20160 deletions

View File

@@ -1,4 +1,4 @@
name: Build with Tests
name: Run Tests
on:
pull_request:
@@ -10,47 +10,29 @@ on:
jobs:
windows-build-and-run:
name: Run Tests on Windows
runs-on: windows-2022
env:
IsRunningOnGitHubActions: 'true'
steps:
steps:
- 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'
run: |
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net8.0
linux-build-and-run:
name: Run Tests on Linux
runs-on: ubuntu-latest
env:
IsRunningOnGitHubActions: 'true'
steps:
steps:
- 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'
run: |
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net7.0
dotnet test './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj' -c Release --framework net8.0

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage"
uri="datacollector://Microsoft/CodeCoverage/2.0"
assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*Validation.*</ModulePath>
<ModulePath>.*\.tests.dll$</ModulePath>
<ModulePath>.*simmetrics.*</ModulePath>
</Exclude>
</ModulePaths>
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>

View File

@@ -1,14 +0,0 @@
{
"ServerUri": "https://sonarcloud.io",
"Organization": {
"Key": "stefh-github",
"Name": "Stef Heyenrath (Organization)"
},
"ProjectKey": "wiremock",
"Profiles": {
"CSharp": {
"ProfileKey": "AWRupN8iowGp6EI3lYmF",
"ProfileTimestamp": "2018-09-06T11:06:47+02:00"
}
}
}

View File

@@ -1,362 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="SonarQube - wiremock Sonar way" Description="This rule set was automatically generated from SonarQube.&#xD;&#xA;https://sonarcloud.io/profiles/show?key=AWRupN8iowGp6EI3lYmF" ToolsVersion="15.0">
<Rules AnalyzerId="SonarAnalyzer.CSharp" RuleNamespace="SonarAnalyzer.CSharp">
<Rule Id="S100" Action="None" />
<Rule Id="S1006" Action="Warning" />
<Rule Id="S101" Action="Warning" />
<Rule Id="S103" Action="None" />
<Rule Id="S104" Action="None" />
<Rule Id="S1048" Action="Warning" />
<Rule Id="S105" Action="None" />
<Rule Id="S106" Action="None" />
<Rule Id="S1066" Action="Warning" />
<Rule Id="S1067" Action="None" />
<Rule Id="S107" Action="Warning" />
<Rule Id="S1075" Action="Warning" />
<Rule Id="S108" Action="Warning" />
<Rule Id="S109" Action="None" />
<Rule Id="S110" Action="Warning" />
<Rule Id="S1104" Action="Warning" />
<Rule Id="S1109" Action="None" />
<Rule Id="S1110" Action="Warning" />
<Rule Id="S1116" Action="Warning" />
<Rule Id="S1117" Action="Warning" />
<Rule Id="S1118" Action="Warning" />
<Rule Id="S112" Action="Warning" />
<Rule Id="S1121" Action="Warning" />
<Rule Id="S1123" Action="Warning" />
<Rule Id="S1125" Action="Warning" />
<Rule Id="S113" Action="None" />
<Rule Id="S1134" Action="Warning" />
<Rule Id="S1135" Action="Warning" />
<Rule Id="S1144" Action="Warning" />
<Rule Id="S1145" Action="None" />
<Rule Id="S1147" Action="None" />
<Rule Id="S1151" Action="None" />
<Rule Id="S1155" Action="Warning" />
<Rule Id="S1163" Action="Warning" />
<Rule Id="S1168" Action="Warning" />
<Rule Id="S1172" Action="Warning" />
<Rule Id="S1185" Action="Warning" />
<Rule Id="S1186" Action="Warning" />
<Rule Id="S1192" Action="None" />
<Rule Id="S1200" Action="None" />
<Rule Id="S1206" Action="Warning" />
<Rule Id="S121" Action="None" />
<Rule Id="S1210" Action="Warning" />
<Rule Id="S1215" Action="Warning" />
<Rule Id="S122" Action="None" />
<Rule Id="S1226" Action="None" />
<Rule Id="S1227" Action="None" />
<Rule Id="S1244" Action="None" />
<Rule Id="S125" Action="Warning" />
<Rule Id="S126" Action="None" />
<Rule Id="S1264" Action="Warning" />
<Rule Id="S127" Action="None" />
<Rule Id="S1301" Action="None" />
<Rule Id="S1309" Action="None" />
<Rule Id="S131" Action="None" />
<Rule Id="S1313" Action="None" />
<Rule Id="S134" Action="None" />
<Rule Id="S138" Action="None" />
<Rule Id="S1449" Action="None" />
<Rule Id="S1450" Action="Warning" />
<Rule Id="S1451" Action="None" />
<Rule Id="S1479" Action="Warning" />
<Rule Id="S1481" Action="Warning" />
<Rule Id="S1541" Action="None" />
<Rule Id="S1607" Action="Warning" />
<Rule Id="S1643" Action="Warning" />
<Rule Id="S1656" Action="Warning" />
<Rule Id="S1659" Action="None" />
<Rule Id="S1694" Action="None" />
<Rule Id="S1696" Action="None" />
<Rule Id="S1697" Action="None" />
<Rule Id="S1698" Action="None" />
<Rule Id="S1699" Action="Warning" />
<Rule Id="S1751" Action="Warning" />
<Rule Id="S1764" Action="Warning" />
<Rule Id="S1821" Action="None" />
<Rule Id="S1848" Action="Warning" />
<Rule Id="S1854" Action="Warning" />
<Rule Id="S1858" Action="None" />
<Rule Id="S1862" Action="Warning" />
<Rule Id="S1871" Action="Warning" />
<Rule Id="S1905" Action="Warning" />
<Rule Id="S1939" Action="Warning" />
<Rule Id="S1940" Action="Warning" />
<Rule Id="S1944" Action="Warning" />
<Rule Id="S1994" Action="None" />
<Rule Id="S2068" Action="Warning" />
<Rule Id="S2070" Action="None" />
<Rule Id="S2092" Action="None" />
<Rule Id="S2114" Action="Warning" />
<Rule Id="S2123" Action="Warning" />
<Rule Id="S2148" Action="None" />
<Rule Id="S2156" Action="None" />
<Rule Id="S2178" Action="Warning" />
<Rule Id="S2183" Action="Warning" />
<Rule Id="S2184" Action="Warning" />
<Rule Id="S2187" Action="Warning" />
<Rule Id="S2190" Action="Warning" />
<Rule Id="S2197" Action="None" />
<Rule Id="S2201" Action="Warning" />
<Rule Id="S2219" Action="Warning" />
<Rule Id="S2221" Action="None" />
<Rule Id="S2223" Action="Warning" />
<Rule Id="S2225" Action="Warning" />
<Rule Id="S2228" Action="None" />
<Rule Id="S2234" Action="Warning" />
<Rule Id="S2245" Action="Warning" />
<Rule Id="S2255" Action="Warning" />
<Rule Id="S2259" Action="Warning" />
<Rule Id="S2275" Action="Warning" />
<Rule Id="S2278" Action="Warning" />
<Rule Id="S2290" Action="Warning" />
<Rule Id="S2291" Action="Warning" />
<Rule Id="S2292" Action="Warning" />
<Rule Id="S2302" Action="None" />
<Rule Id="S2306" Action="Warning" />
<Rule Id="S2325" Action="None" />
<Rule Id="S2326" Action="Warning" />
<Rule Id="S2327" Action="Warning" />
<Rule Id="S2328" Action="Warning" />
<Rule Id="S2330" Action="None" />
<Rule Id="S2333" Action="None" />
<Rule Id="S2339" Action="None" />
<Rule Id="S2342" Action="Warning" />
<Rule Id="S2344" Action="Warning" />
<Rule Id="S2345" Action="Warning" />
<Rule Id="S2346" Action="Warning" />
<Rule Id="S2357" Action="None" />
<Rule Id="S2360" Action="None" />
<Rule Id="S2365" Action="Warning" />
<Rule Id="S2368" Action="Warning" />
<Rule Id="S2372" Action="Warning" />
<Rule Id="S2376" Action="Warning" />
<Rule Id="S2386" Action="Warning" />
<Rule Id="S2387" Action="None" />
<Rule Id="S2436" Action="Warning" />
<Rule Id="S2437" Action="Warning" />
<Rule Id="S2486" Action="Warning" />
<Rule Id="S2551" Action="Warning" />
<Rule Id="S2583" Action="Warning" />
<Rule Id="S2589" Action="Warning" />
<Rule Id="S2674" Action="None" />
<Rule Id="S2681" Action="Warning" />
<Rule Id="S2688" Action="Warning" />
<Rule Id="S2692" Action="Warning" />
<Rule Id="S2696" Action="Warning" />
<Rule Id="S2699" Action="None" />
<Rule Id="S2701" Action="None" />
<Rule Id="S2737" Action="Warning" />
<Rule Id="S2743" Action="Warning" />
<Rule Id="S2757" Action="Warning" />
<Rule Id="S2758" Action="Warning" />
<Rule Id="S2760" Action="None" />
<Rule Id="S2761" Action="Warning" />
<Rule Id="S2930" Action="Warning" />
<Rule Id="S2931" Action="None" />
<Rule Id="S2933" Action="Warning" />
<Rule Id="S2934" Action="Warning" />
<Rule Id="S2952" Action="None" />
<Rule Id="S2953" Action="Warning" />
<Rule Id="S2955" Action="None" />
<Rule Id="S2971" Action="Warning" />
<Rule Id="S2995" Action="Warning" />
<Rule Id="S2996" Action="Warning" />
<Rule Id="S2997" Action="Warning" />
<Rule Id="S3005" Action="Warning" />
<Rule Id="S3010" Action="Warning" />
<Rule Id="S3052" Action="None" />
<Rule Id="S3060" Action="Warning" />
<Rule Id="S3168" Action="Warning" />
<Rule Id="S3169" Action="Warning" />
<Rule Id="S3172" Action="Warning" />
<Rule Id="S3215" Action="None" />
<Rule Id="S3216" Action="None" />
<Rule Id="S3217" Action="Warning" />
<Rule Id="S3218" Action="Warning" />
<Rule Id="S3220" Action="Warning" />
<Rule Id="S3234" Action="None" />
<Rule Id="S3235" Action="None" />
<Rule Id="S3236" Action="Warning" />
<Rule Id="S3237" Action="Warning" />
<Rule Id="S3240" Action="None" />
<Rule Id="S3241" Action="Warning" />
<Rule Id="S3242" Action="None" />
<Rule Id="S3244" Action="Warning" />
<Rule Id="S3246" Action="Warning" />
<Rule Id="S3247" Action="Warning" />
<Rule Id="S3249" Action="Warning" />
<Rule Id="S3251" Action="Warning" />
<Rule Id="S3253" Action="None" />
<Rule Id="S3254" Action="None" />
<Rule Id="S3256" Action="Warning" />
<Rule Id="S3257" Action="None" />
<Rule Id="S3261" Action="Warning" />
<Rule Id="S3262" Action="Warning" />
<Rule Id="S3263" Action="Warning" />
<Rule Id="S3264" Action="Warning" />
<Rule Id="S3265" Action="Warning" />
<Rule Id="S3330" Action="None" />
<Rule Id="S3343" Action="Warning" />
<Rule Id="S3346" Action="Warning" />
<Rule Id="S3353" Action="None" />
<Rule Id="S3358" Action="Warning" />
<Rule Id="S3366" Action="None" />
<Rule Id="S3376" Action="Warning" />
<Rule Id="S3397" Action="Warning" />
<Rule Id="S3400" Action="Warning" />
<Rule Id="S3415" Action="Warning" />
<Rule Id="S3427" Action="Warning" />
<Rule Id="S3431" Action="None" />
<Rule Id="S3433" Action="Warning" />
<Rule Id="S3440" Action="Warning" />
<Rule Id="S3441" Action="None" />
<Rule Id="S3442" Action="Warning" />
<Rule Id="S3443" Action="Warning" />
<Rule Id="S3444" Action="Warning" />
<Rule Id="S3445" Action="Warning" />
<Rule Id="S3447" Action="Warning" />
<Rule Id="S3449" Action="Warning" />
<Rule Id="S3450" Action="Warning" />
<Rule Id="S3451" Action="Warning" />
<Rule Id="S3453" Action="Warning" />
<Rule Id="S3456" Action="Warning" />
<Rule Id="S3457" Action="Warning" />
<Rule Id="S3458" Action="Warning" />
<Rule Id="S3459" Action="Warning" />
<Rule Id="S3464" Action="Warning" />
<Rule Id="S3466" Action="Warning" />
<Rule Id="S3532" Action="None" />
<Rule Id="S3597" Action="Warning" />
<Rule Id="S3598" Action="Warning" />
<Rule Id="S3600" Action="Warning" />
<Rule Id="S3603" Action="Warning" />
<Rule Id="S3604" Action="Warning" />
<Rule Id="S3610" Action="Warning" />
<Rule Id="S3626" Action="Warning" />
<Rule Id="S3655" Action="Warning" />
<Rule Id="S3693" Action="Warning" />
<Rule Id="S3717" Action="None" />
<Rule Id="S3776" Action="Warning" />
<Rule Id="S3869" Action="Warning" />
<Rule Id="S3871" Action="Warning" />
<Rule Id="S3872" Action="None" />
<Rule Id="S3874" Action="None" />
<Rule Id="S3875" Action="Warning" />
<Rule Id="S3876" Action="None" />
<Rule Id="S3877" Action="Warning" />
<Rule Id="S3880" Action="None" />
<Rule Id="S3881" Action="Warning" />
<Rule Id="S3884" Action="Warning" />
<Rule Id="S3885" Action="Warning" />
<Rule Id="S3887" Action="Warning" />
<Rule Id="S3889" Action="Warning" />
<Rule Id="S3897" Action="Warning" />
<Rule Id="S3898" Action="None" />
<Rule Id="S3900" Action="None" />
<Rule Id="S3902" Action="None" />
<Rule Id="S3903" Action="Warning" />
<Rule Id="S3904" Action="Warning" />
<Rule Id="S3906" Action="None" />
<Rule Id="S3908" Action="None" />
<Rule Id="S3909" Action="None" />
<Rule Id="S3923" Action="Warning" />
<Rule Id="S3925" Action="Warning" />
<Rule Id="S3926" Action="Warning" />
<Rule Id="S3927" Action="Warning" />
<Rule Id="S3928" Action="Warning" />
<Rule Id="S3937" Action="None" />
<Rule Id="S3956" Action="None" />
<Rule Id="S3962" Action="None" />
<Rule Id="S3963" Action="Warning" />
<Rule Id="S3966" Action="Warning" />
<Rule Id="S3967" Action="None" />
<Rule Id="S3971" Action="Warning" />
<Rule Id="S3972" Action="Warning" />
<Rule Id="S3973" Action="Warning" />
<Rule Id="S3981" Action="Warning" />
<Rule Id="S3984" Action="Warning" />
<Rule Id="S3990" Action="None" />
<Rule Id="S3992" Action="None" />
<Rule Id="S3993" Action="None" />
<Rule Id="S3994" Action="None" />
<Rule Id="S3995" Action="None" />
<Rule Id="S3996" Action="None" />
<Rule Id="S3997" Action="None" />
<Rule Id="S3998" Action="Warning" />
<Rule Id="S4000" Action="None" />
<Rule Id="S4002" Action="None" />
<Rule Id="S4004" Action="None" />
<Rule Id="S4005" Action="None" />
<Rule Id="S4015" Action="Warning" />
<Rule Id="S4016" Action="Warning" />
<Rule Id="S4017" Action="None" />
<Rule Id="S4018" Action="None" />
<Rule Id="S4019" Action="Warning" />
<Rule Id="S4022" Action="None" />
<Rule Id="S4023" Action="None" />
<Rule Id="S4025" Action="None" />
<Rule Id="S4026" Action="None" />
<Rule Id="S4027" Action="None" />
<Rule Id="S4035" Action="Warning" />
<Rule Id="S4039" Action="None" />
<Rule Id="S4040" Action="None" />
<Rule Id="S4041" Action="None" />
<Rule Id="S4047" Action="None" />
<Rule Id="S4049" Action="None" />
<Rule Id="S4050" Action="None" />
<Rule Id="S4052" Action="None" />
<Rule Id="S4055" Action="None" />
<Rule Id="S4056" Action="None" />
<Rule Id="S4057" Action="None" />
<Rule Id="S4058" Action="None" />
<Rule Id="S4059" Action="None" />
<Rule Id="S4060" Action="None" />
<Rule Id="S4061" Action="Warning" />
<Rule Id="S4069" Action="None" />
<Rule Id="S4070" Action="None" />
<Rule Id="S4142" Action="None" />
<Rule Id="S4143" Action="Warning" />
<Rule Id="S4144" Action="Warning" />
<Rule Id="S4158" Action="Warning" />
<Rule Id="S4159" Action="Warning" />
<Rule Id="S4200" Action="Warning" />
<Rule Id="S4210" Action="Warning" />
<Rule Id="S4211" Action="Warning" />
<Rule Id="S4212" Action="None" />
<Rule Id="S4214" Action="Warning" />
<Rule Id="S4220" Action="Warning" />
<Rule Id="S4225" Action="None" />
<Rule Id="S4226" Action="None" />
<Rule Id="S4260" Action="Warning" />
<Rule Id="S4261" Action="None" />
<Rule Id="S4275" Action="Warning" />
<Rule Id="S4277" Action="Warning" />
<Rule Id="S4426" Action="Warning" />
<Rule Id="S4428" Action="Warning" />
<Rule Id="S4432" Action="None" />
<Rule Id="S4433" Action="Warning" />
<Rule Id="S4456" Action="Warning" />
<Rule Id="S4457" Action="Warning" />
<Rule Id="S4462" Action="None" />
<Rule Id="S4524" Action="Warning" />
<Rule Id="S4564" Action="None" />
<Rule Id="S4581" Action="Warning" />
<Rule Id="S4586" Action="Warning" />
<Rule Id="S818" Action="Warning" />
<Rule Id="S881" Action="None" />
<Rule Id="S907" Action="Warning" />
<Rule Id="S927" Action="Warning" />
</Rules>
<Rules AnalyzerId="SonarAnalyzer.Security" RuleNamespace="SonarAnalyzer.Security">
<Rule Id="S2076" Action="Warning" />
<Rule Id="S2078" Action="Warning" />
<Rule Id="S2083" Action="Warning" />
<Rule Id="S2091" Action="Warning" />
<Rule Id="S2631" Action="Warning" />
<Rule Id="S3649" Action="Warning" />
</Rules>
</RuleSet>

View File

@@ -1,3 +1,28 @@
# 1.5.60 (09 July 2024)
- [#1128](https://github.com/WireMock-Net/WireMock.Net/pull/1128) - Add Handlebars.Net.Helpers.Xslt [feature] contributed by [StefH](https://github.com/StefH)
- [#1130](https://github.com/WireMock-Net/WireMock.Net/pull/1130) - Add AdminPath to WireMockServerSettings [feature] contributed by [StefH](https://github.com/StefH)
- [#1131](https://github.com/WireMock-Net/WireMock.Net/pull/1131) - Add unit tests for AdminApiMappingBuilder [test] contributed by [StefH](https://github.com/StefH)
- [#1132](https://github.com/WireMock-Net/WireMock.Net/pull/1132) - Multipart Matcher Fix [bug] contributed by [rmeshksar](https://github.com/rmeshksar)
- [#1133](https://github.com/WireMock-Net/WireMock.Net/pull/1133) - Add unit tests for AdminApiMappingBuilder_ [test] contributed by [StefH](https://github.com/StefH)
- [#1134](https://github.com/WireMock-Net/WireMock.Net/pull/1134) - Remove some files and folders [refactor] contributed by [StefH](https://github.com/StefH)
- [#1119](https://github.com/WireMock-Net/WireMock.Net/issues/1119) - Error in RequestMessageMultiPartMatcher [bug]
- [#1121](https://github.com/WireMock-Net/WireMock.Net/issues/1121) - XML transformation [feature]
# 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 &quot;/__admin/health&quot; 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)

View File

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

View File

@@ -1,7 +1,7 @@
rem https://github.com/StefH/GitHubReleaseNotes
SET version=1.5.55
SET version=1.5.60
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example --version %version% --token %GH_TOKEN%
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --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%
GitHubReleaseNotes --output PackageReleaseNotes.txt --skip-empty-releases --exclude-labels question invalid doc duplicate example environment --template PackageReleaseNotes.template --version %version% --token %GH_TOKEN%

View File

@@ -1,4 +1,11 @@
# 1.5.55 (22 May 2024)
- #1107 When only Port is provided, bind to * (Fixes #1100) [bug]
# 1.5.60 (09 July 2024)
- #1128 Add Handlebars.Net.Helpers.Xslt [feature]
- #1130 Add AdminPath to WireMockServerSettings [feature]
- #1131 Add unit tests for AdminApiMappingBuilder [test]
- #1132 Multipart Matcher Fix [bug]
- #1133 Add unit tests for AdminApiMappingBuilder_ [test]
- #1134 Remove some files and folders [refactor]
- #1119 Error in RequestMessageMultiPartMatcher [bug]
- #1121 XML transformation [feature]
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md

View File

@@ -27,7 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
.github\FUNDING.yml = .github\FUNDING.yml
Generate-ReleaseNotes.cmd = Generate-ReleaseNotes.cmd
nuget.config = nuget.config
PackageReadme.md = PackageReadme.md
PackageReleaseNotes.template = PackageReleaseNotes.template
PackageReleaseNotes.txt = PackageReleaseNotes.txt
@@ -70,7 +69,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Net472
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{1DAEFF47-D117-4E95-8B3E-4F7C8B92011A}"
ProjectSection(SolutionItems) = preProject
..\System.Linq.Dynamic.Core\.github\workflows\ci.yml = ..\System.Linq.Dynamic.Core\.github\workflows\ci.yml
.github\workflows\ci.yml = .github\workflows\ci.yml
.github\workflows\CreateRelease.yml = .github\workflows\CreateRelease.yml
EndProjectSection
EndProject
@@ -106,7 +105,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{0147029F
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultipartUploader", "tools\MultipartUploader\MultipartUploader.csproj", "{07C30227-ADEC-4BDE-8CDC-849D85A690BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET7.UsingNuGet", "examples\WireMock.Net.Console.NET7.UsingNuGet\WireMock.Net.Console.NET7.UsingNuGet.csproj", "{941229D6-191B-4B5E-AC81-0905EBF4F19D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NET7.UsingNuGet", "examples\WireMock.Net.Console.NET7.UsingNuGet\WireMock.Net.Console.NET7.UsingNuGet.csproj", "{941229D6-191B-4B5E-AC81-0905EBF4F19D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NET8", "examples\WireMock.Net.Console.NET8\WireMock.Net.Console.NET8.csproj", "{1EA72C0F-92E9-486B-8FFE-53F992BFC4AA}"
EndProject

View File

@@ -1,21 +0,0 @@
pool:
vmImage: 'Ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 8'
inputs:
packageType: sdk
version: 8.0.x
- script: |
dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --configuration $(buildConfiguration) --framework net8.0 --logger trx
displayName: 'Test'
- task: PublishTestResults@2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'

View File

@@ -14,53 +14,45 @@ jobs:
echo "BuildId = $(buildId)"
displayName: 'Print buildId'
- task: UseDotNet@2
displayName: Use .NET 8.0
inputs:
packageType: 'sdk'
version: '8.0.x'
- script: |
dotnet tool install --global dotnet-sonarscanner
dotnet tool install --global dotnet-coverage
dotnet tool install --global coverlet.console
displayName: 'Install dotnet tools'
- task: PowerShell@2
displayName: "Use JDK11 by default"
displayName: "Use JDK17 by default"
inputs:
targetType: 'inline'
script: |
$jdkPath = $env:JAVA_HOME_11_X64
$jdkPath = $env:JAVA_HOME_17_X64
Write-Host "##vso[task.setvariable variable=JAVA_HOME]$jdkPath"
- script: |
dotnet dev-certs https --trust || true
displayName: 'dotnet dev-certs https'
- task: SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
# See: https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/dotnet-test-coverage
- script: |
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
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
displayName: 'Build Unit tests'
inputs:
command: 'build'
projects: './test/WireMock.Net.Tests/WireMock.Net.Tests.csproj'
arguments: '--configuration Debug --framework net8.0'
arguments: '--configuration Debug --framework net8.0 --no-incremental'
- task: CmdLine@2
inputs:
script: 'dotnet test ./test/WireMock.Net.Tests/WireMock.Net.Tests.csproj --no-build --configuration Debug --framework net8.0'
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"'
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
- task: SonarCloudPublish@1
displayName: 'SonarCloud: Publish Quality Gate Result'
- script: |
dotnet sonarscanner end /d:sonar.token="$(SONAR_TOKEN)"
displayName: 'End analysis on SonarCloud'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest')) # Do not run for PullRequests
- task: whitesource.ws-bolt.bolt.wss.WhiteSource Bolt@19

View File

@@ -1,29 +0,0 @@
trigger:
- none
pool:
vmImage: 'Ubuntu-latest'
variables:
buildProjects: '**/src/**/*.csproj'
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Use .NET 8'
inputs:
packageType: sdk
version: 8.0.x
- task: DotNetCoreCLI@2
displayName: Build Release
inputs:
command: 'build'
arguments: /p:Configuration=$(buildConfiguration)
projects: $(buildProjects)
- task: PublishBuildArtifacts@1
displayName: Publish Artifacts
condition: succeeded()
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'

View File

@@ -14,10 +14,13 @@ class Program
{
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.
var api = RestClient.For<IWireMockAdminApi>("http://localhost:9091");
// await api.ResetMappingsAsync().ConfigureAwait(false);
await api.ResetMappingsAsync().ConfigureAwait(false);
var mappingBuilder = api.GetMappingBuilder();
mappingBuilder.Given(m => m
@@ -51,13 +54,32 @@ class Program
.WithPath("/bla3")
)
.WithResponse(rsp => rsp
.WithBodyAsJson(new
.WithBodyAsJson(new
{
x = "test"
}, 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);
Console.WriteLine($"result = {JsonConvert.SerializeObject(result)}");
@@ -112,6 +134,9 @@ class Program
var getFileResult = await api.GetFileAsync("1.cs");
Console.WriteLine($"getFileResult = {getFileResult}");
Console.WriteLine("Press any key to reset mappings");
Console.ReadKey();
var resetMappingsAsync = await api.ResetMappingsAsync();
Console.WriteLine($"resetMappingsAsync = {resetMappingsAsync.Status}");

View File

@@ -1,8 +0,0 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
}
}
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ApplicationIcon>../../resources/WireMock.Net-Logo.ico</ApplicationIcon>
</PropertyGroup>

View File

@@ -97,34 +97,30 @@ message HelloReply {
private static void RunOnLocal()
{
var localIP = Dns.GetHostEntry(Dns.GetHostName()).AddressList.First(a => a.AddressFamily == AddressFamily.InterNetwork);
//try
//{
// var server = WireMockServer.Start(new WireMockServerSettings
// {
// Urls = new[] { $"http://{localIP}:9091" },
// StartAdminInterface = true
// });
// System.Console.WriteLine($"1: {string.Join(", ", server.Urls)}");
// System.Console.WriteLine("Press any key to stop...");
// System.Console.ReadKey();
// server.Stop();
//}
//catch (Exception e)
//{
// System.Console.WriteLine(e);
//}
try
{
var server = WireMockServer.Start(new WireMockServerSettings
{
Port = 9091,
StartAdminInterface = true
StartAdminInterface = true,
Logger = new WireMockConsoleLogger()
});
System.Console.WriteLine($"2: {string.Join(", ", server.Urls)}");
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();
@@ -134,24 +130,6 @@ message HelloReply {
{
System.Console.WriteLine(e);
}
//try
//{
// var server = WireMockServer.Start(new WireMockServerSettings
// {
// Urls = new[] { "http://*:9091" },
// StartAdminInterface = true
// });
// System.Console.WriteLine($"3: {string.Join(", ", server.Urls)}");
// System.Console.WriteLine("Press any key to stop...");
// System.Console.ReadKey();
// server.Stop();
//}
//catch (Exception e)
//{
// System.Console.WriteLine(e);
//}
}
public static void Run()
@@ -251,7 +229,9 @@ message HelloReply {
server.SetBasicAuthentication("a", "b");
//server.SetAzureADAuthentication("6c2a4722-f3b9-4970-b8fc-fac41e29stef", "8587fde1-7824-42c7-8592-faf92b04stef");
// server.AllowPartialMapping();
//var http = new HttpClient();
//var response = await http.GetAsync($"{_wireMockServer.Url}/pricing");
//var value = await response.Content.ReadAsStringAsync();
#if PROTOBUF
var protoBufJsonMatcher = new JsonPartialWildcardMatcher(new { name = "*" });
@@ -395,7 +375,6 @@ message HelloReply {
.WithHeader("Content-Type", "text/plain")
);
server
.Given(Request.Create()
.UsingMethod("GET")

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +0,0 @@
dotnet test ..\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj -c Debug -f netcoreapp2.1 /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover,lcov\" /p:CoverletOutput="../../report/"
%USERPROFILE%\.nuget\packages\ReportGenerator\3.1.2\tools\ReportGenerator.exe -reports:"coverage.opencover.xml" -targetdir:"coverlet"
start coverlet\index.htm

View File

@@ -0,0 +1,130 @@
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)
);
}
}

View File

@@ -1,3 +1,9 @@
using System;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Stef.Validation;
using WireMock.Client.Builders;
namespace WireMock.Client.Extensions;
@@ -7,13 +13,77 @@ namespace WireMock.Client.Extensions;
/// </summary>
public static class WireMockAdminApiExtensions
{
private const int MaxRetries = 5;
private const int InitialWaitingTimeInMilliSeconds = 500;
private const string HealthStatusHealthy = "Healthy";
/// <summary>
/// Get a new <see cref="AdminApiMappingBuilder"/> for the <see cref="IWireMockAdminApi"/>.
/// </summary>
/// <param name="api">See <see cref="IWireMockAdminApi"/>.</param>
/// <param name="adminApi">See <see cref="IWireMockAdminApi"/>.</param>
/// <returns></returns>
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi api)
public static AdminApiMappingBuilder GetMappingBuilder(this IWireMockAdminApi adminApi)
{
return new AdminApiMappingBuilder(api);
return new AdminApiMappingBuilder(adminApi);
}
/// <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;
}
}
}

View File

@@ -24,12 +24,24 @@ public interface IWireMockAdminApi
[Header("Authorization")]
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>
/// Get the settings.
/// </summary>
/// <returns>SettingsModel</returns>
[Get("settings")]
Task<SettingsModel> GetSettingsAsync();
Task<SettingsModel> GetSettingsAsync(CancellationToken cancellationToken = default);
/// <summary>
/// Update the settings.

View File

@@ -29,7 +29,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Stef.Validation" Version="0.1.1" />
<PackageReference Include="Testcontainers" Version="[3.7.0]" />
<PackageReference Include="Testcontainers" Version="[3.9.0]" />
<PackageReference Include="JetBrains.Annotations" VersionOverride="2022.3.1" PrivateAssets="All" Version="2023.3.0" />
</ItemGroup>

View File

@@ -4,10 +4,10 @@ using System.Net.Http.Headers;
using System.Text;
using DotNet.Testcontainers.Containers;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using RestEase;
using Stef.Validation;
using WireMock.Client;
using WireMock.Client.Extensions;
using WireMock.Http;
namespace WireMock.Net.Testcontainers;
@@ -25,8 +25,7 @@ public sealed class WireMockContainer : DockerContainer
/// Initializes a new instance of the <see cref="WireMockContainer" /> class.
/// </summary>
/// <param name="configuration">The container configuration.</param>
/// <param name="logger">The logger.</param>
public WireMockContainer(WireMockConfiguration configuration, ILogger logger) : base(configuration, logger)
public WireMockContainer(WireMockConfiguration configuration) : base(configuration)
{
_configuration = Guard.NotNull(configuration);
}
@@ -47,13 +46,7 @@ public sealed class WireMockContainer : DockerContainer
ValidateIfRunning();
var api = RestClient.For<IWireMockAdminApi>(GetPublicUri());
if (_configuration.HasBasicAuthentication)
{
api.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes($"{_configuration.Username}:{_configuration.Password}")));
}
return api;
return _configuration.HasBasicAuthentication ? api.WithAuthorization(_configuration.Username!, _configuration.Password!) : api;
}
/// <summary>

View File

@@ -138,7 +138,7 @@ public sealed class WireMockContainerBuilder : ContainerBuilder<WireMockContaine
{
Validate();
return new WireMockContainer(DockerResourceConfiguration, TestcontainersSettings.Logger);
return new WireMockContainer(DockerResourceConfiguration);
}
/// <inheritdoc />

View File

@@ -31,7 +31,6 @@ public class JsonMatcher : IJsonMatcher
public bool Regex { get; }
private readonly JToken _valueAsJToken;
private readonly Func<JToken, JToken> _jTokenConverter;
/// <summary>
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
@@ -70,7 +69,6 @@ public class JsonMatcher : IJsonMatcher
Value = value;
_valueAsJToken = JsonUtils.ConvertValueToJToken(value);
_jTokenConverter = ignoreCase ? Rename : jToken => jToken;
}
/// <inheritdoc />
@@ -86,7 +84,7 @@ public class JsonMatcher : IJsonMatcher
{
var inputAsJToken = JsonUtils.ConvertValueToJToken(input);
var match = IsMatch(_jTokenConverter(_valueAsJToken), _jTokenConverter(inputAsJToken));
var match = IsMatch(RenameJToken(_valueAsJToken), RenameJToken(inputAsJToken));
score = MatchScores.ToScore(match);
}
catch (Exception ex)
@@ -179,38 +177,59 @@ public class JsonMatcher : IJsonMatcher
}
}
// 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)
{
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;
}
}

View File

@@ -71,23 +71,21 @@ public class RequestMessageMultiPartMatcher : IRequestMatcher
{
var mimePartMatchers = Matchers.OfType<MimePartMatcher>().ToArray();
foreach (var mimePart in message.BodyParts.OfType<MimeKit.MimePart>())
foreach (var mimePartMatcher in Matchers.OfType<MimePartMatcher>().ToArray())
{
var matchesForMimePart = new List<MatchResult> { default };
matchesForMimePart.AddRange(mimePartMatchers.Select(matcher => matcher.IsMatch(mimePart)));
score = matchesForMimePart.Select(m => m.Score).Max();
if (MatchScores.IsPerfect(score))
score = MatchScores.Mismatch;
foreach (var mimeBodyPart in message.BodyParts.OfType<MimeKit.MimePart>())
{
if (MatchOperator == MatchOperator.Or)
var matchResult = mimePartMatcher.IsMatch(mimeBodyPart);
if (matchResult.IsPerfect())
{
score = MatchScores.Perfect;
break;
}
}
else
if ((MatchOperator == MatchOperator.Or && MatchScores.IsPerfect(score))
|| (MatchOperator == MatchOperator.And && !MatchScores.IsPerfect(score)))
{
score = MatchScores.Mismatch;
break;
}
}

View File

@@ -51,23 +51,13 @@ public interface IBodyRequestBuilder : IProtoBufRequestBuilder
IRequestBuilder WithBody(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 NewtonSoft.Json).
/// WithBodyAsJson: A <see cref="JsonMatcher"/> will be used to match this object.
/// </summary>
/// <param name="body">The body.</param>
/// <param name="matchBehaviour">The match behaviour [default is AcceptOnMatch].</param>
/// <returns>A <see cref="IRequestBuilder"/>.</returns>
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>
/// WithBody: func (string)
/// </summary>

View File

@@ -2,8 +2,6 @@
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
using System;
using System.Collections.Generic;
using JsonConverter.Abstractions;
using Newtonsoft.Json;
using Stef.Validation;
using WireMock.Matchers;
using WireMock.Matchers.Request;
@@ -37,19 +35,7 @@ public partial class Request
/// <inheritdoc />
public IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
{
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;
return WithBody(new IMatcher[] { new JsonMatcher(matchBehaviour, body) });
}
/// <inheritdoc />

View File

@@ -19,6 +19,7 @@ using WireMock.Matchers.Request;
using WireMock.RequestBuilders;
using WireMock.ResponseProviders;
using WireMock.Serialization;
using WireMock.Settings;
using WireMock.Types;
using WireMock.Util;
@@ -30,96 +31,116 @@ namespace WireMock.Server;
public partial class WireMockServer
{
private const int EnhancedFileSystemWatcherTimeoutMs = 1000;
private const string AdminFiles = "/__admin/files";
private const string AdminMappings = "/__admin/mappings";
private const string AdminMappingsCode = "/__admin/mappings/code";
private const string AdminMappingsWireMockOrg = "/__admin/mappings/wiremock.org";
private const string AdminRequests = "/__admin/requests";
private const string AdminSettings = "/__admin/settings";
private const string AdminScenarios = "/__admin/scenarios";
private const string AdminOpenApi = "/__admin/openapi";
private const string DefaultAdminPathPrefix = "/__admin";
private const string QueryParamReloadStaticMappings = "reloadStaticMappings";
private static readonly Guid ProxyMappingGuid = new("e59914fd-782e-428e-91c1-4810ffb86567");
private static readonly RegexMatcher AdminRequestContentTypeJson = new ContentTypeMatcher(WireMockConstants.ContentTypeJson, true);
private static readonly RegexMatcher AdminMappingsGuidPathMatcher = new(@"^\/__admin\/mappings\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
private static readonly RegexMatcher AdminMappingsCodeGuidPathMatcher = new(@"^\/__admin\/mappings\/code\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
private static readonly RegexMatcher AdminRequestsGuidPathMatcher = new(@"^\/__admin\/requests\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})$");
private static readonly RegexMatcher AdminScenariosNameMatcher = new(@"^\/__admin\/scenarios\/.+$");
private static readonly RegexMatcher AdminScenariosNameWithResetMatcher = new(@"^\/__admin\/scenarios\/.+\/reset$");
private EnhancedFileSystemWatcher? _enhancedFileSystemWatcher;
private AdminPaths? _adminPaths;
private sealed class AdminPaths
{
private readonly string _prefix;
private readonly string _prefixEscaped;
public AdminPaths(WireMockServerSettings settings)
{
_prefix = settings.AdminPath ?? DefaultAdminPathPrefix;
_prefixEscaped = _prefix.Replace("/", "\\/");
}
public string Files => $"{_prefix}/files";
public string Health => $"{_prefix}/health";
public string Mappings => $"{_prefix}/mappings";
public string MappingsCode => $"{_prefix}/mappings/code";
public string MappingsWireMockOrg => $"{_prefix}mappings/wiremock.org";
public string Requests => $"{_prefix}/requests";
public string Settings => $"{_prefix}/settings";
public string Scenarios => $"{_prefix}/scenarios";
public string OpenApi => $"{_prefix}/openapi";
public RegexMatcher MappingsGuidPathMatcher => new($"^{_prefixEscaped}\\/mappings\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
public RegexMatcher MappingsCodeGuidPathMatcher => new($"^{_prefixEscaped}\\/mappings\\/code\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
public RegexMatcher RequestsGuidPathMatcher => new($"^{_prefixEscaped}\\/requests\\/([0-9A-Fa-f]{{8}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{4}}[-][0-9A-Fa-f]{{12}})$");
public RegexMatcher ScenariosNameMatcher => new($"^{_prefixEscaped}\\/scenarios\\/.+$");
public RegexMatcher ScenariosNameWithResetMatcher => new($"^{_prefixEscaped}\\/scenarios\\/.+\\/reset$");
public RegexMatcher FilesFilenamePathMatcher => new($"^{_prefixEscaped}\\/files\\/.+$");
}
#region InitAdmin
private void InitAdmin()
{
_adminPaths = new AdminPaths(_settings);
// __admin/health
Given(Request.Create().WithPath(_adminPaths.Health).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(HealthGet));
// __admin/settings
Given(Request.Create().WithPath(AdminSettings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsGet));
Given(Request.Create().WithPath(AdminSettings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsUpdate));
Given(Request.Create().WithPath(_adminPaths.Settings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsGet));
Given(Request.Create().WithPath(_adminPaths.Settings).UsingMethod("PUT", "POST").WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SettingsUpdate));
// __admin/mappings
Given(Request.Create().WithPath(AdminMappings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsGet));
Given(Request.Create().WithPath(AdminMappings).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsPost));
Given(Request.Create().WithPath(AdminMappings).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsDelete));
Given(Request.Create().WithPath(_adminPaths.Mappings).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsGet));
Given(Request.Create().WithPath(_adminPaths.Mappings).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsPost));
Given(Request.Create().WithPath(_adminPaths.Mappings).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsDelete));
// __admin/mappings/code
Given(Request.Create().WithPath(AdminMappingsCode).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsCodeGet));
Given(Request.Create().WithPath(_adminPaths.MappingsCode).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsCodeGet));
// __admin/mappings/wiremock.org
Given(Request.Create().WithPath(AdminMappingsWireMockOrg).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsPostWireMockOrg));
Given(Request.Create().WithPath(_adminPaths.MappingsWireMockOrg).UsingPost().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsPostWireMockOrg));
// __admin/mappings/reset
Given(Request.Create().WithPath(AdminMappings + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsReset));
Given(Request.Create().WithPath(_adminPaths.Mappings + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsReset));
// __admin/mappings/{guid}
Given(Request.Create().WithPath(AdminMappingsGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingGet));
Given(Request.Create().WithPath(AdminMappingsGuidPathMatcher).UsingPut().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingPut));
Given(Request.Create().WithPath(AdminMappingsGuidPathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingDelete));
Given(Request.Create().WithPath(_adminPaths.MappingsGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingGet));
Given(Request.Create().WithPath(_adminPaths.MappingsGuidPathMatcher).UsingPut().WithHeader(HttpKnownHeaderNames.ContentType, AdminRequestContentTypeJson)).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingPut));
Given(Request.Create().WithPath(_adminPaths.MappingsGuidPathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingDelete));
// __admin/mappings/code/{guid}
Given(Request.Create().WithPath(AdminMappingsCodeGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingCodeGet));
Given(Request.Create().WithPath(_adminPaths.MappingsCodeGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingCodeGet));
// __admin/mappings/save
Given(Request.Create().WithPath($"{AdminMappings}/save").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsSave));
Given(Request.Create().WithPath($"{_adminPaths.Mappings}/save").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(MappingsSave));
// __admin/mappings/swagger
Given(Request.Create().WithPath($"{AdminMappings}/swagger").UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SwaggerGet));
Given(Request.Create().WithPath($"{_adminPaths.Mappings}/swagger").UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(SwaggerGet));
// __admin/requests
Given(Request.Create().WithPath(AdminRequests).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsGet));
Given(Request.Create().WithPath(AdminRequests).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsDelete));
Given(Request.Create().WithPath(_adminPaths.Requests).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsGet));
Given(Request.Create().WithPath(_adminPaths.Requests).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsDelete));
// __admin/requests/reset
Given(Request.Create().WithPath(AdminRequests + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsDelete));
Given(Request.Create().WithPath(_adminPaths.Requests + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsDelete));
// __admin/request/{guid}
Given(Request.Create().WithPath(AdminRequestsGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestGet));
Given(Request.Create().WithPath(AdminRequestsGuidPathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestDelete));
Given(Request.Create().WithPath(_adminPaths.RequestsGuidPathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestGet));
Given(Request.Create().WithPath(_adminPaths.RequestsGuidPathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestDelete));
// __admin/requests/find
Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFind));
Given(Request.Create().WithPath(AdminRequests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFindByMappingGuid));
Given(Request.Create().WithPath(_adminPaths.Requests + "/find").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFind));
Given(Request.Create().WithPath(_adminPaths.Requests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFindByMappingGuid));
// __admin/scenarios
Given(Request.Create().WithPath(AdminScenarios).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosGet));
Given(Request.Create().WithPath(AdminScenarios).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosReset));
Given(Request.Create().WithPath(AdminScenariosNameMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenarioReset));
Given(Request.Create().WithPath(_adminPaths.Scenarios).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosGet));
Given(Request.Create().WithPath(_adminPaths.Scenarios).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosReset));
Given(Request.Create().WithPath(_adminPaths.ScenariosNameMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenarioReset));
// __admin/scenarios/reset
Given(Request.Create().WithPath(AdminScenarios + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosReset));
Given(Request.Create().WithPath(AdminScenariosNameWithResetMatcher).UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenarioReset));
Given(Request.Create().WithPath(_adminPaths.Scenarios + "/reset").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosReset));
Given(Request.Create().WithPath(_adminPaths.ScenariosNameWithResetMatcher).UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenarioReset));
// __admin/files/{filename}
Given(Request.Create().WithPath(AdminFilesFilenamePathMatcher).UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FilePost));
Given(Request.Create().WithPath(AdminFilesFilenamePathMatcher).UsingPut()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FilePut));
Given(Request.Create().WithPath(AdminFilesFilenamePathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileGet));
Given(Request.Create().WithPath(AdminFilesFilenamePathMatcher).UsingHead()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileHead));
Given(Request.Create().WithPath(AdminFilesFilenamePathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileDelete));
Given(Request.Create().WithPath(_adminPaths.FilesFilenamePathMatcher).UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FilePost));
Given(Request.Create().WithPath(_adminPaths.FilesFilenamePathMatcher).UsingPut()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FilePut));
Given(Request.Create().WithPath(_adminPaths.FilesFilenamePathMatcher).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileGet));
Given(Request.Create().WithPath(_adminPaths.FilesFilenamePathMatcher).UsingHead()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileHead));
Given(Request.Create().WithPath(_adminPaths.FilesFilenamePathMatcher).UsingDelete()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(FileDelete));
// __admin/openapi
Given(Request.Create().WithPath($"{AdminOpenApi}/convert").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(OpenApiConvertToMappings));
Given(Request.Create().WithPath($"{AdminOpenApi}/save").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(OpenApiSaveToMappings));
Given(Request.Create().WithPath($"{_adminPaths.OpenApi}/convert").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(OpenApiConvertToMappings));
Given(Request.Create().WithPath($"{_adminPaths.OpenApi}/save").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(OpenApiSaveToMappings));
}
#endregion
@@ -218,6 +239,22 @@ public partial class WireMockServer
}
#endregion
#region Health
private static IResponseMessage HealthGet(IRequestMessage requestMessage)
{
return new ResponseMessage
{
BodyData = new BodyData
{
DetectedBodyType = BodyType.String,
BodyAsString = "Healthy"
},
StatusCode = (int)HttpStatusCode.OK,
Headers = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string>(WireMockConstants.ContentTypeTextPlain) } }
};
}
#endregion
#region Settings
private IResponseMessage SettingsGet(IRequestMessage requestMessage)
{
@@ -645,7 +682,7 @@ public partial class WireMockServer
private IResponseMessage ScenarioReset(IRequestMessage requestMessage)
{
var name = string.Equals(HttpRequestMethod.DELETE, requestMessage.Method, StringComparison.OrdinalIgnoreCase) ?
requestMessage.Path.Substring(AdminScenarios.Length + 1) :
requestMessage.Path.Substring(_adminPaths!.Scenarios.Length + 1) :
requestMessage.Path.Split('/').Reverse().Skip(1).First();
return ResetScenario(name) ?
@@ -830,4 +867,4 @@ public partial class WireMockServer
var singleResult = ((JObject)value).ToObject<T>();
return new[] { singleResult! };
}
}
}

View File

@@ -2,7 +2,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using WireMock.Matchers;
using WireMock.Types;
using WireMock.Util;
@@ -10,7 +9,6 @@ namespace WireMock.Server;
public partial class WireMockServer
{
private static readonly RegexMatcher AdminFilesFilenamePathMatcher = new(@"^\/__admin\/files\/.*$");
private static readonly Encoding[] FileBodyIsString = { Encoding.UTF8, Encoding.ASCII };
#region Files/{filename}
@@ -117,9 +115,9 @@ public partial class WireMockServer
return ResponseMessageBuilder.Create(HttpStatusCode.OK, "File deleted.");
}
private static string GetFileNameFromRequestMessage(IRequestMessage requestMessage)
private string GetFileNameFromRequestMessage(IRequestMessage requestMessage)
{
return Path.GetFileName(requestMessage.Path.Substring(AdminFiles.Length + 1));
return Path.GetFileName(requestMessage.Path.Substring(_adminPaths!.Files.Length + 1));
}
#endregion
}

View File

@@ -245,16 +245,16 @@ public class WireMockServerSettings
public bool CustomCertificateDefined => CertificateSettings?.IsDefined == true;
#if USE_ASPNETCORE
/// <summary>
/// Client certificate mode for the server
/// </summary>
[PublicAPI]
public ClientCertificateMode ClientCertificateMode { get; set; }
/// <summary>
/// Client certificate mode for the server
/// </summary>
[PublicAPI]
public ClientCertificateMode ClientCertificateMode { get; set; }
/// <summary>
/// Whether to accept any client certificate
/// </summary>
public bool AcceptAnyClientCertificate { get; set; }
/// <summary>
/// Whether to accept any client certificate
/// </summary>
public bool AcceptAnyClientCertificate { get; set; }
#endif
/// <summary>
@@ -320,4 +320,11 @@ public class WireMockServerSettings
/// </summary>
[PublicAPI]
public Dictionary<string, GraphQLSchemaDetails>? GraphQLSchemas { get; set; }
/// <summary>
/// The admin path to use for accessing the Admin REST interface.
/// If not set <c>__/admin</c> is used.
/// </summary>
[PublicAPI]
public string? AdminPath { get; set; }
}

View File

@@ -45,6 +45,7 @@ public static class WireMockServerSettingsParser
AdminAzureADTenant = parser.GetStringValue(nameof(WireMockServerSettings.AdminAzureADTenant)),
AdminPassword = parser.GetStringValue(nameof(WireMockServerSettings.AdminPassword)),
AdminUsername = parser.GetStringValue(nameof(WireMockServerSettings.AdminUsername)),
AdminPath = parser.GetStringValue(nameof(WireMockServerSettings.AdminPath), "/__admin"),
AllowBodyForAllHttpMethods = parser.GetBoolValue(nameof(WireMockServerSettings.AllowBodyForAllHttpMethods)),
AllowCSharpCodeMatcher = parser.GetBoolValue(nameof(WireMockServerSettings.AllowCSharpCodeMatcher)),
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue(nameof(WireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse)),

View File

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

View File

@@ -17,6 +17,7 @@ using VerifyXunit;
using WireMock.Admin.Mappings;
using WireMock.Admin.Settings;
using WireMock.Client;
using WireMock.Client.Extensions;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.Matchers;
@@ -41,6 +42,47 @@ public partial class WireMockAdminApiTests
VerifyNewtonsoftJson.Enable(VerifySettings);
}
[Fact]
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_OK()
{
// Arrange
var adminUsername = $"username_{Guid.NewGuid()}";
var adminPassword = $"password_{Guid.NewGuid()}";
var server = WireMockServer.Start(w =>
{
w.StartAdminInterface = true;
w.AdminUsername = adminUsername;
w.AdminPassword = adminPassword;
});
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0])
.WithAuthorization(adminUsername, adminPassword);
// Act 1
await api.WaitForHealthAsync().ConfigureAwait(false);
// Act 2
var status = await api.GetHealthAsync().ConfigureAwait(false);
status.Should().Be("Healthy");
}
[Fact]
public async Task IWireMockAdminApi_WaitForHealthAsync_AndCall_GetHealthAsync_ThrowsException()
{
// Arrange
var server = WireMockServer.Start(w =>
{
w.StartAdminInterface = true;
w.AdminUsername = $"username_{Guid.NewGuid()}";
w.AdminPassword = $"password_{Guid.NewGuid()}";
});
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0]);
// Act
Func<Task> act = () => api.WaitForHealthAsync(maxRetries: 3);
await act.Should().ThrowAsync<InvalidOperationException>();
}
[Fact]
public async Task IWireMockAdminApi_GetSettingsAsync()
{
@@ -53,6 +95,28 @@ public partial class WireMockAdminApiTests
Check.That(settings).IsNotNull();
}
[Fact]
public async Task IWireMockAdminApi_GetSettingsAsync_ForDifferentAdminPath()
{
// Arrange
var server = WireMockServer.Start(w =>
{
w.StartAdminInterface = true;
w.AdminPath = "/foo/__admin";
});
var api = RestClient.For<IWireMockAdminApi>(server.Urls[0] + "/foo");
// Act
var settings = await api.GetSettingsAsync().ConfigureAwait(false);
// Assert
Check.That(settings).IsNotNull();
// Cleanup
server.Stop();
server.Dispose();
}
[Fact]
public async Task IWireMockAdminApi_PostSettingsAsync()
{

View File

@@ -0,0 +1,32 @@
{
Guid: 53241df5-582c-458a-a67b-6de3d1d0508e,
UpdatedAt: DateTime_1,
Title: This is my title 1,
Request: {
Path: {
Matchers: [
{
Name: WildcardMatcher,
Pattern: /bla1,
IgnoreCase: false
}
]
},
Methods: [
POST
],
Body: {
Matcher: {
Name: JsonPartialMatcher,
Pattern: {
test: abc
},
IgnoreCase: false,
Regex: false
}
}
},
Response: {
Body: The Response
}
}

View File

@@ -0,0 +1,67 @@
#if !(NET452 || NET461 || NETCOREAPP3_1)
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using VerifyTests;
using VerifyXunit;
using WireMock.Client;
using WireMock.Client.Extensions;
using WireMock.Net.Tests.VerifyExtensions;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests.Client.Builders;
[ExcludeFromCodeCoverage]
[UsesVerify]
public class AdminApiMappingBuilderTests
{
private static readonly VerifySettings VerifySettings = new();
static AdminApiMappingBuilderTests()
{
VerifyNewtonsoftJson.Enable(VerifySettings);
}
[Fact]
public async Task GetMappingBuilder_BuildAndPostAsync()
{
using var server = WireMockServer.StartWithAdminInterface();
var api = RestEase.RestClient.For<IWireMockAdminApi>(server.Url!);
var guid = Guid.Parse("53241df5-582c-458a-a67b-6de3d1d0508e");
var mappingBuilder = api.GetMappingBuilder();
mappingBuilder.Given(m => m
.WithTitle("This is my title 1")
.WithGuid(guid)
.WithRequest(req => req
.UsingPost()
.WithPath("/bla1")
.WithBody(body => body
.WithMatcher(matcher => matcher
.WithName("JsonPartialMatcher")
.WithPattern(new { test = "abc" })
)
)
)
.WithResponse(rsp => rsp
.WithBody("The Response")
)
);
// Act
var status = await mappingBuilder.BuildAndPostAsync().ConfigureAwait(false);
// Assert
status.Status.Should().Be("Mapping added");
var getMappingResult = await api.GetMappingAsync(guid).ConfigureAwait(false);
await Verifier.Verify(getMappingResult, VerifySettings).DontScrubGuids();
server.Stop();
}
}
#endif

View File

@@ -0,0 +1,40 @@
using System;
using FluentAssertions;
using WireMock.Extensions;
using Xunit;
namespace WireMock.Net.Tests.Extensions;
public class EnumExtensionsTests
{
private enum TestEnum
{
Value1
}
[Fact]
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldReturnCorrectValue()
{
// Arrange
var enumValue = TestEnum.Value1;
// Act
var result = enumValue.GetFullyQualifiedEnumValue();
// Assert
result.Should().Be("WireMock.Net.Tests.Extensions.TestEnum.Value1");
}
[Fact]
public void EnumExtensions_GetFullyQualifiedEnumValue_ShouldThrowArgumentException_WhenTypeIsNotEnum()
{
// Arrange
int nonEnumValue = 42;
// Act
Action act = () => nonEnumValue.GetFullyQualifiedEnumValue();
// Assert
act.Should().Throw<ArgumentException>().WithMessage("T must be an enum");
}
}

View File

@@ -385,4 +385,22 @@ public class JsonPartialWildcardMatcherTests
// Assert
Assert.Equal(0.0, match);
}
[Fact]
public void JsonPartialWildcardMatcher_IsMatch_WithIgnoreCaseTrueAndRegexTrue_JObject()
{
// Assign
var matcher = new JsonPartialWildcardMatcher(new { id = 1, Number = "^\\d+$" }, ignoreCase: true, regex: true);
// Act
var jObject = new JObject
{
{ "Id", new JValue(1) },
{ "Number", new JValue(1) }
};
double match = matcher.IsMatch(jObject).Score;
// Assert
Assert.Equal(1.0, match);
}
}

View File

@@ -3,8 +3,6 @@ using FluentAssertions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JsonConverter.Abstractions;
using Moq;
using Newtonsoft.Json;
using NFluent;
using WireMock.Matchers;
@@ -293,7 +291,7 @@ public class RequestBuilderWithBodyTests
}
[Fact]
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
public void Request_WithBody_Object_JsonPathMatcher_true()
{
// Arrange
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
@@ -316,7 +314,7 @@ public class RequestBuilderWithBodyTests
}
[Fact]
public void Request_WithBodyAsJson_Array_JsonPathMatcher_1()
public void Request_WithBody_Array_JsonPathMatcher_1()
{
// Arrange
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
@@ -339,7 +337,7 @@ public class RequestBuilderWithBodyTests
}
[Fact]
public void Request_WithBodyAsJson_Array_JsonPathMatcher_2()
public void Request_WithBody_Array_JsonPathMatcher_2()
{
// Arrange
var spec = Request.Create().UsingAnyMethod().WithBody(new JsonPathMatcher("$..[?(@.Id == 1)]"));
@@ -363,7 +361,7 @@ public class RequestBuilderWithBodyTests
}
[Fact]
public void Request_WithBodyAsObject_ExactObjectMatcher_true()
public void Request_WithBody_ExactObjectMatcher_true()
{
// Assign
object body = DateTime.MinValue;
@@ -384,7 +382,7 @@ public class RequestBuilderWithBodyTests
}
[Fact]
public void Request_WithBodyAsJson_UsingObject()
public void Request_WithBodyAsJson_UsingObject_UsesJsonMatcher()
{
// Assign
object body = new
@@ -395,34 +393,8 @@ public class RequestBuilderWithBodyTests
var bodyData = new BodyData
{
BodyAsString = JsonConvert.SerializeObject(body),
DetectedBodyType = BodyType.String
};
// Act
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);
// Assert
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
}
[Fact]
public void Request_WithBodyAsJson_WithIJsonConverter_UsingObject()
{
// Assign
var jsonConverterMock = new Mock<IJsonConverter>();
jsonConverterMock.Setup(j => j.Serialize(It.IsAny<object>(), It.IsAny<JsonConverterOptions>())).Returns("test");
object body = new
{
Any = "key"
};
var requestBuilder = Request.Create().UsingAnyMethod().WithBodyAsJson(body, jsonConverterMock.Object);
var bodyData = new BodyData
{
BodyAsString = "test",
DetectedBodyType = BodyType.String
BodyAsJson = body,
DetectedBodyType = BodyType.Json
};
// Act

View File

@@ -1,6 +1,7 @@
#if MIMEKIT
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using WireMock.Matchers;
using WireMock.Matchers.Request;
@@ -34,8 +35,123 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
--=-5XgmpXt0XOfzdtcgNJc2ZQ==--
";
[Fact]
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsMultiPart()
private static readonly MimePartMatcher PerfectTextPlainMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("text/plain"),
null,
null,
new ExactMatcher("This is some plain text")
);
private static readonly MimePartMatcher PerfectPartTextMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("text/json"),
null,
null,
new JsonMatcher(new { Key = "Value" }, true)
);
private static readonly MimePartMatcher PerfectImagePngMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("image/png"),
new ExactMatcher("attachment; filename=\"image.png\""),
new ExactMatcher("base64"),
new ExactObjectMatcher(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAgMAAAAP2OW3AAAADFBMVEX/tID/vpH/pWX/sHidUyjlAAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC"))
);
private static readonly MimePartMatcher MismatchTextPlainMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("text/plain"),
null,
null,
new ExactMatcher("--INVALID TEXT--")
);
private static readonly MimePartMatcher MismatchPartTextMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("text/json"),
null,
null,
new JsonMatcher(new { Key = "InvalidValue" }, true)
);
private static readonly MimePartMatcher MismatchImagePngMatcher = new(
MatchBehaviour.AcceptOnMatch,
new ContentTypeMatcher("image/png"),
new ExactMatcher("attachment; filename=\"invalid.png\""),
new ExactMatcher("base64"),
null
);
public static TheoryData<IMatcher?, IMatcher?, IMatcher?> PerfectMatchersData => new()
{
{ PerfectTextPlainMatcher, null, null },
{ PerfectPartTextMatcher, null, null },
{ PerfectImagePngMatcher, null, null },
{ PerfectPartTextMatcher, PerfectTextPlainMatcher, null },
{ PerfectPartTextMatcher, PerfectImagePngMatcher, PerfectTextPlainMatcher },
};
public static TheoryData<IMatcher?, IMatcher?, IMatcher?> MismatchMatchersData => new()
{
{ MismatchTextPlainMatcher, null, null },
{ MismatchPartTextMatcher, null, null },
{ MismatchImagePngMatcher, null, null },
{ MismatchPartTextMatcher, MismatchTextPlainMatcher, null },
{ MismatchPartTextMatcher, MismatchImagePngMatcher, MismatchTextPlainMatcher },
};
public static TheoryData<IMatcher?, IMatcher?, IMatcher?> MixedMatchersData => new()
{
{ MismatchPartTextMatcher, PerfectTextPlainMatcher, null },
{ PerfectPartTextMatcher, MismatchImagePngMatcher, null },
};
[Theory]
[MemberData(nameof(PerfectMatchersData))]
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsMultiPart_Perfect(IMatcher? matcher1, IMatcher? matcher2, IMatcher? matcher3)
{
// Assign
var score = GetScore(matcher1, matcher2, matcher3);
// Assert
score.Should().Be(MatchScores.Perfect);
}
[Theory]
[MemberData(nameof(MismatchMatchersData))]
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsMultiPart_Mismatch(IMatcher? matcher1, IMatcher? matcher2, IMatcher? matcher3)
{
// Assign
var score = GetScore(matcher1, matcher2, matcher3);
// Assert
score.Should().Be(MatchScores.Mismatch);
}
[Theory]
[MemberData(nameof(MixedMatchersData))]
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsMultiPart_Mixed_With_And(IMatcher? matcher1, IMatcher? matcher2, IMatcher? matcher3)
{
// Assign
var score = GetScore(matcher1, matcher2, matcher3);
// Assert
score.Should().Be(MatchScores.Mismatch);
}
[Theory]
[MemberData(nameof(MixedMatchersData))]
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsMultiPart_Mixed_With_Or(IMatcher? matcher1, IMatcher? matcher2, IMatcher? matcher3)
{
// Assign
var score = GetScore(matcher1, matcher2, matcher3, MatchOperator.Or);
// Assert
score.Should().Be(MatchScores.Perfect);
}
private static double GetScore(IMatcher? matcher1, IMatcher? matcher2, IMatcher? matcher3, MatchOperator matchOperator = MatchOperator.And)
{
// Assign
var body = new BodyData
@@ -44,41 +160,20 @@ AAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC
DetectedBodyType = BodyType.MultiPart
};
var textPlainContentTypeMatcher = new ContentTypeMatcher("text/plain");
var textPlainContentMatcher = new ExactMatcher("This is some plain text");
var textPlainMatcher = new MimePartMatcher(MatchBehaviour.AcceptOnMatch, textPlainContentTypeMatcher, null, null, textPlainContentMatcher);
var partTextJsonContentTypeMatcher = new ContentTypeMatcher("text/json");
var partTextJsonContentMatcher = new JsonMatcher(new { Key = "Value" }, true);
var partTextMatcher = new MimePartMatcher(MatchBehaviour.AcceptOnMatch, partTextJsonContentTypeMatcher, null, null, partTextJsonContentMatcher);
var imagePngContentTypeMatcher = new ContentTypeMatcher("image/png");
var imagePngContentDispositionMatcher = new ExactMatcher("attachment; filename=\"image.png\"");
var imagePngContentTransferEncodingMatcher = new ExactMatcher("base64");
var imagePngContentMatcher = new ExactObjectMatcher(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAgMAAAAP2OW3AAAADFBMVEX/tID/vpH/pWX/sHidUyjlAAAADElEQVR4XmMQYNgAAADkAMHebX3mAAAAAElFTkSuQmCC"));
var imagePngMatcher = new MimePartMatcher(MatchBehaviour.AcceptOnMatch, imagePngContentTypeMatcher, imagePngContentDispositionMatcher, imagePngContentTransferEncodingMatcher, imagePngContentMatcher);
var matchers = new IMatcher[]
{
textPlainMatcher,
partTextMatcher,
imagePngMatcher
};
var headers = new Dictionary<string, string[]>
{
{ "Content-Type", new[] { @"multipart/mixed; boundary=""=-5XgmpXt0XOfzdtcgNJc2ZQ==""" } }
};
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body, headers);
var matchers = new IMatcher?[] { matcher1, matcher2, matcher3 }
.Where(m => m is not null)
.ToArray();
var matcher = new RequestMessageMultiPartMatcher(matchers);
var matcher = new RequestMessageMultiPartMatcher(MatchBehaviour.AcceptOnMatch, matchOperator, matchers!);
// Act
var result = new RequestMatchResult();
var score = matcher.GetMatchingScore(requestMessage, result);
// Assert
score.Should().Be(MatchScores.Perfect);
return matcher.GetMatchingScore(requestMessage, result);
}
}
#endif

View File

@@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Threading.Tasks;
using FluentAssertions;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -354,7 +355,7 @@ public class ResponseWithHandlebarsJsonPathTests
public async Task Response_ProvideResponse_Transformer_WithBodyAsFile_JsonPath()
{
// Assign
string jsonString = "{ \"MyUniqueNumber\": \"1\" }";
const string jsonString = "{ \"MyUniqueNumber\": \"1\" }";
var bodyData = new BodyData
{
BodyAsString = jsonString,
@@ -365,15 +366,17 @@ public class ResponseWithHandlebarsJsonPathTests
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);
string jsonPath = "\"$.MyUniqueNumber\"";
var responseBuilder = Response.Create()
.WithTransformer()
.WithBodyFromFile(@"c:\\{{JsonPath.SelectToken request.body " + jsonPath + "}}\\test.json"); // why use a \\ here ?
// We need to use `c:\\\\` here because when just using `c:\\\`, the `\\` it will be interpreted as an escape character to skip / exclude / escape the whole {{}} expression.
// See https://handlebarsjs.com/guide/expressions.html#escaping-handlebars-expressions
.WithBodyFromFile("c:\\\\{{JsonPath.SelectToken request.body \"$.MyUniqueNumber\" }}\\test.json");
// Act
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
// Assert
Check.That(response.Message.BodyData.BodyAsFile).Equals(@"c:\1\test.json");
response.Message.BodyData?.BodyAsFile.Should().Be(@"c:\1\test.json");
}
}

View File

@@ -0,0 +1,35 @@
using FluentAssertions;
using WireMock.Settings;
using Xunit;
namespace WireMock.Net.Tests.Settings;
public class WireMockServerSettingsParserTests
{
[Fact]
public void TryParseArguments_With_Args()
{
// Act
var result = WireMockServerSettingsParser.TryParseArguments(new[]
{
"--adminPath", "ap"
}, null, out var settings);
// Assert
result.Should().BeTrue();
settings.Should().NotBeNull();
settings!.AdminPath.Should().Be("ap");
}
[Fact]
public void TryParseArguments_Without_Args()
{
// Act
var result = WireMockServerSettingsParser.TryParseArguments(new string[] { }, null, out var settings);
// Assert
result.Should().BeTrue();
settings.Should().NotBeNull();
settings!.AdminPath.Should().Be("/__admin");
}
}

View File

@@ -1,4 +1,5 @@
#if NET6_0_OR_GREATER
using System;
using System.Threading.Tasks;
using FluentAssertions;
using FluentAssertions.Execution;
@@ -13,9 +14,12 @@ public class TestcontainersTests
public async Task WireMockContainer_Build_and_StartAsync_and_StopAsync()
{
// Act
var adminUsername = $"username_{Guid.NewGuid()}";
var adminPassword = $"password_{Guid.NewGuid()}";
var wireMockContainer = new WireMockContainerBuilder()
.WithAutoRemove(true)
.WithCleanUp(true)
.WithAdminUserNameAndPassword(adminUsername, adminPassword)
.Build();
try

View File

@@ -9,6 +9,7 @@ using FluentAssertions;
using Moq;
using Newtonsoft.Json;
using NFluent;
using WireMock.Admin.Settings;
using WireMock.Handlers;
using WireMock.Logging;
using WireMock.RequestBuilders;
@@ -22,13 +23,9 @@ namespace WireMock.Net.Tests;
public class WireMockServerAdminTests
{
// For for AppVeyor + OpenCover
private string GetCurrentFolder()
private static string GetCurrentFolder()
{
string current = Directory.GetCurrentDirectory();
//if (!current.EndsWith("WireMock.Net.Tests"))
// return Path.Combine(current, "test", "WireMock.Net.Tests");
return current;
return Directory.GetCurrentDirectory();
}
[Fact]
@@ -468,9 +465,9 @@ public class WireMockServerAdminTests
Check.That(server.MappingModels.Count()).Equals(3);
Guid? guid1 = server.MappingModels.ElementAt(0).Guid;
Guid? guid2 = server.MappingModels.ElementAt(1).Guid;
Guid? guid3 = server.MappingModels.ElementAt(2).Guid;
var guid1 = server.MappingModels.ElementAt(0).Guid;
var guid2 = server.MappingModels.ElementAt(1).Guid;
var guid3 = server.MappingModels.ElementAt(2).Guid;
Check.That(guid1).IsNotNull();
Check.That(guid2).IsNotNull();
@@ -482,7 +479,7 @@ public class WireMockServerAdminTests
$"]";
// Act
var request = new HttpRequestMessage()
var request = new HttpRequestMessage
{
Method = HttpMethod.Delete,
RequestUri = new Uri($"http://localhost:{server.Ports[0]}/__admin/mappings"),
@@ -501,22 +498,45 @@ public class WireMockServerAdminTests
}
[Fact]
public async Task WireMockServer_Admin_()
public async Task WireMockServer_CreateClient_And_CallEndpoint()
{
// given
// Arrange
var server = WireMockServer.Start();
var client = server.CreateClient();
server.CreateClient();
// Act
await client.GetAsync($"{server.Url}/foo").ConfigureAwait(false);
// when
await new HttpClient().GetAsync("http://localhost:" + server.Ports[0] + "/foo").ConfigureAwait(false);
// then
// Assert
Check.That(server.LogEntries).HasSize(1);
var requestLogged = server.LogEntries.First();
Check.That(requestLogged.RequestMessage.Method).IsEqualTo("GET");
Check.That(requestLogged.RequestMessage.BodyData).IsNull();
// Cleanup
server.Stop();
server.Dispose();
}
[Fact]
public async Task WireMockServer_CreateClient_And_CallAdminSettingsEndpoint()
{
// Arrange
var server = WireMockServer.Start(w =>
{
w.StartAdminInterface = true;
w.AdminPath = "/adm";
});
var client = server.CreateClient();
// Act
var settings = await client.GetStringAsync($"{server.Url}/adm/settings").ConfigureAwait(false);
// Assert
settings.Should().NotBeNull();
// Cleanup
server.Stop();
server.Dispose();
}
}

View File

@@ -117,7 +117,7 @@ public class WireMockServerProxyTests
}
// Assert
server.Mappings.Should().HaveCount(35);
server.Mappings.Should().HaveCount(36);
}
[Fact]

View File

@@ -81,7 +81,7 @@ public class WireMockServerSettingsTests
// Assert
server.Mappings.Should().NotBeNull();
server.Mappings.Should().HaveCount(33);
server.Mappings.Should().HaveCount(34);
server.Mappings.All(m => m.Priority == WireMockConstants.AdminPriority).Should().BeTrue();
}
@@ -100,9 +100,9 @@ public class WireMockServerSettingsTests
// Assert
server.Mappings.Should().NotBeNull();
server.Mappings.Should().HaveCount(34);
server.Mappings.Should().HaveCount(35);
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(33);
server.Mappings.Count(m => m.Priority == WireMockConstants.AdminPriority).Should().Be(34);
server.Mappings.Count(m => m.Priority == WireMockConstants.ProxyPriority).Should().Be(1);
}