mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 06:13:35 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9778c5adbe | ||
|
|
1caa769618 | ||
|
|
cf4e83b10b | ||
|
|
95a201573a | ||
|
|
b248c8c6e5 | ||
|
|
180526c8b4 | ||
|
|
361d40189b | ||
|
|
061eb93fd0 | ||
|
|
e5b2ad0543 | ||
|
|
66b2ff16de | ||
|
|
40ff8514ac |
150
CHANGELOG.md
Normal file
150
CHANGELOG.md
Normal file
@@ -0,0 +1,150 @@
|
||||
# 1.0.3 (04 February 2018)
|
||||
|
||||
- [#86](https://github.com/WireMock-Net/WireMock.Net/issues/86) - Feature : Add FileSystemWatcher logic for watching static mapping files +feature
|
||||
- [#85](https://github.com/WireMock-Net/WireMock.Net/issues/85) - Bug: https for netstandard does not work ? +fix
|
||||
- [#83](https://github.com/WireMock-Net/WireMock.Net/issues/83) - Feature : Add also a method in IProxyResponseBuilder to provide proxy-settings +feature
|
||||
- [#82](https://github.com/WireMock-Net/WireMock.Net/issues/82) - Feature: make it possible to ignore some headers when proxying +feature
|
||||
- [#81](https://github.com/WireMock-Net/WireMock.Net/issues/81) - Feature: When using proxy, only BodyAsBytes in case of binary data?
|
||||
- [#80](https://github.com/WireMock-Net/WireMock.Net/issues/80) - Feature: When using proxy, in case Content-Type is JSON, use BodyAsJson in Response
|
||||
|
||||
Commits: 40ff8514ac...cf4e83b10b
|
||||
|
||||
|
||||
# 1.0.2.13 (23 January 2018)
|
||||
|
||||
- [#79](https://github.com/WireMock-Net/WireMock.Net/pull/79) - Fix missed content headers contributed by ([vladimir-fed](https://github.com/vladimir-fed))
|
||||
- [#78](https://github.com/WireMock-Net/WireMock.Net/issues/78) - WireMock not working when attempting to access from anything other than localhost.
|
||||
- [#57](https://github.com/WireMock-Net/WireMock.Net/issues/57) - ProxyAndRecord does not save query-parameters, headers and body +fix
|
||||
|
||||
Commits: 6d60b3773a...cdcaaa970a
|
||||
|
||||
|
||||
# 1.0.2.12 (16 January 2018)
|
||||
|
||||
- [#77](https://github.com/WireMock-Net/WireMock.Net/pull/77) - Fixed issue #76 contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#76](https://github.com/WireMock-Net/WireMock.Net/issues/76) - Bug: IFluentMockServerAdmin is missing content-type for some POST/PUT calls
|
||||
- [#75](https://github.com/WireMock-Net/WireMock.Net/pull/75) - Add WireMock.Net.WebApplication example contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#74](https://github.com/WireMock-Net/WireMock.Net/pull/74) - Capturing the index of the existing mapping before removing and insert the updated mapping at the same index of the list contributed by ([raghavendrabankapur](https://github.com/raghavendrabankapur))
|
||||
- [#73](https://github.com/WireMock-Net/WireMock.Net/issues/73) - Updated mapping is not being picked and responded with the response
|
||||
|
||||
Commits: da798a59aa...e6af765777
|
||||
|
||||
|
||||
# 1.0.2.11 (20 December 2017)
|
||||
|
||||
- [#72](https://github.com/WireMock-Net/WireMock.Net/issues/72) - Matching WithParam on OData End Points
|
||||
|
||||
Commits: 71196b51c9...71196b51c9
|
||||
|
||||
|
||||
# 1.0.2.9 (07 December 2017)
|
||||
|
||||
- [#71](https://github.com/WireMock-Net/WireMock.Net/pull/71) - Fixed restricted headers on response contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#69](https://github.com/WireMock-Net/WireMock.Net/issues/69) - Instructions are incorrect (?)
|
||||
|
||||
Commits: 601af2d6b2...fd5bc203c3
|
||||
|
||||
|
||||
# 1.0.2.10 (12 December 2017)
|
||||
|
||||
- [#70](https://github.com/WireMock-Net/WireMock.Net/issues/70) - Proxy/Intercept pattern is throwing a keep alive header error with net461
|
||||
|
||||
Commits: d0fc889f42...d0fc889f42
|
||||
|
||||
|
||||
# 1.0.2.8 (23 November 2017)
|
||||
|
||||
- [#68](https://github.com/WireMock-Net/WireMock.Net/issues/68) - Full path required in Stub
|
||||
- [#67](https://github.com/WireMock-Net/WireMock.Net/pull/67) - bug: fix supporting the Patch method and logging the body contributed by Alastair Crabtree ([alastairtree](https://github.com/alastairtree))
|
||||
- [#65](https://github.com/WireMock-Net/WireMock.Net/pull/65) - bug: Fix admin api client definition returning the wrong types contributed by Alastair Crabtree ([alastairtree](https://github.com/alastairtree))
|
||||
- [#64](https://github.com/WireMock-Net/WireMock.Net/issues/64) - Pull Requests do not trigger test + codecoverage ?
|
||||
|
||||
Commits: d0b48e2967...ea16ee866b
|
||||
|
||||
|
||||
# 1.0.2.7 (18 November 2017)
|
||||
|
||||
- [#63](https://github.com/WireMock-Net/WireMock.Net/pull/63) - Fix issue with concurrent logging contributed by ([vladimir-fed](https://github.com/vladimir-fed))
|
||||
- [#62](https://github.com/WireMock-Net/WireMock.Net/pull/62) - Add the Host, Protocol, Port and Origin to the Request message so they can be used in templating contributed by Alastair Crabtree ([alastairtree](https://github.com/alastairtree))
|
||||
- [#61](https://github.com/WireMock-Net/WireMock.Net/issues/61) - Partial mapping
|
||||
- [#53](https://github.com/WireMock-Net/WireMock.Net/issues/53) - New feature request: Access to Owin pipeline
|
||||
- [#42](https://github.com/WireMock-Net/WireMock.Net/issues/42) - Enhancement - Save/load request logs to/from disk +feature
|
||||
- [#27](https://github.com/WireMock-Net/WireMock.Net/issues/27) - New feature: Record and Save
|
||||
|
||||
Commits: e25c873765...018d2a904d
|
||||
|
||||
|
||||
# 1.0.2.6 (30 October 2017)
|
||||
|
||||
- [#60](https://github.com/WireMock-Net/WireMock.Net/pull/60) - Fix proxy headers handling contributed by Oleksandr Liakhevych ([Dreamescaper](https://github.com/Dreamescaper))
|
||||
- [#59](https://github.com/WireMock-Net/WireMock.Net/pull/59) - Add ability to provide multiple values for headers in response contributed by Oleksandr Liakhevych ([Dreamescaper](https://github.com/Dreamescaper))
|
||||
- [#58](https://github.com/WireMock-Net/WireMock.Net/issues/58) - Multiple headers with same name +feature
|
||||
- [#56](https://github.com/WireMock-Net/WireMock.Net/issues/56) - WithBodyFromFile Support +feature
|
||||
- [#54](https://github.com/WireMock-Net/WireMock.Net/issues/54) - Proxy for AWS: Error unmarshalling response back from AWS +fix
|
||||
|
||||
Commits: cbe6a0a2b4...d83f308591
|
||||
|
||||
|
||||
# 1.0.2.5 (24 October 2017)
|
||||
|
||||
- [#55](https://github.com/WireMock-Net/WireMock.Net/pull/55) - Fix the problem with headers passthrough contributed by deeptowncitizen ([deeptowncitizen](https://github.com/deeptowncitizen)) +fix
|
||||
- [#52](https://github.com/WireMock-Net/WireMock.Net/issues/52) - SimMetrics.NET error when trying to install NuGet Package
|
||||
- [#48](https://github.com/WireMock-Net/WireMock.Net/issues/48) - Stateful support +feature
|
||||
- [#44](https://github.com/WireMock-Net/WireMock.Net/issues/44) - Bug: Server not listening after Start() returns (on macOS) +fix
|
||||
|
||||
Commits: 7c289d44a7...15370a89ca
|
||||
|
||||
|
||||
# 1.0.2.4 (10 October 2017)
|
||||
|
||||
- [#51](https://github.com/WireMock-Net/WireMock.Net/pull/51) - Observable logs contributed by deeptowncitizen ([deeptowncitizen](https://github.com/deeptowncitizen))
|
||||
- [#50](https://github.com/WireMock-Net/WireMock.Net/issues/50) - New Feature: Callbacks
|
||||
- [#49](https://github.com/WireMock-Net/WireMock.Net/pull/49) - stateful behavior contributed by deeptowncitizen ([deeptowncitizen](https://github.com/deeptowncitizen))
|
||||
- [#47](https://github.com/WireMock-Net/WireMock.Net/issues/47) - Feature: add matcher details to Request to see which matchers match/not match +feature
|
||||
- [#46](https://github.com/WireMock-Net/WireMock.Net/issues/46) - Log the ip-address from the client/caller also in the RequestLog +feature
|
||||
- [#45](https://github.com/WireMock-Net/WireMock.Net/pull/45) - Add RequestLogExpirationDuration and MaxRequestLogCount (#43) contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#43](https://github.com/WireMock-Net/WireMock.Net/issues/43) - Feature: Add RequestLogExpirationDuration and MaxRequestLogCount
|
||||
- [#41](https://github.com/WireMock-Net/WireMock.Net/pull/41) - Dotnet 20 preview final contributed by Stef Heyenrath ([StefH](https://github.com/StefH)) +feature
|
||||
- [#40](https://github.com/WireMock-Net/WireMock.Net/pull/40) - Expose more settings to stand-alone app contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#39](https://github.com/WireMock-Net/WireMock.Net/pull/39) - Listen on http://*:9090 contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#38](https://github.com/WireMock-Net/WireMock.Net/issues/38) - Bug: support also listening on *:{port}
|
||||
- [#37](https://github.com/WireMock-Net/WireMock.Net/issues/37) - Wrong Request Match result is returning
|
||||
- [#36](https://github.com/WireMock-Net/WireMock.Net/issues/36) - How to implement a request body-dependent response?
|
||||
- [#35](https://github.com/WireMock-Net/WireMock.Net/pull/35) - Revert changes that were made by mistake in prior PR contributed by ([phillee007](https://github.com/phillee007))
|
||||
- [#34](https://github.com/WireMock-Net/WireMock.Net/issues/34) - Where is SearchLogsFor method?
|
||||
- [#33](https://github.com/WireMock-Net/WireMock.Net/issues/33) - Issue with launching sample code (StandAlone server) +fix
|
||||
- [#32](https://github.com/WireMock-Net/WireMock.Net/pull/32) - [Feature] Add support for client certificate password and test with real services that require client certificate auth contributed by ([phillee007](https://github.com/phillee007)) +feature
|
||||
- [#31](https://github.com/WireMock-Net/WireMock.Net/issues/31) - Feature request: Nuget package for standalone version +feature
|
||||
- [#20](https://github.com/WireMock-Net/WireMock.Net/issues/20) - Add client certificate authentication
|
||||
- [#19](https://github.com/WireMock-Net/WireMock.Net/issues/19) - Is this the same as Mock4Net?
|
||||
- [#15](https://github.com/WireMock-Net/WireMock.Net/issues/15) - New feature: Proxying +feature
|
||||
|
||||
Commits: 538195551d...e87e09e10d
|
||||
|
||||
|
||||
# 1.02.1 (14 June 2017)
|
||||
|
||||
- [#30](https://github.com/WireMock-Net/WireMock.Net/issues/30) - [Feature] Disable partial mappings by default in standalone version +fix
|
||||
- [#29](https://github.com/WireMock-Net/WireMock.Net/issues/29) - Support of .Net 4.0
|
||||
- [#28](https://github.com/WireMock-Net/WireMock.Net/issues/28) - Facing issue with WildcardMatcher and '?'
|
||||
|
||||
Commits: 84db9bbf0d...7111ab384b
|
||||
|
||||
|
||||
# 1.0.2.0 (05 May 2017)
|
||||
|
||||
- [#26](https://github.com/WireMock-Net/WireMock.Net/pull/26) - merge netstandard into main contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
|
||||
- [#25](https://github.com/WireMock-Net/WireMock.Net/issues/25) - Upgrade to vs2017 +feature
|
||||
- [#23](https://github.com/WireMock-Net/WireMock.Net/issues/23) - Consider port to .Net Core
|
||||
- [#21](https://github.com/WireMock-Net/WireMock.Net/issues/21) - Admin static json mappings +feature
|
||||
|
||||
Commits: b547993415...8d9cef6dd1
|
||||
|
||||
|
||||
# 1.0.1.2 (27 February 2017)
|
||||
|
||||
- [#24](https://github.com/WireMock-Net/WireMock.Net/pull/24) - Body Encoding contributed by Sebastian Bebrys ([sbebrys](https://github.com/sbebrys))
|
||||
- [#22](https://github.com/WireMock-Net/WireMock.Net/issues/22) - Add basic-authentication for accessing admin-interface +feature
|
||||
- [#8](https://github.com/WireMock-Net/WireMock.Net/issues/8) - admin rest api
|
||||
|
||||
Commits: bb35f55bbb...02803562c6
|
||||
BIN
GitReleaseNotes.exe
Normal file
BIN
GitReleaseNotes.exe
Normal file
Binary file not shown.
5
GitReleaseNotes.txt
Normal file
5
GitReleaseNotes.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
https://github.com/GitTools/GitReleaseNotes
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags
|
||||
14
README.md
14
README.md
@@ -43,6 +43,16 @@ This is quite straight forward to launch a mock server within a console applicat
|
||||
### SSL
|
||||
You can start a standalone mock server listening for HTTPS requests. To do so, there is just a flag to set when creating the server:
|
||||
```csharp
|
||||
var server = FluentMockServer.Start(port: 8443, ssl: true);
|
||||
var server1 = FluentMockServer.Start(port: 8443, ssl: true);
|
||||
|
||||
// or like this
|
||||
|
||||
var server2 = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { "http://localhost:9091", "https://localhost:9443" }
|
||||
});
|
||||
```
|
||||
Obviously you need a certificate registered on your box, properly associated with your application and the port number that will be used. This is not really specific to WireMock, not very straightforward and hence the following stackoverflow thread might come handy: [Httplistener with https support](http://stackoverflow.com/questions/11403333/httplistener-with-https-support)
|
||||
|
||||
- In case when using **net 4.5.2** or **net 4.6**, you need a certificate registered on your box, properly associated with your application and the port number that will be used. This is not really specific to WireMock.Net, not very straightforward and hence the following stackoverflow thread might come handy: [Httplistener with https support](http://stackoverflow.com/questions/11403333/httplistener-with-https-support).
|
||||
|
||||
- When using **netstandard**, WireMock.Net uses a self signed certificate (which can be overriden if you like) to host https urls.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2020
|
||||
VisualStudioVersion = 15.0.27130.2027
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EF242EDF-7133-4277-9A0C-18744DE08707}"
|
||||
EndProject
|
||||
@@ -9,7 +9,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
.runsettings = .runsettings
|
||||
appveyor.yml = appveyor.yml
|
||||
CHANGELOG.md = CHANGELOG.md
|
||||
codecov-local.cmd = codecov-local.cmd
|
||||
GitReleaseNotes.txt = GitReleaseNotes.txt
|
||||
README.md = README.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
@@ -23,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Tests", "test\
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NETCoreApp", "examples\WireMock.Net.Console.NETCoreApp\WireMock.Net.Console.NETCoreApp.csproj", "{FE281639-B014-4C8A-96FA-141164A74713}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Record.NETCoreApp", "examples\WireMock.Net.Console.Record.NETCoreApp\WireMock.Net.Console.Record.NETCoreApp.csproj", "{1995E414-F197-4AB4-90C2-68D806B5AF59}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Proxy.NETCoreApp", "examples\WireMock.Net.Console.Record.NETCoreApp\WireMock.Net.Console.Proxy.NETCoreApp.csproj", "{1995E414-F197-4AB4-90C2-68D806B5AF59}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Client", "examples\WireMock.Net.Client\WireMock.Net.Client.csproj", "{058D4B6C-C03E-49D0-91DB-A535B058FA0D}"
|
||||
EndProject
|
||||
@@ -40,6 +42,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET452
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Proxy.Net452", "examples\WireMock.Net.Console.Proxy.Net452\WireMock.Net.Console.Proxy.Net452.csproj", "{26433A8F-BF01-4962-97EB-81BFFBB61096}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Proxy.NETCoreApp2", "examples\WireMock.Net.Console.Proxy.NETCoreApp2\WireMock.Net.Console.Proxy.NETCoreApp2.csproj", "{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -86,6 +92,14 @@ Global
|
||||
{049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -101,6 +115,8 @@ Global
|
||||
{668F689E-57B4-422E-8846-C0FF643CA999} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{049539C1-7A66-4559-AD7A-B1C73B97CBB0} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BF428BCC-C837-433B-87D2-15C7014B73E9}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
},
|
||||
"UseTransformer": false,
|
||||
"Headers": {
|
||||
"Date": "Wed, 25 Oct 2017 18:57:40 GMT",
|
||||
"Date": "Wed, 27 Oct 2017 18:57:40 GMT",
|
||||
"Alt-Svc": "quic=\":443\"; ma=2592000; v=\"39,38,37,35\"",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
"Connection": "close"
|
||||
|
||||
36
examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs
Normal file
36
examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.Console.Proxy.NETCoreApp2
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { "http://localhost:9091", "https://localhost:9443" },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "https://www.google.com",
|
||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false,
|
||||
BlackListedHeaders = new[] { "dnt", "Content-Length" }
|
||||
}
|
||||
});
|
||||
|
||||
server.LogEntriesChanged += (sender, eventRecordArgs) =>
|
||||
{
|
||||
System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented));
|
||||
};
|
||||
|
||||
System.Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:63377/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"WireMock.Net.Console.Proxy.NETCoreApp2": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:63378/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj" />
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
examples/WireMock.Net.Console.Proxy.Net452/App.config
Normal file
6
examples/WireMock.Net.Console.Proxy.Net452/App.config
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
36
examples/WireMock.Net.Console.Proxy.Net452/Program.cs
Normal file
36
examples/WireMock.Net.Console.Proxy.Net452/Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.Console.Proxy.Net452
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { "http://localhost:9091/", "https://localhost:9443/" },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "https://www.google.com",
|
||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false,
|
||||
BlackListedHeaders = new[] { "dnt", "Content-Length" }
|
||||
}
|
||||
});
|
||||
|
||||
server.LogEntriesChanged += (sender, eventRecordArgs) =>
|
||||
{
|
||||
System.Console.WriteLine(JsonConvert.SerializeObject(eventRecordArgs.NewItems, Formatting.Indented));
|
||||
};
|
||||
|
||||
System.Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
server.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("WireMock.Net.Console.Proxy.Net452")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WireMock.Net.Console.Proxy.Net452")]
|
||||
[assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("26433a8f-bf01-4962-97eb-81bffbb61096")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{26433A8F-BF01-4962-97EB-81BFFBB61096}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WireMock.Net.Console.Proxy.Net452</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.Console.Proxy.Net452</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WireMock.Net.Console.Proxy.Net452.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Condition="'$(Platform)' == 'x64'" Include="..\packages\Libuv.1.10.0\runtimes\win7-x64\native\libuv.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Visible>False</Visible>
|
||||
<Link>libuv.dll</Link>
|
||||
</None>
|
||||
<None Condition="'$(Platform)' == 'x86'" Include="..\packages\Libuv.1.10.0\runtimes\win7-x86\native\libuv.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Visible>False</Visible>
|
||||
<Link>libuv.dll</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.3.1.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj">
|
||||
<Project>{b6269aac-170a-43d5-8b9a-579ded3d9a95}</Project>
|
||||
<Name>WireMock.Net.StandAlone</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj">
|
||||
<Project>{d3804228-91f4-4502-9595-39584e5a01ad}</Project>
|
||||
<Name>WireMock.Net</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -2,7 +2,7 @@
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.Console.Record.NETCoreApp
|
||||
namespace WireMock.Net.Console.Proxy.NETCoreApp
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
@@ -16,9 +16,10 @@ namespace WireMock.Net.Console.Record.NETCoreApp
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "https://www.google.com",
|
||||
//X509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false
|
||||
SaveMappingToFile = false,
|
||||
BlackListedHeaders = new [] { "dnt", "Content-Length" }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -6,13 +6,9 @@
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -21,6 +21,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
Urls = new[] { url1, url2, url3 },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = true,
|
||||
WatchStaticMappings = true,
|
||||
//ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
//{
|
||||
// SaveMapping = true
|
||||
@@ -28,7 +29,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
PreWireMockMiddlewareInit = app => { System.Console.WriteLine($"PreWireMockMiddlewareInit : {app.GetType()}"); },
|
||||
PostWireMockMiddlewareInit = app => { System.Console.WriteLine($"PostWireMockMiddlewareInit : {app.GetType()}"); }
|
||||
});
|
||||
System.Console.WriteLine("FluentMockServer listening at {0}", string.Join(" and ", server.Urls));
|
||||
System.Console.WriteLine("FluentMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace WireMock.Net.StandAlone
|
||||
{
|
||||
StartAdminInterface = parser.GetBoolValue("StartAdminInterface", true),
|
||||
ReadStaticMappings = parser.GetBoolValue("ReadStaticMappings"),
|
||||
WatchStaticMappings = parser.GetBoolValue("WatchStaticMappings"),
|
||||
AllowPartialMapping = parser.GetBoolValue("AllowPartialMapping", true),
|
||||
AdminUsername = parser.GetStringValue("AdminUsername"),
|
||||
AdminPassword = parser.GetStringValue("AdminPassword"),
|
||||
@@ -67,7 +68,8 @@ namespace WireMock.Net.StandAlone
|
||||
Url = proxyURL,
|
||||
SaveMapping = parser.GetBoolValue("SaveMapping"),
|
||||
SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"),
|
||||
X509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("X509Certificate2ThumbprintOrSubjectName")
|
||||
ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"),
|
||||
BlackListedHeaders = parser.GetValues("BlackListedHeaders")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -75,7 +77,7 @@ namespace WireMock.Net.StandAlone
|
||||
|
||||
FluentMockServer server = Start(settings);
|
||||
|
||||
Console.WriteLine("WireMock.Net server listening at {0}", string.Join(" and ", server.Urls));
|
||||
Console.WriteLine("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.2.13</Version>
|
||||
<Version>1.0.3</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
||||
<PackageId>WireMock.Net.StandAlone</PackageId>
|
||||
<PackageTags>tdd;mock;http;wiremock;test;server;unittest</PackageTags>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/LICENSE</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/WireMock-Net/WireMock.Net</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<DebugType>portable</DebugType>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
<RootNamespace>WireMock.Net.StandAlone</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugType>full</DebugType>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<PathMap>$(MSBuildProjectDirectory)=/</PathMap>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0' ">
|
||||
<DefineConstants>NETSTANDARD</DefineConstants>
|
||||
|
||||
@@ -10,29 +10,20 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The unique identifier.
|
||||
/// </value>
|
||||
public Guid? Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the unique title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The unique title.
|
||||
/// </value>
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the priority.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The priority.
|
||||
/// </value>
|
||||
/// </summary>
|
||||
public int? Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Scenario.
|
||||
/// The Scenario.
|
||||
/// </summary>
|
||||
public string Scenario { get; set; }
|
||||
|
||||
@@ -48,19 +39,13 @@ namespace WireMock.Admin.Mappings
|
||||
public object SetStateTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The request.
|
||||
/// </value>
|
||||
/// </summary>
|
||||
public RequestModel Request { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the response.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The response.
|
||||
/// </value>
|
||||
/// </summary>
|
||||
public ResponseModel Response { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
@@ -10,37 +14,28 @@ namespace WireMock.Http
|
||||
{
|
||||
public static HttpClient CreateHttpClient(string clientX509Certificate2ThumbprintOrSubjectName = null)
|
||||
{
|
||||
HttpClientHandler handler;
|
||||
|
||||
if (string.IsNullOrEmpty(clientX509Certificate2ThumbprintOrSubjectName))
|
||||
{
|
||||
handler = new HttpClientHandler();
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls,
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
||||
};
|
||||
|
||||
var x509Certificate2 = CertificateUtil.GetCertificate(clientX509Certificate2ThumbprintOrSubjectName);
|
||||
handler.ClientCertificates.Add(x509Certificate2);
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
CheckCertificateRevocationList = false,
|
||||
SslProtocols = System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls,
|
||||
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true,
|
||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
||||
};
|
||||
#else
|
||||
|
||||
var webRequestHandler = new WebRequestHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true,
|
||||
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
|
||||
};
|
||||
|
||||
var x509Certificate2 = CertificateUtil.GetCertificate(clientX509Certificate2ThumbprintOrSubjectName);
|
||||
webRequestHandler.ClientCertificates.Add(x509Certificate2);
|
||||
handler = webRequestHandler;
|
||||
var handler = new WebRequestHandler
|
||||
{
|
||||
ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true,
|
||||
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
|
||||
};
|
||||
#endif
|
||||
|
||||
if (!string.IsNullOrEmpty(clientX509Certificate2ThumbprintOrSubjectName))
|
||||
{
|
||||
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
|
||||
|
||||
var x509Certificate2 = ClientCertificateHelper.GetCertificate(clientX509Certificate2ThumbprintOrSubjectName);
|
||||
handler.ClientCertificates.Add(x509Certificate2);
|
||||
}
|
||||
|
||||
// For proxy we shouldn't follow auto redirects
|
||||
@@ -49,7 +44,11 @@ namespace WireMock.Http
|
||||
// If UseCookies enabled, httpClient ignores Cookie header
|
||||
handler.UseCookies = false;
|
||||
|
||||
return new HttpClient(handler);
|
||||
var client = new HttpClient(handler);
|
||||
#if NET452 || NET46
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
|
||||
#endif
|
||||
return client;
|
||||
}
|
||||
|
||||
public static async Task<ResponseMessage> SendAsync(HttpClient client, RequestMessage requestMessage, string url)
|
||||
@@ -86,23 +85,22 @@ namespace WireMock.Http
|
||||
// Call the URL
|
||||
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead);
|
||||
|
||||
// Transform response
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = (int)httpResponseMessage.StatusCode,
|
||||
|
||||
BodyAsBytes = await httpResponseMessage.Content.ReadAsByteArrayAsync(),
|
||||
Body = await httpResponseMessage.Content.ReadAsStringAsync()
|
||||
};
|
||||
// Create transform response
|
||||
var responseMessage = new ResponseMessage { StatusCode = (int)httpResponseMessage.StatusCode };
|
||||
|
||||
// Set both content and response headers, replacing URLs in values
|
||||
var headers = httpResponseMessage.Content?.Headers.Union(httpResponseMessage.Headers);
|
||||
var headers = (httpResponseMessage.Content?.Headers.Union(httpResponseMessage.Headers) ?? Enumerable.Empty<KeyValuePair<string, IEnumerable<string>>>()).ToArray();
|
||||
var contentTypeHeader = headers.FirstOrDefault(header => string.Equals(header.Key, HttpKnownHeaderNames.ContentType, StringComparison.OrdinalIgnoreCase));
|
||||
if (httpResponseMessage.Content != null)
|
||||
{
|
||||
SetBody(httpResponseMessage.Content, contentTypeHeader, responseMessage);
|
||||
}
|
||||
|
||||
foreach (var header in headers)
|
||||
{
|
||||
// if Location header contains absolute redirect URL, and base URL is one that we proxy to,
|
||||
// If Location header contains absolute redirect URL, and base URL is one that we proxy to,
|
||||
// we need to replace it to original one.
|
||||
if (string.Equals(header.Key, "Location", StringComparison.OrdinalIgnoreCase)
|
||||
if (string.Equals(header.Key, HttpKnownHeaderNames.Location, StringComparison.OrdinalIgnoreCase)
|
||||
&& Uri.TryCreate(header.Value.First(), UriKind.Absolute, out Uri absoluteLocationUri)
|
||||
&& string.Equals(absoluteLocationUri.Host, requiredUri.Host, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -117,5 +115,41 @@ namespace WireMock.Http
|
||||
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
private static async void SetBody(HttpContent content, KeyValuePair<string, IEnumerable<string>> contentTypeHeader, ResponseMessage responseMessage)
|
||||
{
|
||||
bool contentTypeIsDefault = contentTypeHeader.Equals(default(KeyValuePair<string, IEnumerable<string>>));
|
||||
string[] textContentTypes = { "text/", "application/xml", "application/javascript", "application/typescript", "application/xhtml+xml" };
|
||||
|
||||
if (!contentTypeIsDefault && contentTypeHeader.Value.Any(value => textContentTypes.Any(t => value != null && value.StartsWith(t, StringComparison.OrdinalIgnoreCase))))
|
||||
{
|
||||
try
|
||||
{
|
||||
responseMessage.Body = await content.ReadAsStringAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Reading as string failed, just get the ByteArray.
|
||||
responseMessage.BodyAsBytes = await content.ReadAsByteArrayAsync();
|
||||
}
|
||||
}
|
||||
else if (!contentTypeIsDefault && contentTypeHeader.Value.Any(value => value != null && value.StartsWith("application/json", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
string stringContent = await content.ReadAsStringAsync();
|
||||
try
|
||||
{
|
||||
responseMessage.BodyAsJson = JsonConvert.DeserializeObject(stringContent, new JsonSerializerSettings { Formatting = Formatting.Indented });
|
||||
}
|
||||
catch
|
||||
{
|
||||
// JsonConvert failed, just set the Body as string.
|
||||
responseMessage.Body = stringContent;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
responseMessage.BodyAsBytes = await content.ReadAsByteArrayAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ namespace WireMock.Http
|
||||
public static bool TryExtractProtocolAndPort(string url, out string proto, out int port)
|
||||
{
|
||||
proto = null;
|
||||
port = -1;
|
||||
port = 0;
|
||||
|
||||
Match m = UrlDetailsRegex.Match(url);
|
||||
if (m.Success)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace WireMock.Http
|
||||
namespace WireMock.HttpsCertificate
|
||||
{
|
||||
internal static class CertificateUtil
|
||||
internal static class ClientCertificateHelper
|
||||
{
|
||||
public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName)
|
||||
{
|
||||
91
src/WireMock.Net/HttpsCertificate/PublicCertificateHelper.cs
Normal file
91
src/WireMock.Net/HttpsCertificate/PublicCertificateHelper.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace WireMock.HttpsCertificate
|
||||
{
|
||||
internal static class PublicCertificateHelper
|
||||
{
|
||||
// 1] Generate using https://www.pluralsight.com/blog/software-development/selfcert-create-a-self-signed-certificate-interactively-gui-or-programmatically-in-net
|
||||
// 2] Converted to Base64
|
||||
private const string Data = @"MIIQMgIBAzCCD+4GCSqGSIb3DQEHAaCCD98Egg/bMIIP1zCCCogGCSqGSIb3DQEHAaCCCnkEggp1
|
||||
MIIKcTCCCm0GCyqGSIb3DQEMCgECoIIJfjCCCXowHAYKKoZIhvcNAQwBAzAOBAi1j9x1jTfUewIC
|
||||
B9AEgglYa48lP16+isiGEVT7zwN3XwaPwPOHZcQ7tRA/DA8LZnZbwU7XhtPObF5bZcHn4engX2An
|
||||
ISFpe2S5XJ7BfHmsGOO7Bxj6C2IcZIPTefvAd9vWE0WUAGN11SLhJ3fB/ZRt3Nys7JCJzywQCkYK
|
||||
dCA35V7WfETCLT6+ArtRU4qsjop2YXyUzcLw3OuumBAoRsazgUKz8rkZJbifkSikbdxs+Hupcf2I
|
||||
NOOuKStKoqouqCO/vmRi8u8g0KQhf2LcQBSqLk6OZ8TQuv07W5tVO2Ky5qCYu6aXBBlHhGSY9fGL
|
||||
vqaYcxMcVJQpXUUL6nSWCoaLdaAAB+Anw1Tpbd47W7ieTK5Yq2IROPQIr1mk8nvFbxoTcBuIQ6oU
|
||||
RiiLX+mb3hYgbTL3LqDmmm9FFI8enJu6pUxP8iKKROtCqhYXhF1i3EwReBzJzpDGZ+y4rJxb0Es4
|
||||
sPVc/TaVPSJCTmgcKzwps7M12uxm8G9Dv3lKgZVmgDRivovCJFxHdCdgCYB08FvNWuFtXO+schsE
|
||||
N0nY2i07A2joaJC18yvoNGZ+ySBTBPOBN+5XbiQs0vsQ4MfLETb2O2dFjwE/tErgo6RWYg2qQNAe
|
||||
DSh2wHzI0YJM3PqaUR0Q9KnjEWc92hsLI34KnuNkNkVk4NEjPOetxeIBcYN7CDD6tTxp42sU++bT
|
||||
o9zyjy1BPS+LuEblxDTSlVPb0dxvkwNBXBi0RXIOWfD15BWcV1Uv972jB6To1XPDIOc+eq7fa5yn
|
||||
HRW/GYdGPmOYKietdw6V3t2Et9cPlw4v08IelucF06Ju2a73QtidtkA89vxjn7qOEVACAXpsiMsM
|
||||
4JCcAzF7jh0U2mskSB14I9HcZh1Sei0J2ZULcXNyuIw9nsWp8vrH04OOoUDe7/UpX7c8+A+tqDUy
|
||||
1W2V1dJDhlwu2SXL5jJFBK4P9p2e+XyHJ+AcYXrHQIKxqoCgvnywT4HnI2bvZ1+lmIR99mp1Cvzj
|
||||
RUgJaqhI7u6WH3i6fmkA92hF8MP5WDYTGwjsHPrCg6Xkqykuvub4osu+gLq5t+JC9rOczgrRNYXg
|
||||
54FMzlCyQxTfgY6IRwPH/xYHKGbViFF+jA4ksLMRjI2XOV4swbI232SxMoQQDNsjx1la2nZM3P5z
|
||||
g7zpmaiyzY44q3kU1viMMR7qM/w1S6nTW0ZkzTXk8Gttor/0JWT1K8KgwK02B6Q9zNwfK60a0cQm
|
||||
SbA/dXkWapuIzQLz+ZUPyG/1EP5KuKNnsp0hfVi8TTgOFceoV9kyIhrTQNI0o5O91dqkyWd/bMl2
|
||||
OnrnRnhka6f839zJKUpWPTfRX9RMJTk/5HVcL/qsHYcJedZyPawJjMU+cxW1ZZjr1Lo6M0fjKuTI
|
||||
Askg0ZKS0FJ60jTKnc1DmldQLtieHh1UTdty+yn1A0rGnrFEyN7if2/d1EduWJaf6bvWzfH+d/36
|
||||
1gDwp4OXi0qWu7c5zByGZi2j2sFo4v0cGgjPZUJvF5z0V8OkE15DiA4xtTSkIjCnEmOhODViwrfc
|
||||
ONvHB+inBW9wLp26qFgNcYrYxP2FC54pPCxO+KJaAJrtfE3A4lkboB7V0xFu23ecOy4n2gho39tg
|
||||
Bxkt1Xj3GCLgeKvcYLzOPytZldXDTtoCcsm5uhCmBHEmPUsnLc7Tt1cFflFtWTOjtyv0Lk8Qu2BU
|
||||
B/hSSgjZRpqE+hzjtghjXdFOT5wKULvtUz5eu+lH7kjGghQbF962vLcRCsr+tMPba6MFqhy5Q+dM
|
||||
NcHc+HIx2WiuRZ6jdCZSUpH3f1+kH6XYj2P3/F0kLBRAMPGKbXpIi9Px4AVDEDClL77mDpVgeEoh
|
||||
kkVh5zvk2PsEPonmTFK0kQE8Q4cYFWTKa9lAE4Wc35EzvpKFdTwQKhr5kN7tEq17n5wJt/499164
|
||||
ho0+LjzYy62JI/fv3RPISL0gXr2INLW7fgZ5KNjcnu/AITJu3ycw/XH8BKsx4dcbBgBdrKY8afEn
|
||||
IZ1EIv/TuNvmifmAEGX/DWuVmZIOU6pTystzTQwfz0wko3lUKjkPM40RLN9o6lddV6fM3QNtK0ac
|
||||
hqOOmG68LzI1U33nvUBol/FeEV0DLvGjvsIRC/TCtDu5Vk2tKS13p9kNj4owJK8d343PZ/eyi/Oe
|
||||
sNZCCJJuj4iIodekm1hzj7zc6ZLNudgab/WkF7TbWDOhDPwG1gE/McffGNWPFlwsaopoZaH8E8tl
|
||||
QSOnHqAiNa7B3ifxMrGDWHDlxkWddClbKd9ujL4mgB88Wo8JceLawDOcSVGImvWGxsrK2RX7FK57
|
||||
GQYuc0zcq3NH4jpoOyS+vpMeigTPDOvQdqjGgEUW3aXdA8Ma0KYVEyAhK/rFXw8FelGREM2ku1kN
|
||||
kziOTAe52SWqcrv6NUPfo1/Uc6u7KpwQrcDlFZWxPCKomeRQTm6AmP2QHMgl2gaUbmuBF/C9Ccl2
|
||||
1Iqh8vUdDT3lHdf5I5SjRPJJXX2/0/oUFmwIC5AFp8/XXnIG05BER1X2Y+SL15QHW7lYsvd4ZKTv
|
||||
tvYaZNWajgAVZl8gJYFUQG+U+cFYcpHhf6SGzcuwcmQJGxptZAVnRtDzNjJ04vJB616/uoI2Qkp2
|
||||
ysGAjDNlwgeckmU7TSYoYaML29pRupTTQqKItyFDuebUpSKBTxsEFIJBCTErA8TD8I9T5nzT+rTy
|
||||
+Lpp9mqcxQR1RhxgTx5bE7D4igdblobX0IONARg4EIAk8xj1Ba3k4skdjAQcJOHKd+xVo+vsrIqg
|
||||
a+ycemROE5F3D3s21ozMOn1Dy8iIeQusJQTSkP82+wHYWXRg59N0cq/40CaJskK+yp7afOWFoCqY
|
||||
T/D9OGlfeIIiLivwMh8naPZyM4+pd/CFZwcWoGtIno04nWWR/xQVe17jqPMov1xonC2E3AcKxUXl
|
||||
PMdZoOARkR+KHZnoBZ/vjqxeDPARKupijkw5QQI3jNmd5IELjcL8OraHlo+e884mRsa/66J7p94D
|
||||
bidzjiVLUhCsZnVks9eZF6PIEg49eq/+w8ph3X7XBNnZYAbgola/0yy/PlPzgJ3p/AgXMoGr+HXO
|
||||
p2WAs1WRo9mAdeOBMrAMvXKFD04bZPNHke0Ri03O5U7NRRs1T0LnqdZHyF39As8FiktfJl1bn/U0
|
||||
sUjhc4fDNnDaBN8VF8VsEa7UolRC6NqQ1oHaeEZRoq0li6NbXIXdxIIT4bbqwajqFkvvO6qc6SEG
|
||||
iAlUzTGB2zATBgkqhkiG9w0BCRUxBgQEAQAAADBXBgkqhkiG9w0BCRQxSh5IADcAOAA1ADAAZABj
|
||||
ADAAYwAtAGIAZQBmAGIALQA0AGEANQBiAC0AOAA5ADcAMAAtAGIAZAA5ADkAOQAxADEAOQA2AGIA
|
||||
YgA1MGsGCSsGAQQBgjcRATFeHlwATQBpAGMAcgBvAHMAbwBmAHQAIABFAG4AaABhAG4AYwBlAGQA
|
||||
IABDAHIAeQBwAHQAbwBnAHIAYQBwAGgAaQBjACAAUAByAG8AdgBpAGQAZQByACAAdgAxAC4AMDCC
|
||||
BUcGCSqGSIb3DQEHBqCCBTgwggU0AgEAMIIFLQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQMwDgQI
|
||||
Amt1zAZpKWkCAgfQgIIFAJoBLiXPEZGuUfsyM2ed66sBIirBctHbhyydZsQDT8V2crq6AI3P0dBT
|
||||
Agf/MouK/JcAfdGEEpU6SKxqZBDZoTRbyK7VdW5YiKGUurFGf66L9K3c4MHhVLMWnSkwK+0gwiIB
|
||||
RB82Or4ru0cSQbF32vsuJgJY9Ax4YODKokPFUzZjPrmch4AgZWKxslDFDq4xs3tpLIeZbALWYdrR
|
||||
PUZaReO+NaLfNKwTZsinzjPkCst7R1Jfjf1abikPrOMPgYFUiQL7GNQFbefeJu9SCXlj09u/qw+l
|
||||
uLrwEyMamG0cgjrWbMOohGtvAuHqeZIIWuLnGE2quq7Ah/U55lliZn3IFgs1n6FalW/XGH0T0aRA
|
||||
im6f1EgxtJShBNdG6qNrkzYMyY2Xvpk82qtmvMbhJMDstpovsdT1rZ6OGfsyJAlG94BcCWC2wuvW
|
||||
MYs6H7AirBG/iocNm7JwSBQ7wjl0keH9vuHDQsI+uu9yWGuyZK6MmxDEOEMZRndU0GrlLIp7zQx8
|
||||
gPeagKqSHhPK0ghHhDilMyToE3Euvi5jneh90eofWK6E4E8KtQTWvFeCe9fYRhMaflH9lwfHfXPo
|
||||
9J+7GZLRF/MDTlE8jzWoP5csUxV3jnXQkTUOfHvO7QK6POKwLGkCyZ5wKFydyYdTekG+KU2Vml2y
|
||||
s6pZ+kME1VMYiHRF3CaXX1ZYKikEdnuB1Qp8BE2uKQTaYO4Wns0vQIVRWTrk/Gp5RXu1ihzoTiFb
|
||||
YqLFROQTM+dVTUk3C6W82OroNwofW5ErZwpbdgJJ83gbPLr9W4KZ6YegvEWFT1MawnIYDC6RSKtg
|
||||
fI1blSZOo1SIF6+nR0gFPivSEGBJHclIg7TtvGSB1q7TQFS4W5l+AHdgGPqqURnjuJ7/DVFZHqEV
|
||||
jJM1QEvH/RY1rDXP8FZC6CZR/Le7tVm5o8bHnlU4gyStvNyLXHCP6o3gHmaBcfYmqJr/0ZEKnwnd
|
||||
MBmdIgwQ3+JnKvjAeDe8Z/l0U03CbzeyN3TgUolDlUGVDF2FdPZqrVsLKw6VJv3hoFZmgEbb1fDq
|
||||
Jblc82lrYIEW8E7ltRLDyNDmRdyaqkqw0e7SygXXxv6SKerxoJ5E1NyJdHeQXSahRrsj5UZpxlTE
|
||||
ylb3upIF0F006w2D5J7xUDktPetVgM97dN3whbOrzWPPkn5CTZMaUdYGTYQK3/K/jQSKuXcaM04A
|
||||
EWmcQOQ/5Quco/aMYWTTwFI9+bKZayZKHqQjNKuwss+iWTW2b26cA2XAr2XWCL9PEybVRK/5n4km
|
||||
5qkGIMjjczZxNy1+H1QoEOwkGVzQd390ktQajJBFcf9wBO+Ar14EgPKvdL4DRvCvXOK3CtrgbAq6
|
||||
GK7uULRrz9t/5lu27ba5wcwxg6bFhgCsJsoSCJnLCR7H+QMB4LhnWA10U4hFWCamCKFoGkiXW6yV
|
||||
OF4x+0D0MmrjrrAGi05KzfrsXNtRG0xbkmvrsjqzmsOKyjvtiBCrR0S6NUtKhyxoiz5bCCm+d8rm
|
||||
jaPk9q01k52pjJAKYW0f+5+r15LamBecnjXtJ07LCl6cMA1Cj4L0mQUSefyFi666GC3TmhzHwhnj
|
||||
SV64nTApS0gBsc6c18fUBsMcUj5nCNclIzfxwnARd/30yg22r09nUY2gtQTwk/W6VCpAH+7yZkH1
|
||||
TLNGa+UmMnPsnBjlAJ6l9VPsa4uJM2DIQKtZXWq4DkhSAYKF6joIP7nKMDswHzAHBgUrDgMCGgQU
|
||||
wTM1Z+CJZG9xAcf1zAVGl4ggYyYEFGBFyJ8VBwijS2zy1qwN1WYGtcWoAgIH0A==
|
||||
";
|
||||
|
||||
public static X509Certificate2 GetX509Certificate2()
|
||||
{
|
||||
byte[] data = Convert.FromBase64String(Data);
|
||||
return new X509Certificate2(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The full filename path for this mapping (only defined for static mappings).
|
||||
/// </summary>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
@@ -63,17 +68,19 @@ namespace WireMock
|
||||
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
/// <param name="title">The unique title (can be null_.</param>
|
||||
/// <param name="title">The unique title (can be null).</param>
|
||||
/// <param name="path">The full file path from this mapping title (can be null).</param>
|
||||
/// <param name="requestMatcher">The request matcher.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="priority">The priority for this mapping.</param>
|
||||
/// <param name="scenario">The scenario. [Optional]</param>
|
||||
/// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param>
|
||||
/// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param>
|
||||
public Mapping(Guid guid, [CanBeNull] string title, IRequestMatcher requestMatcher, IResponseProvider provider, int priority, [CanBeNull] string scenario, [CanBeNull] object executionConditionState, [CanBeNull] object nextState)
|
||||
public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path, IRequestMatcher requestMatcher, IResponseProvider provider, int priority, [CanBeNull] string scenario, [CanBeNull] object executionConditionState, [CanBeNull] object nextState)
|
||||
{
|
||||
Guid = guid;
|
||||
Title = title;
|
||||
Path = path;
|
||||
RequestMatcher = requestMatcher;
|
||||
Provider = provider;
|
||||
Priority = priority;
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="simMetricType">The SimMetric Type</param>
|
||||
public SimMetricsMatcher([NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
|
||||
{
|
||||
Check.NotEmpty(patterns, nameof(patterns));
|
||||
Check.NotNullOrEmpty(patterns, nameof(patterns));
|
||||
|
||||
_patterns = patterns;
|
||||
_simMetricType = simMetricType;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#if NETSTANDARD
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using WireMock.Http;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -14,7 +18,7 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly string[] _uriPrefixes;
|
||||
private readonly string[] _urls;
|
||||
|
||||
private IWebHost _host;
|
||||
|
||||
@@ -27,7 +31,7 @@ namespace WireMock.Owin
|
||||
public AspNetCoreSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
foreach (string uriPrefix in uriPrefixes)
|
||||
{
|
||||
@@ -38,7 +42,7 @@ namespace WireMock.Owin
|
||||
}
|
||||
|
||||
_options = options;
|
||||
_uriPrefixes = uriPrefixes;
|
||||
_urls = uriPrefixes;
|
||||
}
|
||||
|
||||
public Task StartAsync()
|
||||
@@ -47,16 +51,45 @@ namespace WireMock.Owin
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
appBuilder.UseMiddleware<GlobalExceptionMiddleware>();
|
||||
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
#if NETSTANDARD1_3
|
||||
if (_urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
options.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
}
|
||||
#else
|
||||
// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?tabs=aspnetcore2x
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("http://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(IPAddress.Loopback, port);
|
||||
}
|
||||
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(IPAddress.Loopback, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
});
|
||||
}
|
||||
#endif
|
||||
})
|
||||
#if NETSTANDARD1_3
|
||||
.UseUrls(_urls)
|
||||
#endif
|
||||
.Build();
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_host.Run(_cts.Token);
|
||||
@@ -65,7 +98,11 @@ namespace WireMock.Owin
|
||||
#else
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||
IsStarted = true;
|
||||
return _host.RunAsync(_cts.Token);
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_host.Run();
|
||||
IsStarted = true;
|
||||
}, _cts.Token);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Util;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
@@ -65,7 +66,7 @@ namespace WireMock.Owin
|
||||
}
|
||||
}
|
||||
|
||||
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null)
|
||||
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null && responseMessage.BodyAsJson == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -84,11 +85,20 @@ namespace WireMock.Owin
|
||||
return;
|
||||
}
|
||||
|
||||
Encoding encoding = responseMessage.BodyEncoding ?? _utf8NoBom;
|
||||
using (var writer = new StreamWriter(response.Body, encoding))
|
||||
if (responseMessage.BodyAsJson != null)
|
||||
{
|
||||
string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore });
|
||||
using (var writer = new StreamWriter(response.Body, responseMessage.BodyEncoding ?? _utf8NoBom))
|
||||
{
|
||||
await writer.WriteAsync(jsonBody);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(response.Body, responseMessage.BodyEncoding ?? _utf8NoBom))
|
||||
{
|
||||
await writer.WriteAsync(responseMessage.Body);
|
||||
// TODO : response.ContentLength = responseMessage.Body.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace WireMock.Owin
|
||||
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
foreach (string uriPrefix in uriPrefixes)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotEmpty(matchers, nameof(matchers));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(matchers));
|
||||
return this;
|
||||
@@ -74,7 +74,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params string[] clientIPs)
|
||||
{
|
||||
Check.NotEmpty(clientIPs, nameof(clientIPs));
|
||||
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
|
||||
return this;
|
||||
@@ -87,7 +87,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(funcs));
|
||||
return this;
|
||||
@@ -100,7 +100,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotEmpty(matchers, nameof(matchers));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(matchers));
|
||||
return this;
|
||||
@@ -113,7 +113,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params string[] paths)
|
||||
{
|
||||
Check.NotEmpty(paths, nameof(paths));
|
||||
Check.NotNullOrEmpty(paths, nameof(paths));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(paths));
|
||||
return this;
|
||||
@@ -126,7 +126,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(funcs));
|
||||
return this;
|
||||
@@ -139,7 +139,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithUrl(params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotEmpty(matchers, nameof(matchers));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(matchers));
|
||||
return this;
|
||||
@@ -152,7 +152,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithUrl(params string[] urls)
|
||||
{
|
||||
Check.NotEmpty(urls, nameof(urls));
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(urls));
|
||||
return this;
|
||||
@@ -165,7 +165,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
|
||||
return this;
|
||||
@@ -228,7 +228,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb"/>
|
||||
public IRequestBuilder UsingVerb(params string[] verbs)
|
||||
{
|
||||
Check.NotEmpty(verbs, nameof(verbs));
|
||||
Check.NotNullOrEmpty(verbs, nameof(verbs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher(verbs));
|
||||
return this;
|
||||
@@ -328,7 +328,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithParam(params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageParamMatcher(funcs));
|
||||
return this;
|
||||
@@ -363,7 +363,7 @@ namespace WireMock.RequestBuilders
|
||||
public IRequestBuilder WithHeader(string name, params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotEmpty(matchers, nameof(matchers));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, matchers));
|
||||
return this;
|
||||
@@ -376,7 +376,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(funcs));
|
||||
return this;
|
||||
@@ -403,7 +403,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithCookie(string name, params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotEmpty(matchers, nameof(matchers));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(name, matchers));
|
||||
return this;
|
||||
@@ -416,7 +416,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
|
||||
{
|
||||
Check.NotEmpty(funcs, nameof(funcs));
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(funcs));
|
||||
return this;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -8,11 +9,18 @@ namespace WireMock.ResponseBuilders
|
||||
public interface IProxyResponseBuilder : IStatusCodeResponseBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// With Proxy URL using X509Certificate2.
|
||||
/// WithProxy URL using Client X509Certificate2.
|
||||
/// </summary>
|
||||
/// <param name="proxyUrl">The proxy url.</param>
|
||||
/// <param name="clientX509Certificate2ThumbprintOrSubjectName">The X509Certificate2 file to use for client authentication.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithProxy([NotNull] string proxyUrl, [CanBeNull] string clientX509Certificate2ThumbprintOrSubjectName = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithProxy using IProxyAndRecordSettings.
|
||||
/// </summary>
|
||||
/// <param name="settings">The IProxyAndRecordSettings.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithProxy([NotNull] IProxyAndRecordSettings settings);
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Http;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Transformers;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
@@ -43,7 +44,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <summary>
|
||||
/// The client X509Certificate2 Thumbprint or SubjectName to use.
|
||||
/// </summary>
|
||||
public string X509Certificate2ThumbprintOrSubjectName { get; private set; }
|
||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response message.
|
||||
@@ -296,22 +297,25 @@ namespace WireMock.ResponseBuilders
|
||||
return WithDelay(TimeSpan.FromMilliseconds(milliseconds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With Proxy URL.
|
||||
/// </summary>
|
||||
/// <param name="proxyUrl">The proxy url.</param>
|
||||
/// <param name="clientX509Certificate2ThumbprintOrSubjectName">The X509Certificate2 file to use for client authentication.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(string, string)"/>
|
||||
public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null)
|
||||
{
|
||||
Check.NotEmpty(proxyUrl, nameof(proxyUrl));
|
||||
Check.NotNullOrEmpty(proxyUrl, nameof(proxyUrl));
|
||||
|
||||
ProxyUrl = proxyUrl;
|
||||
X509Certificate2ThumbprintOrSubjectName = clientX509Certificate2ThumbprintOrSubjectName;
|
||||
ClientX509Certificate2ThumbprintOrSubjectName = clientX509Certificate2ThumbprintOrSubjectName;
|
||||
_httpClientForProxy = HttpClientHelper.CreateHttpClient(clientX509Certificate2ThumbprintOrSubjectName);
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(IProxyAndRecordSettings)"/>
|
||||
public IResponseBuilder WithProxy(IProxyAndRecordSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
|
||||
return WithProxy(settings.Url, settings.ClientX509Certificate2ThumbprintOrSubjectName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The provide response.
|
||||
/// </summary>
|
||||
|
||||
@@ -37,6 +37,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as a json object.
|
||||
/// </summary>
|
||||
public object BodyAsJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as bytes.
|
||||
/// </summary>
|
||||
@@ -74,7 +79,7 @@ namespace WireMock
|
||||
/// <param name="values">The values.</param>
|
||||
public void AddHeader(string name, params string[] values)
|
||||
{
|
||||
Check.NotEmpty(values, nameof(values));
|
||||
Check.NotNullOrEmpty(values, nameof(values));
|
||||
|
||||
var newHeaderValues = Headers.TryGetValue(name, out WireMockList<string> existingValues)
|
||||
? values.Union(existingValues).ToArray()
|
||||
|
||||
@@ -97,6 +97,7 @@ namespace WireMock.Serialization
|
||||
mappingModel.Response.StatusCode = null;
|
||||
mappingModel.Response.Headers = null;
|
||||
mappingModel.Response.BodyDestination = null;
|
||||
mappingModel.Response.BodyAsJson = null;
|
||||
mappingModel.Response.Body = null;
|
||||
mappingModel.Response.BodyAsBytes = null;
|
||||
mappingModel.Response.BodyAsFile = null;
|
||||
@@ -110,6 +111,7 @@ namespace WireMock.Serialization
|
||||
mappingModel.Response.BodyDestination = response.ResponseMessage.BodyDestination;
|
||||
mappingModel.Response.StatusCode = response.ResponseMessage.StatusCode;
|
||||
mappingModel.Response.Headers = Map(response.ResponseMessage.Headers);
|
||||
mappingModel.Response.BodyAsJson = response.ResponseMessage.BodyAsJson;
|
||||
mappingModel.Response.Body = response.ResponseMessage.Body;
|
||||
mappingModel.Response.BodyAsBytes = response.ResponseMessage.BodyAsBytes;
|
||||
mappingModel.Response.BodyAsFile = response.ResponseMessage.BodyAsFile;
|
||||
@@ -150,7 +152,9 @@ namespace WireMock.Serialization
|
||||
private static MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers)
|
||||
{
|
||||
if (matchers == null || !matchers.Any())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return matchers.Select(Map).Where(x => x != null).ToArray();
|
||||
}
|
||||
@@ -158,7 +162,9 @@ namespace WireMock.Serialization
|
||||
private static MatcherModel Map([CanBeNull] IMatcher matcher)
|
||||
{
|
||||
if (matcher == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
|
||||
@@ -43,46 +43,7 @@ namespace WireMock.Server
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Reads the static mappings from a folder.
|
||||
/// </summary>
|
||||
/// <param name="folder">The optional folder. If not defined, use \__admin\mappings\</param>
|
||||
[PublicAPI]
|
||||
public void ReadStaticMappings([CanBeNull] string folder = null)
|
||||
{
|
||||
if (folder == null)
|
||||
folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
|
||||
|
||||
if (!Directory.Exists(folder))
|
||||
return;
|
||||
|
||||
foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f))
|
||||
{
|
||||
ReadStaticMapping(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads the static mapping.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
[PublicAPI]
|
||||
public void ReadStaticMapping([NotNull] string filename)
|
||||
{
|
||||
Check.NotNull(filename, nameof(filename));
|
||||
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
|
||||
|
||||
if (Guid.TryParse(filenameWithoutExtension, out var guidFromFilename))
|
||||
{
|
||||
DeserializeAndAddMapping(File.ReadAllText(filename), guidFromFilename);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeserializeAndAddMapping(File.ReadAllText(filename));
|
||||
}
|
||||
}
|
||||
|
||||
#region InitAdmin
|
||||
private void InitAdmin()
|
||||
{
|
||||
// __admin/settings
|
||||
@@ -129,13 +90,103 @@ namespace WireMock.Server
|
||||
// __admin/scenarios/reset
|
||||
Given(Request.Create().WithPath(AdminScenarios + "/reset").UsingPost()).RespondWith(new DynamicResponseProvider(ScenariosReset));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region StaticMappings
|
||||
/// <summary>
|
||||
/// Reads the static mappings from a folder.
|
||||
/// </summary>
|
||||
/// <param name="folder">The optional folder. If not defined, use \__admin\mappings\</param>
|
||||
[PublicAPI]
|
||||
public void ReadStaticMappings([CanBeNull] string folder = null)
|
||||
{
|
||||
if (folder == null)
|
||||
{
|
||||
folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string filename in Directory.EnumerateFiles(folder).OrderBy(f => f))
|
||||
{
|
||||
ReadStaticMappingAndAddOrUpdate(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Watches the static mappings for changes.
|
||||
/// </summary>
|
||||
/// <param name="folder">The optional folder. If not defined, use \__admin\mappings\</param>
|
||||
[PublicAPI]
|
||||
public void WatchStaticMappings([CanBeNull] string folder = null)
|
||||
{
|
||||
if (folder == null)
|
||||
{
|
||||
folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
|
||||
}
|
||||
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var watcher = new EnhancedFileSystemWatcher(folder, "*.json", 500);
|
||||
watcher.Created += (sender, args) =>
|
||||
{
|
||||
ReadStaticMappingAndAddOrUpdate(args.FullPath);
|
||||
};
|
||||
watcher.Changed += (sender, args) =>
|
||||
{
|
||||
ReadStaticMappingAndAddOrUpdate(args.FullPath);
|
||||
};
|
||||
watcher.Deleted += (sender, args) =>
|
||||
{
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(args.FullPath);
|
||||
|
||||
if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
||||
{
|
||||
DeleteMapping(guidFromFilename);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteMapping(args.FullPath);
|
||||
}
|
||||
};
|
||||
|
||||
watcher.EnableRaisingEvents = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a static mapping file and adds or updates the mapping.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
[PublicAPI]
|
||||
public void ReadStaticMappingAndAddOrUpdate([NotNull] string path)
|
||||
{
|
||||
Check.NotNull(path, nameof(path));
|
||||
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
if (Guid.TryParse(filenameWithoutExtension, out Guid guidFromFilename))
|
||||
{
|
||||
DeserializeAndAddOrUpdateMapping(FileHelper.ReadAllText(path), guidFromFilename, path);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeserializeAndAddOrUpdateMapping(FileHelper.ReadAllText(path), null, path);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Proxy and Record
|
||||
private HttpClient _httpClientForProxy;
|
||||
|
||||
private void InitProxyAndRecord(IProxyAndRecordSettings settings)
|
||||
{
|
||||
_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.X509Certificate2ThumbprintOrSubjectName);
|
||||
_httpClientForProxy = HttpClientHelper.CreateHttpClient(settings.ClientX509Certificate2ThumbprintOrSubjectName);
|
||||
Given(Request.Create().WithPath("/*").UsingAnyVerb()).RespondWith(new ProxyAsyncResponseProvider(ProxyAndRecordAsync, settings));
|
||||
}
|
||||
|
||||
@@ -149,7 +200,7 @@ namespace WireMock.Server
|
||||
|
||||
if (settings.SaveMapping)
|
||||
{
|
||||
var mapping = ToMapping(requestMessage, responseMessage);
|
||||
var mapping = ToMapping(requestMessage, responseMessage, settings.BlackListedHeaders ?? new string[] { });
|
||||
_options.Mappings.Add(mapping);
|
||||
|
||||
if (settings.SaveMappingToFile)
|
||||
@@ -161,16 +212,23 @@ namespace WireMock.Server
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
private Mapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage)
|
||||
private Mapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] blacklistedHeaders)
|
||||
{
|
||||
var request = Request.Create();
|
||||
request.WithPath(requestMessage.Path);
|
||||
request.UsingVerb(requestMessage.Method);
|
||||
|
||||
requestMessage.Query.Loop((key, value) => request.WithParam(key, value.ToArray()));
|
||||
requestMessage.Headers.Loop((key, value) => request.WithHeader(key, value.ToArray()));
|
||||
requestMessage.Cookies.Loop((key, value) => request.WithCookie(key, value));
|
||||
|
||||
requestMessage.Headers.Loop((key, value) =>
|
||||
{
|
||||
if (!blacklistedHeaders.Any(b => string.Equals(key, b, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
request.WithHeader(key, value.ToArray());
|
||||
}
|
||||
});
|
||||
|
||||
if (requestMessage.Body != null)
|
||||
{
|
||||
request.WithBody(new ExactMatcher(requestMessage.Body));
|
||||
@@ -178,7 +236,7 @@ namespace WireMock.Server
|
||||
|
||||
var response = Response.Create(responseMessage);
|
||||
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, request, response, 0, null, null, null);
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, null, request, response, 0, null, null, null);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -221,7 +279,9 @@ namespace WireMock.Server
|
||||
var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
|
||||
|
||||
if (mapping == null)
|
||||
{
|
||||
return new ResponseMessage { StatusCode = 404, Body = "Mapping not found" };
|
||||
}
|
||||
|
||||
var model = MappingConverter.ToMappingModel(mapping);
|
||||
|
||||
@@ -231,23 +291,8 @@ namespace WireMock.Server
|
||||
private ResponseMessage MappingPut(RequestMessage requestMessage)
|
||||
{
|
||||
Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));
|
||||
var mappingModel = JsonConvert.DeserializeObject<MappingModel>(requestMessage.Body);
|
||||
|
||||
if (mappingModel.Request == null)
|
||||
return new ResponseMessage { StatusCode = 400, Body = "Request missing" };
|
||||
|
||||
if (mappingModel.Response == null)
|
||||
return new ResponseMessage { StatusCode = 400, Body = "Response missing" };
|
||||
|
||||
var requestBuilder = InitRequestBuilder(mappingModel.Request);
|
||||
var responseBuilder = InitResponseBuilder(mappingModel.Response);
|
||||
|
||||
IRespondWithAProvider respondProvider = Given(requestBuilder).WithGuid(guid);
|
||||
|
||||
if (!string.IsNullOrEmpty(mappingModel.Title))
|
||||
respondProvider = respondProvider.WithTitle(mappingModel.Title);
|
||||
|
||||
respondProvider.RespondWith(responseBuilder);
|
||||
DeserializeAndAddOrUpdateMapping(requestMessage.Body, guid);
|
||||
|
||||
return new ResponseMessage { Body = "Mapping added or updated" };
|
||||
}
|
||||
@@ -257,7 +302,9 @@ namespace WireMock.Server
|
||||
Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminMappings.Length + 1));
|
||||
|
||||
if (DeleteMapping(guid))
|
||||
{
|
||||
return new ResponseMessage { Body = "Mapping removed" };
|
||||
}
|
||||
|
||||
return new ResponseMessage { Body = "Mapping not found" };
|
||||
}
|
||||
@@ -278,7 +325,9 @@ namespace WireMock.Server
|
||||
{
|
||||
string folder = Path.Combine(Directory.GetCurrentDirectory(), AdminMappingsFolder);
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
|
||||
var model = MappingConverter.ToMappingModel(mapping);
|
||||
string json = JsonConvert.SerializeObject(model, _settings);
|
||||
@@ -308,7 +357,7 @@ namespace WireMock.Server
|
||||
{
|
||||
try
|
||||
{
|
||||
DeserializeAndAddMapping(requestMessage.Body);
|
||||
DeserializeAndAddOrUpdateMapping(requestMessage.Body);
|
||||
}
|
||||
catch (ArgumentException a)
|
||||
{
|
||||
@@ -322,7 +371,7 @@ namespace WireMock.Server
|
||||
return new ResponseMessage { StatusCode = 201, Body = "Mapping added" };
|
||||
}
|
||||
|
||||
private void DeserializeAndAddMapping(string json, Guid? guid = null)
|
||||
private void DeserializeAndAddOrUpdateMapping(string json, Guid? guid = null, string path = null)
|
||||
{
|
||||
var mappingModel = JsonConvert.DeserializeObject<MappingModel>(json);
|
||||
|
||||
@@ -344,11 +393,20 @@ namespace WireMock.Server
|
||||
respondProvider = respondProvider.WithGuid(mappingModel.Guid.Value);
|
||||
}
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
respondProvider = respondProvider.WithPath(path);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(mappingModel.Title))
|
||||
{
|
||||
respondProvider = respondProvider.WithTitle(mappingModel.Title);
|
||||
}
|
||||
|
||||
if (mappingModel.Priority != null)
|
||||
{
|
||||
respondProvider = respondProvider.AtPriority(mappingModel.Priority.Value);
|
||||
}
|
||||
|
||||
if (mappingModel.Scenario != null)
|
||||
{
|
||||
@@ -681,7 +739,7 @@ namespace WireMock.Server
|
||||
{
|
||||
Body = JsonConvert.SerializeObject(result, _settings),
|
||||
StatusCode = 200,
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { "Content-Type", new WireMockList<string>("application/json") } }
|
||||
Headers = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string>("application/json") } }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace WireMock.Server
|
||||
public partial class FluentMockServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Log entries notification handler
|
||||
/// Occurs when [log entries changed].
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public event NotifyCollectionChangedEventHandler LogEntriesChanged
|
||||
@@ -66,7 +66,7 @@ namespace WireMock.Server
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the mapping.
|
||||
/// Deletes a LogEntry.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
[PublicAPI]
|
||||
@@ -83,4 +83,4 @@ namespace WireMock.Server
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ using WireMock.RequestBuilders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using WireMock.Owin;
|
||||
using WireMock.Serialization;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -93,7 +94,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static FluentMockServer Start(params string[] urls)
|
||||
{
|
||||
Check.NotEmpty(urls, nameof(urls));
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new FluentMockServer(new FluentMockServerSettings
|
||||
{
|
||||
@@ -126,7 +127,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static FluentMockServer StartWithAdminInterface(params string[] urls)
|
||||
{
|
||||
Check.NotEmpty(urls, nameof(urls));
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new FluentMockServer(new FluentMockServerSettings
|
||||
{
|
||||
@@ -143,7 +144,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static FluentMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls)
|
||||
{
|
||||
Check.NotEmpty(urls, nameof(urls));
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new FluentMockServer(new FluentMockServerSettings
|
||||
{
|
||||
@@ -157,7 +158,7 @@ namespace WireMock.Server
|
||||
{
|
||||
if (settings.Urls != null)
|
||||
{
|
||||
Urls = settings.Urls;
|
||||
Urls = settings.Urls.Select(u => u.EndsWith("/") ? u : $"{u}/").ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -202,6 +203,11 @@ namespace WireMock.Server
|
||||
ReadStaticMappings();
|
||||
}
|
||||
|
||||
if (settings.WatchStaticMappings == true)
|
||||
{
|
||||
WatchStaticMappings();
|
||||
}
|
||||
|
||||
if (settings.ProxyAndRecordSettings != null)
|
||||
{
|
||||
InitProxyAndRecord(settings.ProxyAndRecordSettings);
|
||||
@@ -274,7 +280,18 @@ namespace WireMock.Server
|
||||
public bool DeleteMapping(Guid guid)
|
||||
{
|
||||
// Check a mapping exists with the same GUID, if so, remove it.
|
||||
var existingMapping = _options.Mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
return DeleteMapping(m => m.Guid == guid);
|
||||
}
|
||||
|
||||
private bool DeleteMapping(string path)
|
||||
{
|
||||
// Check a mapping exists with the same path, if so, remove it.
|
||||
return DeleteMapping(m => string.Equals(m.Path, path, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private bool DeleteMapping(Func<Mapping, bool> predicate)
|
||||
{
|
||||
var existingMapping = _options.Mappings.FirstOrDefault(predicate);
|
||||
if (existingMapping != null)
|
||||
{
|
||||
_options.Mappings.Remove(existingMapping);
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace WireMock.Server
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithTitle(string title);
|
||||
|
||||
/// <summary>
|
||||
/// Define the full filepath for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="path">The full filepath.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithPath(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Define a unique identifier for this mapping.
|
||||
/// </summary>
|
||||
|
||||
@@ -11,18 +11,11 @@ namespace WireMock.Server
|
||||
private int _priority;
|
||||
private Guid? _guid;
|
||||
private string _title;
|
||||
private string _path;
|
||||
private object _executionConditionState;
|
||||
private object _nextState;
|
||||
private string _scenario;
|
||||
|
||||
/// <summary>
|
||||
/// The _registration callback.
|
||||
/// </summary>
|
||||
private readonly RegistrationCallback _registrationCallback;
|
||||
|
||||
/// <summary>
|
||||
/// The _request matcher.
|
||||
/// </summary>
|
||||
private readonly IRequestMatcher _requestMatcher;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,30 +32,20 @@ namespace WireMock.Server
|
||||
/// <summary>
|
||||
/// The respond with.
|
||||
/// </summary>
|
||||
/// <param name="provider">
|
||||
/// The provider.
|
||||
/// </param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
public void RespondWith(IResponseProvider provider)
|
||||
{
|
||||
var mappingGuid = _guid ?? Guid.NewGuid();
|
||||
_registrationCallback(new Mapping(mappingGuid, _title, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
|
||||
_registrationCallback(new Mapping(mappingGuid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define a unique identifier for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
||||
public IRespondWithAProvider WithGuid(string guid)
|
||||
{
|
||||
return WithGuid(Guid.Parse(guid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define a unique identifier for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
|
||||
public IRespondWithAProvider WithGuid(Guid guid)
|
||||
{
|
||||
_guid = guid;
|
||||
@@ -70,11 +53,7 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define a unique identifier for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="title">The unique identifier.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
/// <see cref="IRespondWithAProvider.WithTitle"/>
|
||||
public IRespondWithAProvider WithTitle(string title)
|
||||
{
|
||||
_title = title;
|
||||
@@ -82,11 +61,15 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Define the priority for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="priority">The priority.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
/// <see cref="IRespondWithAProvider.WithPath"/>
|
||||
public IRespondWithAProvider WithPath(string path)
|
||||
{
|
||||
_path = path;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.AtPriority"/>
|
||||
public IRespondWithAProvider AtPriority(int priority)
|
||||
{
|
||||
_priority = priority;
|
||||
@@ -94,6 +77,7 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.InScenario(string)"/>
|
||||
public IRespondWithAProvider InScenario(string scenario)
|
||||
{
|
||||
_scenario = scenario;
|
||||
@@ -101,6 +85,7 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WhenStateIs"/>
|
||||
public IRespondWithAProvider WhenStateIs(object state)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_scenario))
|
||||
@@ -118,6 +103,7 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WillSetStateTo"/>
|
||||
public IRespondWithAProvider WillSetStateTo(object state)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_scenario))
|
||||
|
||||
@@ -25,6 +25,10 @@ namespace WireMock.Settings
|
||||
[PublicAPI]
|
||||
public bool? ReadStaticMappings { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IFluentMockServerSettings.WatchStaticMappings"/>
|
||||
[PublicAPI]
|
||||
public bool? WatchStaticMappings { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IFluentMockServerSettings.ProxyAndRecordSettings"/>
|
||||
[PublicAPI]
|
||||
public IProxyAndRecordSettings ProxyAndRecordSettings { get; set; }
|
||||
|
||||
@@ -28,6 +28,11 @@ namespace WireMock.Settings
|
||||
/// </summary>
|
||||
bool? ReadStaticMappings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Watch the static mapping files + folder for changes when running.
|
||||
/// </summary>
|
||||
bool? WatchStaticMappings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the proxy and record settings.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// IRecordAndSaveSettings
|
||||
/// IProxyAndRecordSettings
|
||||
/// </summary>
|
||||
public interface IProxyAndRecordSettings
|
||||
{
|
||||
@@ -21,8 +21,14 @@
|
||||
bool SaveMappingToFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The clientCertificate thumbprint or subject name fragment to use. Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
||||
/// The clientCertificate thumbprint or subject name fragment to use.
|
||||
/// Example thumbprint : "D2DBF135A8D06ACCD0E1FAD9BFB28678DF7A9818". Example subject name: "www.google.com""
|
||||
/// </summary>
|
||||
string X509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines a list from headers which will excluded from the saved mappings.
|
||||
/// </summary>
|
||||
string[] BlackListedHeaders { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// RecordAndSaveSettings
|
||||
/// ProxyAndRecordSettings
|
||||
/// </summary>
|
||||
public class ProxyAndRecordSettings : IProxyAndRecordSettings
|
||||
{
|
||||
@@ -19,8 +19,12 @@ namespace WireMock.Settings
|
||||
[PublicAPI]
|
||||
public bool SaveMappingToFile { get; set; } = true;
|
||||
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.X509Certificate2ThumbprintOrSubjectName"/>
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.ClientX509Certificate2ThumbprintOrSubjectName"/>
|
||||
[PublicAPI]
|
||||
public string X509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IProxyAndRecordSettings.BlackListedHeaders"/>
|
||||
[PublicAPI]
|
||||
public string[] BlackListedHeaders { get; set; }
|
||||
}
|
||||
}
|
||||
265
src/WireMock.Net/Util/EnhancedFileSystemWatcher.cs
Normal file
265
src/WireMock.Net/Util/EnhancedFileSystemWatcher.cs
Normal file
@@ -0,0 +1,265 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
/// <summary>
|
||||
/// An EnhancedFileSystemWatcher, which can be used to suppress duplicate events that fire on a single change to the file.
|
||||
/// </summary>
|
||||
/// <seealso cref="System.IO.FileSystemWatcher" />
|
||||
/// <seealso cref="System.IDisposable" />
|
||||
public class EnhancedFileSystemWatcher : FileSystemWatcher, IDisposable
|
||||
{
|
||||
#region Private Members
|
||||
// Default Watch Interval in Milliseconds
|
||||
private const int DefaultWatchInterval = 100;
|
||||
|
||||
// This Dictionary keeps the track of when an event occured last for a particular file
|
||||
private ConcurrentDictionary<string, DateTime> _lastFileEvent;
|
||||
|
||||
// Watch Interval in Milliseconds
|
||||
private int _interval;
|
||||
|
||||
// Timespan created when interval is set
|
||||
private TimeSpan _recentTimeSpan;
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
/// <summary>
|
||||
/// Interval, in milliseconds, within which events are considered "recent".
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public int Interval
|
||||
{
|
||||
get => _interval;
|
||||
set
|
||||
{
|
||||
_interval = value;
|
||||
|
||||
// Set timespan based on the value passed
|
||||
_recentTimeSpan = new TimeSpan(0, 0, 0, 0, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows user to set whether to filter recent events.
|
||||
/// If this is set a false, this class behaves like System.IO.FileSystemWatcher class.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public bool FilterRecentEvents { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnhancedFileSystemWatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="interval">The interval.</param>
|
||||
public EnhancedFileSystemWatcher(int interval = DefaultWatchInterval)
|
||||
{
|
||||
Check.Condition(interval, i => i >= 0, nameof(interval));
|
||||
|
||||
InitializeMembers(interval);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnhancedFileSystemWatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="path">The directory to monitor, in standard or Universal Naming Convention (UNC) notation.</param>
|
||||
/// <param name="interval">The interval.</param>
|
||||
public EnhancedFileSystemWatcher([NotNull] string path, int interval = DefaultWatchInterval) : base(path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Check.Condition(interval, i => i >= 0, nameof(interval));
|
||||
|
||||
InitializeMembers(interval);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnhancedFileSystemWatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="path">The directory to monitor, in standard or Universal Naming Convention (UNC) notation.</param>
|
||||
/// <param name="filter">The type of files to watch. For example, "*.txt" watches for changes to all text files.</param>
|
||||
/// <param name="interval">The interval.</param>
|
||||
public EnhancedFileSystemWatcher([NotNull] string path, [NotNull] string filter, int interval = DefaultWatchInterval) : base(path, filter)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Check.NotNullOrEmpty(filter, nameof(filter));
|
||||
Check.Condition(interval, i => i >= 0, nameof(interval));
|
||||
|
||||
InitializeMembers(interval);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
// These events hide the events from the base class.
|
||||
// We want to raise these events appropriately and we do not want the
|
||||
// users of this class subscribing to these events of the base class accidentally
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a file or directory in the specified <see cref="P:System.IO.FileSystemWatcher.Path" /> is changed.
|
||||
/// </summary>
|
||||
public new event FileSystemEventHandler Changed;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a file or directory in the specified <see cref="P:System.IO.FileSystemWatcher.Path" /> is created.
|
||||
/// </summary>
|
||||
public new event FileSystemEventHandler Created;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a file or directory in the specified <see cref="P:System.IO.FileSystemWatcher.Path" /> is deleted.
|
||||
/// </summary>
|
||||
public new event FileSystemEventHandler Deleted;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a file or directory in the specified <see cref="P:System.IO.FileSystemWatcher.Path" /> is renamed.
|
||||
/// </summary>
|
||||
public new event RenamedEventHandler Renamed;
|
||||
#endregion
|
||||
|
||||
#region Protected Methods to raise the Events for this class
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.IO.FileSystemWatcher.Changed" /> event.
|
||||
/// </summary>
|
||||
/// <param name="e">A <see cref="T:System.IO.FileSystemEventArgs" /> that contains the event data.</param>
|
||||
protected new virtual void OnChanged(FileSystemEventArgs e)
|
||||
{
|
||||
Changed?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.IO.FileSystemWatcher.Created" /> event.
|
||||
/// </summary>
|
||||
/// <param name="e">A <see cref="T:System.IO.FileSystemEventArgs" /> that contains the event data.</param>
|
||||
protected new virtual void OnCreated(FileSystemEventArgs e)
|
||||
{
|
||||
Created?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.IO.FileSystemWatcher.Deleted" /> event.
|
||||
/// </summary>
|
||||
/// <param name="e">A <see cref="T:System.IO.FileSystemEventArgs" /> that contains the event data.</param>
|
||||
protected new virtual void OnDeleted(FileSystemEventArgs e)
|
||||
{
|
||||
Deleted?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="E:System.IO.FileSystemWatcher.Renamed" /> event.
|
||||
/// </summary>
|
||||
/// <param name="e">A <see cref="T:System.IO.RenamedEventArgs" /> that contains the event data.</param>
|
||||
protected new virtual void OnRenamed(RenamedEventArgs e)
|
||||
{
|
||||
Renamed?.Invoke(this, e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
/// <summary>
|
||||
/// This Method Initializes the private members.
|
||||
/// Interval is set to its default value of 100 millisecond.
|
||||
/// FilterRecentEvents is set to true, _lastFileEvent dictionary is initialized.
|
||||
/// We subscribe to the base class events.
|
||||
/// </summary>
|
||||
private void InitializeMembers(int interval = 100)
|
||||
{
|
||||
Interval = interval;
|
||||
FilterRecentEvents = true;
|
||||
_lastFileEvent = new ConcurrentDictionary<string, DateTime>();
|
||||
|
||||
base.Created += OnCreated;
|
||||
base.Changed += OnChanged;
|
||||
base.Deleted += OnDeleted;
|
||||
base.Renamed += OnRenamed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method searches the dictionary to find out when the last event occured
|
||||
/// for a particular file. If that event occured within the specified timespan
|
||||
/// it returns true, else false
|
||||
/// </summary>
|
||||
/// <param name="fileName">The filename to be checked</param>
|
||||
/// <returns>True if an event has occured within the specified interval, False otherwise</returns>
|
||||
private bool HasAnotherFileEventOccuredRecently(string fileName)
|
||||
{
|
||||
// Check dictionary only if user wants to filter recent events otherwise return value stays false.
|
||||
if (!FilterRecentEvents)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool retVal = false;
|
||||
if (_lastFileEvent.ContainsKey(fileName))
|
||||
{
|
||||
// If dictionary contains the filename, check how much time has elapsed
|
||||
// since the last event occured. If the timespan is less that the
|
||||
// specified interval, set return value to true
|
||||
// and store current datetime in dictionary for this file
|
||||
DateTime lastEventTime = _lastFileEvent[fileName];
|
||||
DateTime currentTime = DateTime.Now;
|
||||
TimeSpan timeSinceLastEvent = currentTime - lastEventTime;
|
||||
retVal = timeSinceLastEvent < _recentTimeSpan;
|
||||
_lastFileEvent[fileName] = currentTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If dictionary does not contain the filename,
|
||||
// no event has occured in past for this file, so set return value to false
|
||||
// and append filename along with current datetime to the dictionary
|
||||
_lastFileEvent.TryAdd(fileName, DateTime.Now);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#region FileSystemWatcher EventHandlers
|
||||
// Base class Event Handlers. Check if an event has occured recently and call method
|
||||
// to raise appropriate event only if no recent event is detected
|
||||
private void OnChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
{
|
||||
OnChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCreated(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
{
|
||||
OnCreated(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDeleted(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
{
|
||||
OnDeleted(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRenamed(object sender, RenamedEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.OldFullPath))
|
||||
{
|
||||
OnRenamed(e);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region IDisposable Members
|
||||
/// <summary>
|
||||
/// Releases all resources used by the <see cref="T:System.ComponentModel.Component" />.
|
||||
/// </summary>
|
||||
public new void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
29
src/WireMock.Net/Util/FileHelper.cs
Normal file
29
src/WireMock.Net/Util/FileHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
internal static class FileHelper
|
||||
{
|
||||
private const int NumberOfRetries = 3;
|
||||
private const int DelayOnRetry = 500;
|
||||
|
||||
public static string ReadAllText(string path)
|
||||
{
|
||||
for (int i = 1; i <= NumberOfRetries; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// You may check error code to filter some exceptions, not every error can be recovered.
|
||||
Thread.Sleep(DelayOnRetry);
|
||||
}
|
||||
}
|
||||
|
||||
throw new IOException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (!condition(value))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentOutOfRangeException(parameterName);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Validation
|
||||
{
|
||||
if (ReferenceEquals(value, null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentNullException(parameterName);
|
||||
}
|
||||
@@ -45,15 +45,12 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static T NotNull<T>(
|
||||
[NoEnumeration] T value,
|
||||
[InvokerParameterName] [NotNull] string parameterName,
|
||||
[NotNull] string propertyName)
|
||||
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName, [NotNull] string propertyName)
|
||||
{
|
||||
if (ReferenceEquals(value, null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotEmpty(propertyName, nameof(propertyName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(propertyName, nameof(propertyName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
|
||||
}
|
||||
@@ -62,13 +59,13 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
public static IList<T> NotNullOrEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
{
|
||||
NotNull(value, parameterName);
|
||||
|
||||
if (value.Count == 0)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
|
||||
}
|
||||
@@ -77,7 +74,7 @@ namespace WireMock.Validation
|
||||
}
|
||||
|
||||
[ContractAnnotation("value:null => halt")]
|
||||
public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
public static string NotNullOrEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||
{
|
||||
Exception e = null;
|
||||
if (ReferenceEquals(value, null))
|
||||
@@ -91,7 +88,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (e != null)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw e;
|
||||
}
|
||||
@@ -104,7 +101,7 @@ namespace WireMock.Validation
|
||||
if (!ReferenceEquals(value, null)
|
||||
&& (value.Length == 0))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
|
||||
}
|
||||
@@ -119,7 +116,7 @@ namespace WireMock.Validation
|
||||
|
||||
if (value.Any(e => e == null))
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(parameterName);
|
||||
}
|
||||
@@ -131,7 +128,7 @@ namespace WireMock.Validation
|
||||
{
|
||||
if (!value.GetTypeInfo().IsClass)
|
||||
{
|
||||
NotEmpty(parameterName, nameof(parameterName));
|
||||
NotNullOrEmpty(parameterName, nameof(parameterName));
|
||||
|
||||
throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
// copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
|
||||
namespace WireMock.Validation
|
||||
@@ -11,33 +9,33 @@ namespace WireMock.Validation
|
||||
/// <summary>
|
||||
/// The property '{property}' of the argument '{argument}' cannot be null.
|
||||
/// </summary>
|
||||
public static string ArgumentPropertyNull([CanBeNull] string property, [CanBeNull] string argument)
|
||||
public static string ArgumentPropertyNull(string property, string argument)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The property '{property}' of the argument '{argument}' cannot be null.", property, argument);
|
||||
return $"The property '{property}' of the argument '{argument}' cannot be null.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The string argument '{argumentName}' cannot be empty.
|
||||
/// </summary>
|
||||
public static string ArgumentIsEmpty([CanBeNull] string argumentName)
|
||||
public static string ArgumentIsEmpty(string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The string argument '{argumentName}' cannot be empty.", argumentName);
|
||||
return $"The string argument '{argumentName}' cannot be empty.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.
|
||||
/// </summary>
|
||||
public static string InvalidEntityType([CanBeNull] Type type, [CanBeNull] string argumentName)
|
||||
public static string InvalidEntityType(Type type, string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.", type, argumentName);
|
||||
return $"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The collection argument '{argumentName}' must contain at least one element.
|
||||
/// </summary>
|
||||
public static string CollectionArgumentIsEmpty([CanBeNull] string argumentName)
|
||||
public static string CollectionArgumentIsEmpty(string argumentName)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, $"The collection argument '{argumentName}' must contain at least one element.", argumentName);
|
||||
return $"The collection argument '{argumentName}' must contain at least one element.";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,29 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||
<Version>1.0.2.13</Version>
|
||||
<Version>1.0.3</Version>
|
||||
<Authors>Alexandre Victoor;Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<AssemblyName>WireMock.Net</AssemblyName>
|
||||
<PackageId>WireMock.Net</PackageId>
|
||||
<PackageTags>tdd;mock;http;wiremock;test;server;unittest</PackageTags>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/LICENSE</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/WireMock-Net/WireMock.Net</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
<RootNamespace>WireMock</RootNamespace>
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugType>full</DebugType>
|
||||
<IncludeSource>True</IncludeSource>
|
||||
<IncludeSymbols>True</IncludeSymbols>
|
||||
<PathMap>$(MSBuildProjectDirectory)=/</PathMap>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard2.0'">
|
||||
@@ -29,14 +33,15 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="10.4.0">
|
||||
<PackageReference Include="JetBrains.Annotations" Version="11.1.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Handlebars.Net" Version="1.9.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.4" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.3" />
|
||||
<PackageReference Include="RestEase" Version="1.4.4" />
|
||||
<!--<PackageReference Include="OpenSSL.X509Certificate2.Provider" Version="1.0.2" />-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
|
||||
@@ -52,6 +57,7 @@
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.1.3" />
|
||||
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
|
||||
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -17,7 +19,7 @@ namespace WireMock.Net.Tests
|
||||
private FluentMockServer _serverForProxyForwarding;
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_proxy_responses()
|
||||
public async Task FluentMockServer_Proxy_Should_proxy_responses()
|
||||
{
|
||||
// given
|
||||
_server = FluentMockServer.Start();
|
||||
@@ -33,7 +35,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_request()
|
||||
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_request()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
@@ -41,7 +43,16 @@ namespace WireMock.Net.Tests
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create());
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
var settings = new FluentMockServerSettings
|
||||
{
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = _serverForProxyForwarding.Urls[0],
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false
|
||||
}
|
||||
};
|
||||
_server = FluentMockServer.Start(settings);
|
||||
_server
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0]));
|
||||
@@ -54,6 +65,7 @@ namespace WireMock.Net.Tests
|
||||
Content = new StringContent("stringContent")
|
||||
};
|
||||
requestMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
|
||||
requestMessage.Content.Headers.Add("bbb", "test");
|
||||
await new HttpClient().SendAsync(requestMessage);
|
||||
|
||||
// then
|
||||
@@ -61,10 +73,58 @@ namespace WireMock.Net.Tests
|
||||
Check.That(receivedRequest.Body).IsEqualTo("stringContent");
|
||||
Check.That(receivedRequest.Headers).ContainsKey("Content-Type");
|
||||
Check.That(receivedRequest.Headers["Content-Type"]).ContainsExactly("text/plain");
|
||||
Check.That(receivedRequest.Headers).ContainsKey("bbb");
|
||||
|
||||
var mapping = _server.Mappings.Last();
|
||||
var matcher = ((Request) mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().FirstOrDefault(m => m.Name == "bbb");
|
||||
Check.That(matcher).IsNotNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_request_with_empty_content()
|
||||
public async Task FluentMockServer_Proxy_Should_exclude_blacklisted_content_header_in_mapping()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
_serverForProxyForwarding
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create());
|
||||
|
||||
var settings = new FluentMockServerSettings
|
||||
{
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = _serverForProxyForwarding.Urls[0],
|
||||
SaveMapping = true,
|
||||
SaveMappingToFile = false,
|
||||
BlackListedHeaders = new[] { "bbb" }
|
||||
}
|
||||
};
|
||||
_server = FluentMockServer.Start(settings);
|
||||
_server
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create());
|
||||
|
||||
// when
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(_server.Urls[0]),
|
||||
Content = new StringContent("stringContent")
|
||||
};
|
||||
requestMessage.Content.Headers.Add("bbb", "test");
|
||||
await new HttpClient().SendAsync(requestMessage);
|
||||
|
||||
// then
|
||||
var receivedRequest = _serverForProxyForwarding.LogEntries.First().RequestMessage;
|
||||
Check.That(receivedRequest.Headers).ContainsKey("bbb");
|
||||
|
||||
var mapping = _server.Mappings.Last();
|
||||
var matcher = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().FirstOrDefault(m => m.Name == "bbb");
|
||||
Check.That(matcher).IsNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_request_with_empty_content()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
@@ -95,7 +155,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_preserve_content_header_in_proxied_response()
|
||||
public async Task FluentMockServer_Proxy_Should_preserve_content_header_in_proxied_response()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
@@ -125,7 +185,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_change_absolute_location_header_in_proxied_response()
|
||||
public async Task FluentMockServer_Proxy_Should_change_absolute_location_header_in_proxied_response()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
@@ -155,7 +215,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_preserve_cookie_header_in_proxied_request()
|
||||
public async Task FluentMockServer_Proxy_Should_preserve_cookie_header_in_proxied_request()
|
||||
{
|
||||
// given
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
@@ -184,5 +244,35 @@ namespace WireMock.Net.Tests
|
||||
Check.That(receivedRequest.Cookies).IsNotNull();
|
||||
Check.That(receivedRequest.Cookies).ContainsPair("name", "value");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Proxy_Should_set_BodyAsJson_in_proxied_response()
|
||||
{
|
||||
// Assign
|
||||
_serverForProxyForwarding = FluentMockServer.Start();
|
||||
_serverForProxyForwarding
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create()
|
||||
.WithBodyAsJson(new { i = 42 })
|
||||
.WithHeader("Content-Type", "application/json; charset=utf-8"));
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
_server
|
||||
.Given(Request.Create().WithPath("/*"))
|
||||
.RespondWith(Response.Create().WithProxy(_serverForProxyForwarding.Urls[0]));
|
||||
|
||||
// Act
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(_server.Urls[0])
|
||||
};
|
||||
var response = await new HttpClient().SendAsync(requestMessage);
|
||||
|
||||
// Assert
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
Check.That(content).IsEqualTo("{\"i\":42}");
|
||||
Check.That(response.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace WireMock.Net.Tests
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", "documentdb_root.json");
|
||||
_server.ReadStaticMapping(folder);
|
||||
_server.ReadStaticMappingAndAddOrUpdate(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(1);
|
||||
@@ -65,7 +65,7 @@ namespace WireMock.Net.Tests
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
|
||||
_server.ReadStaticMapping(folder);
|
||||
_server.ReadStaticMappingAndAddOrUpdate(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(1);
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace WireMock.Net.Tests
|
||||
private FluentMockServer _server;
|
||||
|
||||
[Fact]
|
||||
public async void Test()
|
||||
public async void FluentMockServer_LogEntriesChanged()
|
||||
{
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
@@ -41,9 +41,9 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ParallelTest()
|
||||
public async Task FluentMockServer_LogEntriesChanged_Parallel()
|
||||
{
|
||||
var expectedCount = 100;
|
||||
int expectedCount = 10;
|
||||
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
@@ -65,11 +65,11 @@ namespace WireMock.Net.Tests
|
||||
var listOfTasks = new List<Task<HttpResponseMessage>>();
|
||||
for (var i = 0; i < expectedCount; i++)
|
||||
{
|
||||
Thread.Sleep(3);
|
||||
listOfTasks.Add(http.GetAsync(_server.Urls[0] + $"/foo"));
|
||||
Thread.Sleep(100);
|
||||
listOfTasks.Add(http.GetAsync($"{_server.Urls[0]}/foo"));
|
||||
}
|
||||
var responses = await Task.WhenAll(listOfTasks);
|
||||
var countResponsesWithStatusNotOk = responses.Where(r => r.StatusCode != HttpStatusCode.OK).Count();
|
||||
var countResponsesWithStatusNotOk = responses.Count(r => r.StatusCode != HttpStatusCode.OK);
|
||||
|
||||
// Assert
|
||||
Check.That(countResponsesWithStatusNotOk).Equals(0);
|
||||
@@ -81,4 +81,4 @@ namespace WireMock.Net.Tests
|
||||
_server?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
test/WireMock.Net.Tests/RequestCookieTests.cs
Normal file
28
test/WireMock.Net.Tests/RequestCookieTests.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestCookieTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Request_WithCookie_OK()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithCookie("session", "a*");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, null, null, new Dictionary<string, string> { { "session", "abc" } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,85 +4,14 @@ using System.Text;
|
||||
using NFluent;
|
||||
using Xunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
//[TestFixture]
|
||||
public partial class RequestTests
|
||||
public class RequestTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_paths()
|
||||
{
|
||||
var requestBuilder = Request.Create().WithPath("/x1", "/x2");
|
||||
|
||||
var request1 = new RequestMessage(new Uri("http://localhost/x1"), "blabla", ClientIp);
|
||||
var request2 = new RequestMessage(new Uri("http://localhost/x2"), "blabla", ClientIp);
|
||||
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request1, requestMatchResult)).IsEqualTo(1.0);
|
||||
Check.That(requestBuilder.GetMatchingScore(request2, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_pathFuncs()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath(url => url.EndsWith("/foo"));
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_prefix()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath(new RegexMatcher("^/foo"));
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_path()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||
{
|
||||
@@ -97,22 +26,6 @@ namespace WireMock.Net.Tests
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_headers()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||
|
||||
// when
|
||||
string bodyAsString = "whatever";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_headers()
|
||||
{
|
||||
@@ -161,19 +74,7 @@ namespace WireMock.Net.Tests
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_cookies()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithCookie("session", "a*");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, null, null, new Dictionary<string, string> { { "session", "abc" } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body()
|
||||
@@ -191,192 +92,7 @@ namespace WireMock.Net.Tests
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_ExactMatcher_true()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "cat";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_ExactMatcher_multiplePatterns()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat", "dog"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "cat";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_ExactMatcher_false()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "caR";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_SimMetricsMatcher1()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
|
||||
|
||||
// when
|
||||
string bodyAsString = "The car drives in the street.";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_SimMetricsMatcher2()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_WildcardMatcher()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello world!";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "X-toto", new[] { "tatata" } } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_RegexMatcher()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello world!";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_XPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
||||
|
||||
// when
|
||||
string xmlBodyAsString = @"
|
||||
<todo-list>
|
||||
<todo-item id='a1'>abc</todo-item>
|
||||
<todo-item id='a2'>def</todo-item>
|
||||
<todo-item id='a3'>xyz</todo-item>
|
||||
</todo-list>";
|
||||
byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, xmlBodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_XPathMatcher_false()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
||||
|
||||
// when
|
||||
string xmlBodyAsString = @"
|
||||
<todo-list>
|
||||
<todo-item id='a1'>abc</todo-item>
|
||||
<todo-item id='a2'>def</todo-item>
|
||||
<todo-item id='a3'>xyz</todo-item>
|
||||
</todo-list>";
|
||||
byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, xmlBodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_body_using_JsonPathMatcher_false()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Should_exclude_requests_not_matching_given_body()
|
||||
{
|
||||
|
||||
202
test/WireMock.Net.Tests/RequestWithBodyTests.cs
Normal file
202
test/WireMock.Net.Tests/RequestWithBodyTests.cs
Normal file
@@ -0,0 +1,202 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestWithBodyTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyExactMatcher()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "cat";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyExactMatcher_multiplePatterns()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat", "dog"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "cat";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyExactMatcher_false()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new ExactMatcher("cat"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "caR";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodySimMetricsMatcher1()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
|
||||
|
||||
// when
|
||||
string bodyAsString = "The car drives in the street.";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(1.0).And.IsStrictlyGreaterThan(0.5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodySimMetricsMatcher2()
|
||||
{
|
||||
// given
|
||||
var requestBuilder = Request.Create().UsingAnyVerb().WithBody(new SimMetricsMatcher("The cat walks in the street."));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request, requestMatchResult)).IsStrictlyLessThan(0.1).And.IsStrictlyGreaterThan(0.05);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyWildcardMatcher()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithBody(new WildcardMatcher("H*o*"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello world!";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "X-toto", new[] { "tatata" } } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyRegexMatcher()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new RegexMatcher("H.*o"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "Hello world!";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyXPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 3]"));
|
||||
|
||||
// when
|
||||
string xmlBodyAsString = @"
|
||||
<todo-list>
|
||||
<todo-item id='a1'>abc</todo-item>
|
||||
<todo-item id='a2'>def</todo-item>
|
||||
<todo-item id='a3'>xyz</todo-item>
|
||||
</todo-list>";
|
||||
byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, xmlBodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyXPathMatcher_false()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new XPathMatcher("/todo-list[count(todo-item) = 99]"));
|
||||
|
||||
// when
|
||||
string xmlBodyAsString = @"
|
||||
<todo-list>
|
||||
<todo-item id='a1'>abc</todo-item>
|
||||
<todo-item id='a2'>def</todo-item>
|
||||
<todo-item id='a3'>xyz</todo-item>
|
||||
</todo-list>";
|
||||
byte[] body = Encoding.UTF8.GetBytes(xmlBodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, xmlBodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyJsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithBodyJsonPathMatcher_false()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,39 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
//[TestFixture]
|
||||
public partial class RequestTests
|
||||
{
|
||||
[Fact]
|
||||
public void Request_WithClientIP_Match_Ok()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithClientIP("127.0.0.2", "1.1.1.1");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithClientIP_Match_Fail()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithClientIP("127.0.0.2");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", "192.1.1.1");
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class RequestWithClientIPTests
|
||||
{
|
||||
[Fact]
|
||||
public void Request_WithClientIP_Match_Ok()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithClientIP("127.0.0.2", "1.1.1.1");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithClientIP_Match_Fail()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithClientIP("127.0.0.2");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost"), "GET", "192.1.1.1");
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
//[TestFixture]
|
||||
public partial class RequestTests
|
||||
public class RequestWithPathTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPath_WithHeader_Match()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||
|
||||
// when
|
||||
string bodyAsString = "whatever";
|
||||
byte[] body = Encoding.UTF8.GetBytes(bodyAsString);
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, bodyAsString, Encoding.UTF8, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPath()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPaths()
|
||||
{
|
||||
var requestBuilder = Request.Create().WithPath("/x1", "/x2");
|
||||
|
||||
var request1 = new RequestMessage(new Uri("http://localhost/x1"), "blabla", ClientIp);
|
||||
var request2 = new RequestMessage(new Uri("http://localhost/x2"), "blabla", ClientIp);
|
||||
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(requestBuilder.GetMatchingScore(request1, requestMatchResult)).IsEqualTo(1.0);
|
||||
Check.That(requestBuilder.GetMatchingScore(request2, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPathFunc()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath(url => url.EndsWith("/foo"));
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPathRegexMatcher()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath(new RegexMatcher("^/foo"));
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Request_WithPathRegex_false()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithPath("/foo");
|
||||
|
||||
// when
|
||||
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", ClientIp);
|
||||
|
||||
// then
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
Check.That(spec.GetMatchingScore(request, requestMatchResult)).IsNotEqualTo(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_path_and_method_delete()
|
||||
{
|
||||
@@ -6,10 +6,12 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public partial class RequestTests
|
||||
public class RequestWithUrlTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_url_wildcard()
|
||||
public void Request_WithUrl()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithUrl("*/foo");
|
||||
@@ -23,7 +25,7 @@ namespace WireMock.Net.Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_specify_requests_matching_given_url_exact()
|
||||
public void Request_WithUrlExact()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().WithUrl("http://localhost/foo");
|
||||
@@ -8,8 +8,10 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public partial class ResponseTests
|
||||
public class ResponseWithBodyHandlebarsTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public async Task Response_ProvideResponse_Handlebars_UrlPathVerb()
|
||||
{
|
||||
@@ -7,7 +7,7 @@ using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public partial class ResponseTests
|
||||
public class ResponseWithBodyTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
Reference in New Issue
Block a user