mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-14 15:43:33 +01:00
Compare commits
81 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9778c5adbe | ||
|
|
1caa769618 | ||
|
|
cf4e83b10b | ||
|
|
95a201573a | ||
|
|
b248c8c6e5 | ||
|
|
180526c8b4 | ||
|
|
361d40189b | ||
|
|
061eb93fd0 | ||
|
|
e5b2ad0543 | ||
|
|
66b2ff16de | ||
|
|
40ff8514ac | ||
|
|
cdcaaa970a | ||
|
|
d07a89c907 | ||
|
|
141ed5d96c | ||
|
|
6d60b3773a | ||
|
|
e6af765777 | ||
|
|
97d80ada11 | ||
|
|
51bd9ec186 | ||
|
|
da798a59aa | ||
|
|
71196b51c9 | ||
|
|
d0fc889f42 | ||
|
|
fd5bc203c3 | ||
|
|
601af2d6b2 | ||
|
|
ea16ee866b | ||
|
|
ee0cb6e670 | ||
|
|
798603118c | ||
|
|
208303729e | ||
|
|
d39e9ef7fa | ||
|
|
431e5656ca | ||
|
|
fa919343ac | ||
|
|
d0b48e2967 | ||
|
|
018d2a904d | ||
|
|
939a5a61ab | ||
|
|
a15e6747b0 | ||
|
|
6c38400827 | ||
|
|
cb1117fdaa | ||
|
|
e25c873765 | ||
|
|
d83f308591 | ||
|
|
c8c9ab99c5 | ||
|
|
d134684bcb | ||
|
|
a96b7bca1e | ||
|
|
cbe6a0a2b4 | ||
|
|
15370a89ca | ||
|
|
656f7f5432 | ||
|
|
bcdc3d646a | ||
|
|
10350fac04 | ||
|
|
37244d5c2f | ||
|
|
07f03997c0 | ||
|
|
7c289d44a7 | ||
|
|
e87e09e10d | ||
|
|
eff21473e3 | ||
|
|
fce60f273d | ||
|
|
8199cdc382 | ||
|
|
782418f107 | ||
|
|
207688e42b | ||
|
|
2d39a18b70 | ||
|
|
9c55ff5ea6 | ||
|
|
8386d93e0d | ||
|
|
5424b1e2e2 | ||
|
|
ab017beaa6 | ||
|
|
8827531391 | ||
|
|
881e4b2af3 | ||
|
|
139ea77888 | ||
|
|
f776911ef8 | ||
|
|
3a50c81895 | ||
|
|
de5277d258 | ||
|
|
23d26ca914 | ||
|
|
f8ad2cd3d6 | ||
|
|
76f0e04874 | ||
|
|
1a77fee273 | ||
|
|
8d072e8b47 | ||
|
|
5c5d408abe | ||
|
|
2aee658dfa | ||
|
|
ef73accc9a | ||
|
|
f38c24e8c4 | ||
|
|
65ac8c6462 | ||
|
|
49ce2f0dfb | ||
|
|
c29b88eb43 | ||
|
|
85e51b6240 | ||
|
|
cece260203 | ||
|
|
538195551d |
22
.vscode/launch.json
vendored
Normal file
22
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": ".NET Core Launch (WireMock.Net.StandAlone.NETCoreApp)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build_WireMock.Net.StandAlone.NETCoreApp",
|
||||
"program": "${workspaceRoot}/examples/WireMock.Net.StandAlone.NETCoreApp/bin/Debug/netcoreapp2.0/WireMock.Net.StandAlone.NETCoreApp.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"stopAtEntry": false,
|
||||
"console": "internalConsole"
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach",
|
||||
"processId": "${command:pickProcess}"
|
||||
}
|
||||
]
|
||||
}
|
||||
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"taskName": "build_WireMock.Net.StandAlone.NETCoreApp",
|
||||
"command": "dotnet build ${workspaceRoot}/examples/WireMock.Net.StandAlone.NETCoreApp/WireMock.Net.StandAlone.NETCoreApp.csproj -f netcoreapp2.0 ",
|
||||
"type": "shell",
|
||||
"group": "build",
|
||||
"presentation": {
|
||||
"reveal": "silent"
|
||||
},
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
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
|
||||
35
README.md
35
README.md
@@ -2,10 +2,10 @@
|
||||
A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) which mimics the functionality from the JAVA based http://WireMock.org
|
||||
|
||||
[](https://ci.appveyor.com/project/StefH/wiremock-net)
|
||||
[](https://codecov.io/gh/StefH/WireMock.Net)
|
||||
[](https://coveralls.io/github/StefH/WireMock.Net?branch=master)
|
||||
[](https://github.com/StefH/WireMock.Net/issues)
|
||||
[](https://github.com/StefH/WireMock.Net/stargazers)
|
||||
[](https://codecov.io/gh/WireMock-Net/WireMock.Net)
|
||||
[](https://coveralls.io/github/WireMock-Net/WireMock.Net?branch=master)
|
||||
[](https://github.com/WireMock-Net/WireMock.Net/issues)
|
||||
[](https://github.com/WireMock-Net/WireMock.Net/stargazers)
|
||||
|
||||
| Name | NuGet |
|
||||
| ---- | ----- |
|
||||
@@ -14,12 +14,21 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
|
||||
|
||||
### Frameworks
|
||||
The following frameworks are supported:
|
||||
- net 4.5
|
||||
- net 4.5.2 and up
|
||||
- net 4.6 and up
|
||||
- netstandard 1.3
|
||||
- netstandard 2.0
|
||||
|
||||
## Build info
|
||||
To build you need:
|
||||
- Microsoft .NET Framework 4.5.2 Developer Pack (https://www.microsoft.com/en-us/download/details.aspx?id=42637)
|
||||
- Microsoft .NET Framework 4.6 Targeting Pack (https://www.microsoft.com/en-us/download/confirmation.aspx?id=48136)
|
||||
- Microsoft .NET Framework 4.6.2 Developer Pack (https://www.microsoft.com/en-us/download/confirmation.aspx?id=53321)
|
||||
- .NET Core 2.0 (https://www.microsoft.com/net/core)
|
||||
|
||||
|
||||
## Stubbing
|
||||
A core feature of WireMock.Net is the ability to return canned/predefined HTTP responses for requests matching criteria, see [Wiki : Stubbing](https://github.com/StefH/WireMock.Net/wiki/Stubbing).
|
||||
A core feature of WireMock.Net is the ability to return canned/predefined HTTP responses for requests matching criteria, see [Wiki : Stubbing & Request Matching](https://github.com/WireMock-Net/WireMock.Net/wiki/Stubbing-and-Request-Matching).
|
||||
|
||||
## Using WireMock in UnitTest framework
|
||||
You can use your favorite test framework and use WireMock within your tests, see
|
||||
@@ -34,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.26430.13
|
||||
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
|
||||
@@ -19,18 +21,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{890A1DED-C
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net", "src\WireMock.Net\WireMock.Net.csproj", "{D3804228-91F4-4502-9595-39584E5A01AD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.ConsoleApplication", "examples\WireMock.Net.ConsoleApplication\WireMock.Net.ConsoleApplication.csproj", "{668F689E-57B4-422E-8846-C0FF643CA268}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{D3804228-91F4-4502-9595-39584E5A01AD} = {D3804228-91F4-4502-9595-39584E5A01AD}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Tests", "test\WireMock.Net.Tests\WireMock.Net.Tests.csproj", "{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NETCoreApp", "examples\WireMock.Net.Console.NETCoreApp\WireMock.Net.Console.NETCoreApp.csproj", "{FE281639-B014-4C8A-96FA-141164A74713}"
|
||||
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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Client", "src\WireMock.Net.Client\WireMock.Net.Client.csproj", "{058D4B6C-C03E-49D0-91DB-A535B058FA0D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Client", "examples\WireMock.Net.Client\WireMock.Net.Client.csproj", "{058D4B6C-C03E-49D0-91DB-A535B058FA0D}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.StandAlone", "src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj", "{B6269AAC-170A-43D5-8B9A-579DED3D9A95}"
|
||||
EndProject
|
||||
@@ -38,11 +35,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.StandAlone.NET
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone.Net452", "examples\WireMock.Net.StandAlone.Net452\WireMock.Net.StandAlone.Net452.csproj", "{668F689E-57B4-422E-8846-C0FF643CA999}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{058D4B6C-C03E-49D0-91DB-A535B058FA0D} = {058D4B6C-C03E-49D0-91DB-A535B058FA0D}
|
||||
{B6269AAC-170A-43D5-8B9A-579DED3D9A95} = {B6269AAC-170A-43D5-8B9A-579DED3D9A95}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.ConsoleTest.Net452", "examples\WireMock.Net.ConsoleTest.Net452\WireMock.Net.ConsoleTest.Net452.csproj", "{B5F1A150-37E1-434D-929F-FAD5AC428107}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET452", "examples\WireMock.Net.ConsoleApplication\WireMock.Net.Console.NET452.csproj", "{668F689E-57B4-422E-8846-C0FF643CA268}"
|
||||
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
|
||||
@@ -54,10 +56,6 @@ Global
|
||||
{D3804228-91F4-4502-9595-39584E5A01AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D3804228-91F4-4502-9595-39584E5A01AD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D3804228-91F4-4502-9595-39584E5A01AD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -86,17 +84,28 @@ Global
|
||||
{668F689E-57B4-422E-8846-C0FF643CA999}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA999}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA999}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B5F1A150-37E1-434D-929F-FAD5AC428107}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B5F1A150-37E1-434D-929F-FAD5AC428107}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B5F1A150-37E1-434D-929F-FAD5AC428107}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B5F1A150-37E1-434D-929F-FAD5AC428107}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{049539C1-7A66-4559-AD7A-B1C73B97CBB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{D3804228-91F4-4502-9595-39584E5A01AD} = {EF242EDF-7133-4277-9A0C-18744DE08707}
|
||||
{668F689E-57B4-422E-8846-C0FF643CA268} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{31DC2EF8-C3FE-467D-84BE-FB5D956E612E} = {890A1DED-C229-4FA1-969E-AAC3BBFC05E5}
|
||||
{FE281639-B014-4C8A-96FA-141164A74713} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{1995E414-F197-4AB4-90C2-68D806B5AF59} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
@@ -104,6 +113,12 @@ Global
|
||||
{B6269AAC-170A-43D5-8B9A-579DED3D9A95} = {EF242EDF-7133-4277-9A0C-18744DE08707}
|
||||
{10E16614-61CA-48D8-8BDD-664C13913DED} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{668F689E-57B4-422E-8846-C0FF643CA999} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{B5F1A150-37E1-434D-929F-FAD5AC428107} = {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}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/AbsolutePath/@EntryValue">C:\Users\azureuser\Documents\Github\WireMock.Net\ReSharper_WireMock.DotSettings</s:String>
|
||||
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/RelativePath/@EntryValue">..\ReSharper_WireMock.DotSettings</s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=FBE2016FCEACD34DB66E1CC40B87F9F2/@KeyIndexDefined">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileFBE2016FCEACD34DB66E1CC40B87F9F2/@KeyIndexDefined">True</s:Boolean>
|
||||
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=FileFBE2016FCEACD34DB66E1CC40B87F9F2/RelativePriority/@EntryValue">1</s:Double></wpf:ResourceDictionary>
|
||||
14
appveyor.yml
14
appveyor.yml
@@ -9,8 +9,8 @@ init:
|
||||
- ps: $Env:LABEL = "CI" + $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0")
|
||||
|
||||
install:
|
||||
- ps: Start-FileDownload 'https://download.microsoft.com/download/8/F/9/8F9659B9-E628-4D1A-B6BF-C3004C8C954B/dotnet-1.1.1-sdk-win-x64.exe'
|
||||
- cmd: dotnet-1.1.1-sdk-win-x64.exe /quiet
|
||||
- ps: Start-FileDownload 'https://download.microsoft.com/download/0/F/D/0FD852A4-7EA1-4E2A-983A-0484AC19B92C/dotnet-sdk-2.0.0-win-gs-x64.exe'
|
||||
- cmd: dotnet-sdk-2.0.0-win-gs-x64.exe /quiet
|
||||
- ps: $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
|
||||
|
||||
environment:
|
||||
@@ -20,26 +20,24 @@ environment:
|
||||
|
||||
before_build:
|
||||
- dotnet restore .\src\WireMock.Net\WireMock.Net.csproj
|
||||
- dotnet restore .\src\WireMock.Net.Client\WireMock.Net.Client.csproj
|
||||
- dotnet restore .\src\WireMock.Net.Standalone\WireMock.Net.Standalone.csproj
|
||||
- nuget restore .\examples\WireMock.Net.ConsoleApplication\WireMock.Net.ConsoleApplication.csproj -PackagesDirectory packages
|
||||
|
||||
build_script:
|
||||
# build WireMock.Net
|
||||
- dotnet build .\src\WireMock.Net\WireMock.Net.csproj -c %CONFIGURATION%
|
||||
|
||||
# build WireMock.Net.Standalone
|
||||
- dotnet build .\src\WireMock.Net.Standalone\WireMock.Net.Standalone.csproj -c %CONFIGURATION%
|
||||
|
||||
# restore and build WireMock.Net.Tests
|
||||
- dotnet restore .\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj
|
||||
- dotnet build .\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj -c %CONFIGURATION%
|
||||
|
||||
# build WireMock.Net.Standalone
|
||||
- dotnet build .\src\WireMock.Net.Standalone\WireMock.Net.Standalone.csproj -c %CONFIGURATION%
|
||||
|
||||
test_script:
|
||||
- nuget.exe install OpenCover -ExcludeVersion
|
||||
- nuget.exe install coveralls.net -ExcludeVersion
|
||||
- pip install codecov
|
||||
|
||||
- cmd: '"OpenCover\tools\OpenCover.Console.exe" -register:user -target:dotnet.exe -targetargs:"test test\WireMock.Net.Tests\WireMock.Net.Tests.csproj --no-build" -returntargetcode -filter:"+[WireMock.Net]* -[WireMock.Net.Tests*]*" -output:coverage.xml -oldstyle -searchdirs:".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452"'
|
||||
- cmd: '"OpenCover\tools\OpenCover.Console.exe" -target:dotnet.exe -targetargs:"test test\WireMock.Net.Tests\WireMock.Net.Tests.csproj --no-build" -output:coverage.xml -returntargetcode -register:user -filter:"+[WireMock.Net]* -[WireMock.Net.Tests*]*" -nodefaultfilters -returntargetcode -oldstyle -searchdirs:".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452"'
|
||||
- codecov -f "coverage.xml"
|
||||
- coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml
|
||||
@@ -12,7 +12,7 @@ namespace WireMock.Net.Client
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Create an implementation of the IFluentMockServerAdmin and pass in the base URL for the API.
|
||||
var api = RestClient.For<IFluentMockServerAdmin>("http://localhost:9090");
|
||||
var api = RestClient.For<IFluentMockServerAdmin>("http://localhost:9091");
|
||||
|
||||
// Set BASIC Auth
|
||||
var value = Convert.ToBase64String(Encoding.ASCII.GetBytes("a:b"));
|
||||
@@ -30,9 +30,24 @@ namespace WireMock.Net.Client
|
||||
var mappings = api.GetMappingsAsync().Result;
|
||||
Console.WriteLine($"mappings = {JsonConvert.SerializeObject(mappings)}");
|
||||
|
||||
var guid = Guid.Parse("11111110-a633-40e8-a244-5cb80bc0ab66");
|
||||
var mapping = api.GetMappingAsync(guid).Result;
|
||||
Console.WriteLine($"mapping = {JsonConvert.SerializeObject(mapping)}");
|
||||
try
|
||||
{
|
||||
var guid = Guid.Parse("11111110-a633-40e8-a244-5cb80bc0ab66");
|
||||
var mapping = api.GetMappingAsync(guid).Result;
|
||||
Console.WriteLine($"mapping = {JsonConvert.SerializeObject(mapping)}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
var request = api.GetRequestsAsync().Result;
|
||||
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
|
||||
|
||||
string deleteRequestsAsync = api.DeleteRequestsAsync().Result;
|
||||
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync}");
|
||||
|
||||
string resetRequestsAsync = api.ResetRequestsAsync().Result;
|
||||
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync}");
|
||||
|
||||
Console.WriteLine("Press any key to quit");
|
||||
Console.ReadKey();
|
||||
19
examples/WireMock.Net.Client/WireMock.Net.Client.csproj
Normal file
19
examples/WireMock.Net.Client/WireMock.Net.Client.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<!-- <RuntimeFrameworkVersion>1.0.1</RuntimeFrameworkVersion> -->
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="RestEase" Version="1.4.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -18,19 +18,20 @@
|
||||
<Content Include="__admin\mappings\11111110-a633-40e8-a244-5cb80bc0ab66.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="__admin\mappings\826aff7c-6208-4a3c-923d-575248907db4.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<!--<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />-->
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="__admin\mappings\791a3f31-6946-4ce7-8e6f-0237c7443275.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings\791a3f31-6946-4ce7-8e6f-0237c7443275.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -14,8 +14,9 @@
|
||||
},
|
||||
"Response": {
|
||||
"BodyAsJson": { "body": "static mapping" },
|
||||
"Headers": {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
"Headers": {
|
||||
"Content-Type": "application/json",
|
||||
"Test-X": [ "test 1", "test 2" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"Guid": "791a3f31-6946-4ce7-8e6f-0237c7443275",
|
||||
"Title": "",
|
||||
"Priority": 0,
|
||||
"Request": {
|
||||
"Path": {
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "WildcardMatcher",
|
||||
"Pattern": "/proxy-google-test-post"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Methods": [
|
||||
"post"
|
||||
],
|
||||
"Body": {}
|
||||
},
|
||||
"Response": {
|
||||
"StatusCode": 404,
|
||||
"Body": "<!DOCTYPE html>\n<html lang=en>\n <meta charset=utf-8>\n <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n <title>Error 404 (Not Found)!!1</title>\n <style>\n *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n </style>\n <a href=//www.google.com/><span id=logo aria-label=Google></span></a>\n <p><b>404.</b> <ins>That’s an error.</ins>\n <p>The requested URL <code>/proxy-google-test-post</code> was not found on this server. <ins>That’s all we know.</ins>\n",
|
||||
"BodyAsBytes": "PCFET0NUWVBFIGh0bWw+CjxodG1sIGxhbmc9ZW4+CiAgPG1ldGEgY2hhcnNldD11dGYtOD4KICA8bWV0YSBuYW1lPXZpZXdwb3J0IGNvbnRlbnQ9ImluaXRpYWwtc2NhbGU9MSwgbWluaW11bS1zY2FsZT0xLCB3aWR0aD1kZXZpY2Utd2lkdGgiPgogIDx0aXRsZT5FcnJvciA0MDQgKE5vdCBGb3VuZCkhITE8L3RpdGxlPgogIDxzdHlsZT4KICAgICp7bWFyZ2luOjA7cGFkZGluZzowfWh0bWwsY29kZXtmb250OjE1cHgvMjJweCBhcmlhbCxzYW5zLXNlcmlmfWh0bWx7YmFja2dyb3VuZDojZmZmO2NvbG9yOiMyMjI7cGFkZGluZzoxNXB4fWJvZHl7bWFyZ2luOjclIGF1dG8gMDttYXgtd2lkdGg6MzkwcHg7bWluLWhlaWdodDoxODBweDtwYWRkaW5nOjMwcHggMCAxNXB4fSogPiBib2R5e2JhY2tncm91bmQ6dXJsKC8vd3d3Lmdvb2dsZS5jb20vaW1hZ2VzL2Vycm9ycy9yb2JvdC5wbmcpIDEwMCUgNXB4IG5vLXJlcGVhdDtwYWRkaW5nLXJpZ2h0OjIwNXB4fXB7bWFyZ2luOjExcHggMCAyMnB4O292ZXJmbG93OmhpZGRlbn1pbnN7Y29sb3I6Izc3Nzt0ZXh0LWRlY29yYXRpb246bm9uZX1hIGltZ3tib3JkZXI6MH1AbWVkaWEgc2NyZWVuIGFuZCAobWF4LXdpZHRoOjc3MnB4KXtib2R5e2JhY2tncm91bmQ6bm9uZTttYXJnaW4tdG9wOjA7bWF4LXdpZHRoOm5vbmU7cGFkZGluZy1yaWdodDowfX0jbG9nb3tiYWNrZ3JvdW5kOnVybCgvL3d3dy5nb29nbGUuY29tL2ltYWdlcy9icmFuZGluZy9nb29nbGVsb2dvLzF4L2dvb2dsZWxvZ29fY29sb3JfMTUweDU0ZHAucG5nKSBuby1yZXBlYXQ7bWFyZ2luLWxlZnQ6LTVweH1AbWVkaWEgb25seSBzY3JlZW4gYW5kIChtaW4tcmVzb2x1dGlvbjoxOTJkcGkpeyNsb2dve2JhY2tncm91bmQ6dXJsKC8vd3d3Lmdvb2dsZS5jb20vaW1hZ2VzL2JyYW5kaW5nL2dvb2dsZWxvZ28vMngvZ29vZ2xlbG9nb19jb2xvcl8xNTB4NTRkcC5wbmcpIG5vLXJlcGVhdCAwJSAwJS8xMDAlIDEwMCU7LW1vei1ib3JkZXItaW1hZ2U6dXJsKC8vd3d3Lmdvb2dsZS5jb20vaW1hZ2VzL2JyYW5kaW5nL2dvb2dsZWxvZ28vMngvZ29vZ2xlbG9nb19jb2xvcl8xNTB4NTRkcC5wbmcpIDB9fUBtZWRpYSBvbmx5IHNjcmVlbiBhbmQgKC13ZWJraXQtbWluLWRldmljZS1waXhlbC1yYXRpbzoyKXsjbG9nb3tiYWNrZ3JvdW5kOnVybCgvL3d3dy5nb29nbGUuY29tL2ltYWdlcy9icmFuZGluZy9nb29nbGVsb2dvLzJ4L2dvb2dsZWxvZ29fY29sb3JfMTUweDU0ZHAucG5nKSBuby1yZXBlYXQ7LXdlYmtpdC1iYWNrZ3JvdW5kLXNpemU6MTAwJSAxMDAlfX0jbG9nb3tkaXNwbGF5OmlubGluZS1ibG9jaztoZWlnaHQ6NTRweDt3aWR0aDoxNTBweH0KICA8L3N0eWxlPgogIDxhIGhyZWY9Ly93d3cuZ29vZ2xlLmNvbS8+PHNwYW4gaWQ9bG9nbyBhcmlhLWxhYmVsPUdvb2dsZT48L3NwYW4+PC9hPgogIDxwPjxiPjQwNC48L2I+IDxpbnM+VGhhdOKAmXMgYW4gZXJyb3IuPC9pbnM+CiAgPHA+VGhlIHJlcXVlc3RlZCBVUkwgPGNvZGU+L3Byb3h5LWdvb2dsZS10ZXN0LXBvc3Q8L2NvZGU+IHdhcyBub3QgZm91bmQgb24gdGhpcyBzZXJ2ZXIuICA8aW5zPlRoYXTigJlzIGFsbCB3ZSBrbm93LjwvaW5zPgo=",
|
||||
"BodyEncoding": {
|
||||
"CodePage": 65001,
|
||||
"EncodingName": "Unicode (UTF-8)",
|
||||
"WebName": "utf-8"
|
||||
},
|
||||
"UseTransformer": false,
|
||||
"Headers": {
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
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.ConsoleTest.Net452")]
|
||||
[assembly: AssemblyTitle("WireMock.Net.Console.Proxy.Net452")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("WireMock.Net.ConsoleTest.Net452")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyProduct("WireMock.Net.Console.Proxy.Net452")]
|
||||
[assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
@@ -20,7 +19,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("b5f1a150-37e1-434d-929f-fad5ac428107")]
|
||||
[assembly: Guid("26433a8f-bf01-4962-97eb-81bffbb61096")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
@@ -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
|
||||
{
|
||||
@@ -10,12 +10,16 @@ namespace WireMock.Net.Console.Record.NETCoreApp
|
||||
{
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { "http://localhost:9095/", "https://localhost:9096/" },
|
||||
Urls = new[] { "http://localhost:9091/", "https://localhost:9443/" },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = "https://www.msn.com",
|
||||
SaveMapping = true
|
||||
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" }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.10" />
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<!--<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />-->
|
||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||
<Folder Include="__admin\mappings\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -13,22 +12,84 @@ namespace WireMock.Net.ConsoleApplication
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
string url1 = "http://localhost:9090/";
|
||||
string url2 = "http://localhost:9091/";
|
||||
string url1 = "http://localhost:9091/";
|
||||
string url2 = "http://localhost:9092/";
|
||||
string url3 = "https://localhost:9443/";
|
||||
|
||||
var server = FluentMockServer.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { url1, url2, url3 },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = true
|
||||
ReadStaticMappings = true,
|
||||
WatchStaticMappings = true,
|
||||
//ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
//{
|
||||
// SaveMapping = true
|
||||
//},
|
||||
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");
|
||||
|
||||
server.AllowPartialMapping();
|
||||
|
||||
// .WithHeader("Stef", "Stef")
|
||||
//server
|
||||
// .Given(Request.Create().WithPath("*"))
|
||||
// .RespondWith(Response.Create()
|
||||
// .WithProxy("http://restcountries.eu"));
|
||||
|
||||
server
|
||||
.Given(Request
|
||||
.Create()
|
||||
.WithPath(new WildcardMatcher("/navision/OData/Company('My Company')/School*", true))
|
||||
.WithParam("$filter", "(substringof(Code, 'WA')")
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody(@"{ ""result"": ""odata""}"));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(201)
|
||||
.WithHeader("MyHeader", "application/json", "application/json2")
|
||||
.WithBody(@"{ ""result"": ""data posted with 201""}"));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/file").UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithBodyFromFile(@"c:\temp\x.json", false)
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/filecache").UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithBodyFromFile(@"c:\temp\x.json")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/file_rel").UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithBodyFromFile("Program.cs", false)
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithHeader("ProxyThis", "true")
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithProxy("http://www.google.com")
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/bodyasbytes.png")
|
||||
.UsingGet())
|
||||
.RespondWith(Response.Create()
|
||||
.WithHeader("Content-Type", "image/png")
|
||||
.WithBody(Convert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMTczbp9jAAAAJ0lEQVQoU2NgUPuPD6Hz0RCEAtJoiAxpCCBXGgmRIo0TofORkdp/AMiMdRVnV6O0AAAAAElFTkSuQmCC"))
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/oauth2/access").UsingPost().WithBody("grant_type=password;username=u;password=p"))
|
||||
.RespondWith(Response.Create()
|
||||
@@ -58,13 +119,6 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.WithHeader("Content-Type", "application/json")
|
||||
.WithBody(@"{ ""result"": ""data posted with FUNC 201""}"));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/data", "/ax").UsingPost().WithHeader("Content-Type", "application/json*"))
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(201)
|
||||
.WithHeader("Content-Type", "application/json")
|
||||
.WithBody(@"{ ""result"": ""data posted with 201""}"));
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/json").UsingPost().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]")))
|
||||
.RespondWith(Response.Create()
|
||||
@@ -96,18 +150,54 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
|
||||
|
||||
// http://localhost:8080/any/any?start=1000&stop=1&stop=2
|
||||
//server
|
||||
// .Given(Request.Create().WithPath("/*").UsingGet())
|
||||
// .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
// .AtPriority(server.Mappings.Count() + 1)
|
||||
// .RespondWith(Response.Create()
|
||||
// .WithStatusCode(200)
|
||||
// .WithHeader("Content-Type", "application/json")
|
||||
// .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||
// .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||
// .WithTransformer()
|
||||
// .WithDelay(TimeSpan.FromMilliseconds(100))
|
||||
// );
|
||||
|
||||
server
|
||||
.Given(Request.Create().WithPath("/*").UsingGet())
|
||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
.AtPriority(server.Mappings.Count() + 1)
|
||||
.Given(Request.Create()
|
||||
.WithPath("/state1")
|
||||
.UsingGet())
|
||||
.InScenario("s1")
|
||||
.WillSetStateTo("Test state 1")
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithHeader("Content-Type", "application/json")
|
||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||
.WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||
.WithTransformer()
|
||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||
);
|
||||
.WithBody("No state msg 1"));
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.WithPath("/foostate1")
|
||||
.UsingGet())
|
||||
.InScenario("s1")
|
||||
.WhenStateIs("Test state 1")
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("Test state msg 1"));
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.WithPath("/state2")
|
||||
.UsingGet())
|
||||
.InScenario("s2")
|
||||
.WillSetStateTo("Test state 2")
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("No state msg 2"));
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
.WithPath("/foostate2")
|
||||
.UsingGet())
|
||||
.InScenario("s2")
|
||||
.WhenStateIs("Test state 2")
|
||||
.RespondWith(Response.Create()
|
||||
.WithBody("Test state msg 2"));
|
||||
|
||||
System.Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
@@ -121,4 +211,4 @@ namespace WireMock.Net.ConsoleApplication
|
||||
System.Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,9 +47,6 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="WireMock.Net">
|
||||
<HintPath>..\..\src\WireMock.Net\bin\$(Configuration)\net45\WireMock.Net.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MainApp.cs" />
|
||||
@@ -67,6 +64,16 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</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" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using WireMock.Net.StandAlone;
|
||||
|
||||
namespace WireMock.Net.ConsoleTest.Net452
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
StandAloneApp.Start(args);
|
||||
|
||||
Console.WriteLine("Press any key to stop the server");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?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>{B5F1A150-37E1-434D-929F-FAD5AC428107}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WireMock.Net.ConsoleTest.Net452</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.ConsoleTest.Net452</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</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>
|
||||
<ItemGroup>
|
||||
<Reference Include="CommandLineArgumentsParser, Version=3.0.11.0, Culture=neutral, PublicKeyToken=16ad7bf6f4a1666c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\CommandLineArgumentsParser.3.0.11\lib\net45\CommandLineArgumentsParser.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Handlebars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Handlebars.Net.1.8.0\lib\portable-net45+sl5+wp8+win8\Handlebars.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Hosting, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SimMetrics.Net, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.3\lib\net45\SimMetrics.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<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" />
|
||||
<Reference Include="WireMock.Net, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\WireMock.Net.1.0.2\lib\net45\WireMock.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WireMock.Net.StandAlone, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\WireMock.Net.StandAlone.1.0.0\lib\net452\WireMock.Net.StandAlone.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="XPath2, Version=1.0.3.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\XPath2.1.0.3.1\lib\net452\XPath2.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="CommandLineArgumentsParser" version="3.0.11" targetFramework="net452" />
|
||||
<package id="Handlebars.Net" version="1.8.0" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||
<package id="SimMetrics.Net" version="1.0.3" targetFramework="net452" />
|
||||
<package id="WireMock.Net" version="1.0.2" targetFramework="net452" />
|
||||
<package id="WireMock.Net.StandAlone" version="1.0.0" targetFramework="net452" />
|
||||
<package id="XPath2" version="1.0.3.1" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -1,15 +1,42 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using WireMock.Server;
|
||||
|
||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static int sleepTime = 30000;
|
||||
private static FluentMockServer _server;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
StandAloneApp.Start(args);
|
||||
_server = StandAloneApp.Start(args);
|
||||
|
||||
Console.WriteLine("Press any key to stop the server");
|
||||
Console.ReadKey();
|
||||
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
Stop("CancelKeyPress");
|
||||
};
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||
{
|
||||
Stop("AssemblyLoadContext.Default.Unloading");
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running");
|
||||
Thread.Sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
|
||||
_server.Stop();
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"profiles": {
|
||||
"WireMock.Net.StandAlone.NETCoreApp": {
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "--Urls http://*:9091"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
<TargetFrameworks>netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
1
examples/WireMock.Net.StandAlone.NETCoreApp/run1.cmd
Normal file
1
examples/WireMock.Net.StandAlone.NETCoreApp/run1.cmd
Normal file
@@ -0,0 +1 @@
|
||||
dotnet run --framework netcoreapp1.1
|
||||
1
examples/WireMock.Net.StandAlone.NETCoreApp/run2.cmd
Normal file
1
examples/WireMock.Net.StandAlone.NETCoreApp/run2.cmd
Normal file
@@ -0,0 +1 @@
|
||||
dotnet run --framework netcoreapp2.0
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Net.StandAlone
|
||||
namespace WireMock.Net.StandAlone.Net452
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
<ProjectGuid>{668F689E-57B4-422E-8846-C0FF643CA999}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>WireMock.Net.StandAlone</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
||||
<RootNamespace>WireMock.Net.StandAlone.Net452</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.StandAlone.Net452</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
@@ -35,38 +35,15 @@
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>..\..\WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject>WireMock.Net.StandAlone.Net452.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Handlebars, Version=1.8.1.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Handlebars.Net.1.9.0\lib\net40\Handlebars.dll</HintPath>
|
||||
</Reference>
|
||||
<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=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestEase, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\RestEase.1.4.1\lib\net45\RestEase.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SimMetrics.Net, Version=1.0.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.3\lib\net45\SimMetrics.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="WireMock.Net, Version=1.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\src\WireMock.Net.StandAlone\bin\$(Configuration)\net452\WireMock.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WireMock.Net.StandAlone, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\src\WireMock.Net.StandAlone\bin\$(Configuration)\net452\WireMock.Net.StandAlone.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="XPath2, Version=1.0.3.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\XPath2.1.0.3.1\lib\net452\XPath2.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
@@ -75,6 +52,16 @@
|
||||
<ItemGroup>
|
||||
<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" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Handlebars.Net" version="1.9.0" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
|
||||
<package id="RestEase" version="1.4.1" targetFramework="net452" />
|
||||
<package id="SimMetrics.Net" version="1.0.3" targetFramework="net452" />
|
||||
<package id="XPath2" version="1.0.3.1" targetFramework="net452" />
|
||||
</packages>
|
||||
22
examples/WireMock.Net.WebApplication/App.cs
Normal file
22
examples/WireMock.Net.WebApplication/App.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace WireMock.Net.WebApplication
|
||||
{
|
||||
public class App
|
||||
{
|
||||
private readonly IWireMockService _service;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public App(IWireMockService service, ILogger logger)
|
||||
{
|
||||
_service = service;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_logger.LogInformation("WireMock.Net App running");
|
||||
_service.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
7
examples/WireMock.Net.WebApplication/IWireMockService.cs
Normal file
7
examples/WireMock.Net.WebApplication/IWireMockService.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace WireMock.Net.WebApplication
|
||||
{
|
||||
public interface IWireMockService
|
||||
{
|
||||
void Run();
|
||||
}
|
||||
}
|
||||
57
examples/WireMock.Net.WebApplication/Program.cs
Normal file
57
examples/WireMock.Net.WebApplication/Program.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.WebApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Create service collection
|
||||
var serviceCollection = new ServiceCollection();
|
||||
ConfigureServices(serviceCollection);
|
||||
|
||||
// Create service provider
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
// Run app
|
||||
serviceProvider.GetService<App>().Run();
|
||||
}
|
||||
|
||||
private static void ConfigureServices(IServiceCollection serviceCollection)
|
||||
{
|
||||
// Build configuration
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
.AddEnvironmentVariables() // <-- this is needed to to override settings via the Azure Portal App Settings
|
||||
.Build();
|
||||
|
||||
// Add LoggerFactory
|
||||
var factory = new LoggerFactory();
|
||||
serviceCollection.AddSingleton(factory
|
||||
.AddConsole(configuration.GetSection("Logging"))
|
||||
.AddDebug()
|
||||
.AddAzureWebAppDiagnostics()
|
||||
);
|
||||
|
||||
serviceCollection.AddSingleton(factory.CreateLogger("WireMock.Net Logger"));
|
||||
|
||||
// Add access to generic IConfigurationRoot
|
||||
serviceCollection.AddSingleton(configuration);
|
||||
|
||||
// Add access to IFluentMockServerSettings
|
||||
var settings = configuration.GetSection("FluentMockServerSettings").Get<FluentMockServerSettings>();
|
||||
serviceCollection.AddSingleton<IFluentMockServerSettings>(settings);
|
||||
|
||||
// Add services
|
||||
serviceCollection.AddTransient<IWireMockService, WireMockService>();
|
||||
|
||||
// Add app
|
||||
serviceCollection.AddTransient<App>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:56513/",
|
||||
"sslPort": 0
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchUrl": "__admin/settings",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"WireMock.Net.WebApplication": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "__admin/settings",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "http://localhost:56514/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="wwwroot\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
|
||||
<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>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
37
examples/WireMock.Net.WebApplication/WireMockService.cs
Normal file
37
examples/WireMock.Net.WebApplication/WireMockService.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Threading;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Net.StandAlone;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.Net.WebApplication
|
||||
{
|
||||
public class WireMockService : IWireMockService
|
||||
{
|
||||
private static int sleepTime = 30000;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IFluentMockServerSettings _settings;
|
||||
|
||||
public WireMockService(ILogger logger, IFluentMockServerSettings settings)
|
||||
{
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
_logger.LogInformation("WireMock.Net server starting");
|
||||
|
||||
StandAloneApp.Start(_settings);
|
||||
|
||||
_logger.LogInformation($"WireMock.Net server settings {JsonConvert.SerializeObject(_settings)}");
|
||||
|
||||
while (true)
|
||||
{
|
||||
_logger.LogInformation("WireMock.Net server running");
|
||||
Thread.Sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
20
examples/WireMock.Net.WebApplication/appsettings.json
Normal file
20
examples/WireMock.Net.WebApplication/appsettings.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"Debug": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
},
|
||||
"Console": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug"
|
||||
}
|
||||
}
|
||||
},
|
||||
"FluentMockServerSettings": {
|
||||
"AdminUsername": "a",
|
||||
"AdminPassword": "a",
|
||||
"StartAdminInterface": true
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
|
||||
<PackageReference Include="RestEase" Version="1.4.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
82
src/WireMock.Net.StandAlone/SimpleCommandLineParser.cs
Normal file
82
src/WireMock.Net.StandAlone/SimpleCommandLineParser.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace WireMock.Net.StandAlone
|
||||
{
|
||||
// Based on http://blog.gauffin.org/2014/12/simple-command-line-parser/
|
||||
internal class SimpleCommandLineParser
|
||||
{
|
||||
private IDictionary<string, string[]> Arguments { get; } = new Dictionary<string, string[]>();
|
||||
|
||||
public void Parse(string[] args)
|
||||
{
|
||||
string currentName = null;
|
||||
|
||||
var values = new List<string>();
|
||||
foreach (string arg in args)
|
||||
{
|
||||
if (arg.StartsWith("--"))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
Arguments[currentName] = values.ToArray();
|
||||
}
|
||||
|
||||
values.Clear();
|
||||
currentName = arg.Substring(2);
|
||||
}
|
||||
else if (string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
Arguments[arg] = new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(currentName))
|
||||
{
|
||||
Arguments[currentName] = values.ToArray();
|
||||
}
|
||||
}
|
||||
public bool Contains(string name)
|
||||
{
|
||||
return Arguments.ContainsKey(name);
|
||||
}
|
||||
|
||||
public string[] GetValues(string name, string[] defaultValue = null)
|
||||
{
|
||||
return Contains(name) ? Arguments[name] : defaultValue;
|
||||
}
|
||||
|
||||
public T GetValue<T>(string name, Func<string[], T> func, T defaultValue = default(T))
|
||||
{
|
||||
return Contains(name) ? func(Arguments[name]) : defaultValue;
|
||||
}
|
||||
|
||||
public bool GetBoolValue(string name, bool defaultValue = false)
|
||||
{
|
||||
return GetValue(name, values =>
|
||||
{
|
||||
string value = values.FirstOrDefault();
|
||||
return !string.IsNullOrEmpty(value) ? bool.Parse(value) : defaultValue;
|
||||
}, defaultValue);
|
||||
}
|
||||
|
||||
public int? GetIntValue(string name, int? defaultValue = null)
|
||||
{
|
||||
return GetValue(name, values =>
|
||||
{
|
||||
string value = values.FirstOrDefault();
|
||||
return !string.IsNullOrEmpty(value) ? int.Parse(value) : defaultValue;
|
||||
}, defaultValue);
|
||||
}
|
||||
|
||||
public string GetStringValue(string name, string defaultValue = null)
|
||||
{
|
||||
return GetValue(name, values => values.FirstOrDefault() ?? defaultValue, defaultValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CommandLineParser.Arguments;
|
||||
using CommandLineParser.Exceptions;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WireMock.Net.StandAlone
|
||||
{
|
||||
@@ -13,83 +13,73 @@ namespace WireMock.Net.StandAlone
|
||||
/// </summary>
|
||||
public static class StandAloneApp
|
||||
{
|
||||
private class Options
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone based on the FluentMockServerSettings.
|
||||
/// </summary>
|
||||
/// <param name="settings">The FluentMockServerSettings</param>
|
||||
[PublicAPI]
|
||||
public static FluentMockServer Start([NotNull] IFluentMockServerSettings settings)
|
||||
{
|
||||
[ValueArgument(typeof(string), "Urls", Description = "URL(s) to listen on.", Optional = true, AllowMultiple = true)]
|
||||
public List<string> Urls { get; set; }
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
|
||||
[SwitchArgument("AllowPartialMapping", false, Description = "Allow Partial Mapping (default set to false).", Optional = true)]
|
||||
public bool AllowPartialMapping { get; set; }
|
||||
|
||||
[SwitchArgument("StartAdminInterface", true, Description = "Start the AdminInterface (default set to true).", Optional = true)]
|
||||
public bool StartAdminInterface { get; set; }
|
||||
|
||||
[SwitchArgument("ReadStaticMappings", true, Description = "Read StaticMappings from ./__admin/mappings (default set to true).", Optional = true)]
|
||||
public bool ReadStaticMappings { get; set; }
|
||||
|
||||
[ValueArgument(typeof(string), "ProxyURL", Description = "The ProxyURL to use.", Optional = true)]
|
||||
public string ProxyURL { get; set; }
|
||||
|
||||
[SwitchArgument("SaveProxyMapping", true, Description = "Save the proxied request and response mapping files in ./__admin/mappings. (default set to true).", Optional = true)]
|
||||
public bool SaveMapping { get; set; }
|
||||
|
||||
[ValueArgument(typeof(string), "X509Certificate2", Description = "The X509Certificate2 Filename to use.", Optional = true)]
|
||||
public string X509Certificate2Filename { get; set; }
|
||||
return FluentMockServer.Start(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone bases on the commandline arguments.
|
||||
/// Start WireMock.Net standalone based on the commandline arguments.
|
||||
/// </summary>
|
||||
/// <param name="args">The commandline arguments</param>
|
||||
public static FluentMockServer Start(string[] args)
|
||||
[PublicAPI]
|
||||
public static FluentMockServer Start([NotNull] string[] args)
|
||||
{
|
||||
var options = new Options();
|
||||
var parser = new CommandLineParser.CommandLineParser();
|
||||
parser.ExtractArgumentAttributes(options);
|
||||
Check.NotNull(args, nameof(args));
|
||||
|
||||
try
|
||||
Console.WriteLine("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
var parser = new SimpleCommandLineParser();
|
||||
parser.Parse(args);
|
||||
|
||||
var settings = new FluentMockServerSettings
|
||||
{
|
||||
parser.ParseCommandLine(args);
|
||||
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"),
|
||||
MaxRequestLogCount = parser.GetIntValue("MaxRequestLogCount"),
|
||||
RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"),
|
||||
};
|
||||
|
||||
if (!options.Urls.Any())
|
||||
{
|
||||
options.Urls.Add("http://localhost:9090/");
|
||||
}
|
||||
if (parser.Contains("Port"))
|
||||
{
|
||||
settings.Port = parser.GetIntValue("Port");
|
||||
}
|
||||
else
|
||||
{
|
||||
settings.Urls = parser.GetValues("Urls", new[] { "http://*:9091/" });
|
||||
}
|
||||
|
||||
var settings = new FluentMockServerSettings
|
||||
string proxyURL = parser.GetStringValue("ProxyURL");
|
||||
if (!string.IsNullOrEmpty(proxyURL))
|
||||
{
|
||||
settings.ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Urls = options.Urls.ToArray(),
|
||||
StartAdminInterface = options.StartAdminInterface,
|
||||
ReadStaticMappings = options.ReadStaticMappings,
|
||||
Url = proxyURL,
|
||||
SaveMapping = parser.GetBoolValue("SaveMapping"),
|
||||
SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"),
|
||||
ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"),
|
||||
BlackListedHeaders = parser.GetValues("BlackListedHeaders")
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(options.ProxyURL))
|
||||
{
|
||||
settings.ProxyAndRecordSettings = new ProxyAndRecordSettings
|
||||
{
|
||||
Url = options.ProxyURL,
|
||||
SaveMapping = options.SaveMapping,
|
||||
X509Certificate2Filename = options.X509Certificate2Filename
|
||||
};
|
||||
}
|
||||
|
||||
var server = FluentMockServer.Start(settings);
|
||||
if (options.AllowPartialMapping)
|
||||
{
|
||||
server.AllowPartialMapping();
|
||||
}
|
||||
|
||||
Console.WriteLine("WireMock.Net server listening at {0}", string.Join(" and ", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
catch (CommandLineException e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
parser.ShowUsage();
|
||||
|
||||
throw;
|
||||
}
|
||||
Console.WriteLine("WireMock.Net server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
|
||||
FluentMockServer server = Start(settings);
|
||||
|
||||
Console.WriteLine("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,49 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.0.0</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net45;net452;net46;netstandard1.3</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
||||
<PackageId>WireMock.Net.StandAlone</PackageId>
|
||||
<PackageTags>tdd;mock;http;wiremock;test;server;unittest</PackageTags>
|
||||
<PackageReleaseNotes>Initial version</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/StefH/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/StefH/WireMock.Net</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/StefH/WireMock.Net/master/LICENSE</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/StefH/WireMock.Net</RepositoryUrl>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<DebugType>full</DebugType>
|
||||
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
|
||||
<RootNamespace>WireMock.Net.StandAlone</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
|
||||
<DefineConstants>NETSTANDARD</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineArgumentsParser" Version="3.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<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>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>
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="10.4.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<!-- <PackageReference Include="CommandLineArgumentsParser" Version="3.0.16" /> -->
|
||||
<!-- <PackageReference Include="Marsonsoft.CommandLineParser" Version="1.0.34" /> -->
|
||||
<!-- <PackageReference Include="BurnSystems.CommandLine" Version="1.1.0" /> -->
|
||||
<!-- <ProjectReference Include="..\..\..\CommandLineParser\src\CommandLineArgumentsParser\CommandLineArgumentsParser.csproj" /> -->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
24
src/WireMock.Net/Admin/Mappings/ClientIPModel.cs
Normal file
24
src/WireMock.Net/Admin/Mappings/ClientIPModel.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
/// <summary>
|
||||
/// ClientIPModel
|
||||
/// </summary>
|
||||
public class ClientIPModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,41 +10,42 @@ 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>
|
||||
/// Gets or sets the request.
|
||||
/// The Scenario.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
public string Scenario { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution state condition for the current mapping.
|
||||
/// </summary>
|
||||
public object WhenStateIs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The next state which will be signaled after the current mapping execution.
|
||||
/// In case the value is null state will not be changed.
|
||||
/// </summary>
|
||||
public object SetStateTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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; }
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,19 @@ namespace WireMock.Admin.Mappings
|
||||
/// </summary>
|
||||
public class RequestModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the ClientIP. (Can be a string or a ClientIPModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The ClientIP.
|
||||
/// </value>
|
||||
public object ClientIP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Path. (Can be a string or a PathModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The URL.
|
||||
/// The Path.
|
||||
/// </value>
|
||||
public object Path { get; set; }
|
||||
|
||||
|
||||
@@ -10,79 +10,76 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP status.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The HTTP status.
|
||||
/// </value>
|
||||
public int? StatusCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
||||
/// </summary>
|
||||
public string BodyDestination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body.
|
||||
/// </value>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body.
|
||||
/// </value>
|
||||
public string BodyAsBase64 { get; set; }
|
||||
public string BodyFromBase64 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body (as JSON object).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body.
|
||||
/// </value>
|
||||
public object BodyAsJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body (as bytearray).
|
||||
/// </summary>
|
||||
public byte[] BodyAsBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as a file.
|
||||
/// </summary>
|
||||
public string BodyAsFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the body as file cached?
|
||||
/// </summary>
|
||||
public bool? BodyAsFileIsCached { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body encoding.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body encoding.
|
||||
/// </value>
|
||||
public EncodingModel BodyEncoding { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether [use transformer].
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if [use transformer]; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool UseTransformer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the headers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The headers.
|
||||
/// </value>
|
||||
public IDictionary<string, string> Headers { get; set; }
|
||||
public IDictionary<string, object> Headers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Headers (Raw).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Headers (Raw).
|
||||
/// </value>
|
||||
public string HeadersRaw { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the delay in milliseconds.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The delay in milliseconds.
|
||||
/// </value>
|
||||
public int? Delay { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Proxy URL.
|
||||
/// </summary>
|
||||
/// <value>ProxyUrl</value>
|
||||
public string ProxyUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The client X509Certificate2 Thumbprint or SubjectName to use.
|
||||
/// </summary>
|
||||
public string X509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace WireMock.Admin.Requests
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Admin.Requests
|
||||
{
|
||||
/// <summary>
|
||||
/// LogRequestMatchModel
|
||||
@@ -36,5 +38,13 @@
|
||||
/// The match percentage.
|
||||
/// </value>
|
||||
public double AverageTotalScore { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the match details.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The match details.
|
||||
/// </value>
|
||||
public IList<object> MatchDetails { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,11 @@ namespace WireMock.Admin.Requests
|
||||
/// </summary>
|
||||
public class LogRequestModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Client IP Address.
|
||||
/// </summary>
|
||||
public string ClientIP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DateTime.
|
||||
/// </summary>
|
||||
@@ -18,17 +23,11 @@ namespace WireMock.Admin.Requests
|
||||
/// <summary>
|
||||
/// Gets or sets the Path.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Path.
|
||||
/// </value>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the absolete URL.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The absolute URL.
|
||||
/// </value>
|
||||
public string AbsoluteUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -39,41 +38,26 @@ namespace WireMock.Admin.Requests
|
||||
/// <summary>
|
||||
/// Gets or sets the method.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The method.
|
||||
/// </value>
|
||||
public string Method { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Headers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Headers.
|
||||
/// </value>
|
||||
public IDictionary<string, string> Headers { get; set; }
|
||||
public IDictionary<string, WireMockList<string>> Headers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Cookies.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Cookies.
|
||||
/// </value>
|
||||
public IDictionary<string, string> Cookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body.
|
||||
/// </value>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body encoding.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body encoding.
|
||||
/// </value>
|
||||
public EncodingModel BodyEncoding { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Admin.Requests
|
||||
{
|
||||
@@ -16,13 +17,33 @@ namespace WireMock.Admin.Requests
|
||||
/// <summary>
|
||||
/// Gets the headers.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Headers { get; set; }
|
||||
public IDictionary<string, WireMockList<string>> Headers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body destination (SameAsSource, String or Bytes).
|
||||
/// </summary>
|
||||
public string BodyDestination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as bytes.
|
||||
/// </summary>
|
||||
public byte[] BodyAsBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as file.
|
||||
/// </summary>
|
||||
public string BodyAsFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is the body as file cached?
|
||||
/// </summary>
|
||||
public bool? BodyAsFileIsCached { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original body.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,5 +14,15 @@
|
||||
/// Gets or sets if partial mapping is allowed.
|
||||
/// </summary>
|
||||
public bool? AllowPartialMapping { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the RequestLog expiration in hours
|
||||
/// </summary>
|
||||
public int? RequestLogExpirationDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the MaxRequestLog count.
|
||||
/// </summary>
|
||||
public int? MaxRequestLogCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Requests;
|
||||
using WireMock.Admin.Settings;
|
||||
|
||||
namespace WireMock.Client
|
||||
@@ -54,6 +55,7 @@ namespace WireMock.Client
|
||||
/// </summary>
|
||||
/// <param name="mapping">MappingModel</param>
|
||||
[Post("__admin/mappings")]
|
||||
[Header("Content-Type", "application/json")]
|
||||
Task<string> PostMappingAsync([Body] MappingModel mapping);
|
||||
|
||||
/// <summary>
|
||||
@@ -96,5 +98,65 @@ namespace WireMock.Client
|
||||
/// </summary>
|
||||
[Post("__admin/mappings/save")]
|
||||
Task<string> SaveMappingAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Get the requests.
|
||||
/// </summary>
|
||||
/// <returns>LogRequestModels</returns>
|
||||
[Get("__admin/requests")]
|
||||
Task<IList<LogEntryModel>> GetRequestsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete all requests.
|
||||
/// </summary>
|
||||
[Delete("__admin/requests")]
|
||||
Task<string> DeleteRequestsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete (reset) all requests.
|
||||
/// </summary>
|
||||
[Post("__admin/requests/reset")]
|
||||
Task<string> ResetRequestsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Get a request based on the guid
|
||||
/// </summary>
|
||||
/// <param name="guid">The Guid</param>
|
||||
/// <returns>MappingModel</returns>
|
||||
[Get("__admin/requests/{guid}")]
|
||||
Task<LogEntryModel> GetRequestAsync([Path] Guid guid);
|
||||
|
||||
/// <summary>
|
||||
/// Delete a request based on the guid
|
||||
/// </summary>
|
||||
/// <param name="guid">The Guid</param>
|
||||
[Delete("__admin/requests/{guid}")]
|
||||
Task<string> DeleteRequestAsync([Path] Guid guid);
|
||||
|
||||
/// <summary>
|
||||
/// Find a request based on the criteria
|
||||
/// </summary>
|
||||
/// <param name="model">The RequestModel</param>
|
||||
[Post("__admin/requests/find")]
|
||||
[Header("Content-Type", "application/json")]
|
||||
Task<IList<LogEntryModel>> FindRequestsAsync([Body] RequestModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Get all scenarios
|
||||
/// </summary>
|
||||
[Get("__admin/scenarios")]
|
||||
Task<string> GetScenariosAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete (reset) all scenarios
|
||||
/// </summary>
|
||||
[Delete("__admin/scenarios")]
|
||||
Task<string> DeleteScenariosAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Delete (reset) all scenarios
|
||||
/// </summary>
|
||||
[Post("__admin/scenarios")]
|
||||
Task<string> ResetScenariosAsync();
|
||||
}
|
||||
}
|
||||
@@ -42,10 +42,10 @@ namespace WireMock
|
||||
|
||||
internal class ProxyAsyncResponseProvider : IResponseProvider
|
||||
{
|
||||
private readonly Func<RequestMessage, ProxyAndRecordSettings, Task<ResponseMessage>> _responseMessageFunc;
|
||||
private readonly ProxyAndRecordSettings _settings;
|
||||
private readonly Func<RequestMessage, IProxyAndRecordSettings, Task<ResponseMessage>> _responseMessageFunc;
|
||||
private readonly IProxyAndRecordSettings _settings;
|
||||
|
||||
public ProxyAsyncResponseProvider([NotNull] Func<RequestMessage, ProxyAndRecordSettings, Task<ResponseMessage>> responseMessageFunc, [NotNull] ProxyAndRecordSettings settings)
|
||||
public ProxyAsyncResponseProvider([NotNull] Func<RequestMessage, IProxyAndRecordSettings, Task<ResponseMessage>> responseMessageFunc, [NotNull] IProxyAndRecordSettings settings)
|
||||
{
|
||||
Check.NotNull(responseMessageFunc, nameof(responseMessageFunc));
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
|
||||
@@ -1,81 +1,155 @@
|
||||
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
|
||||
{
|
||||
internal static class HttpClientHelper
|
||||
{
|
||||
private static HttpClient CreateHttpClient(string clientX509Certificate2Filename = null)
|
||||
public static HttpClient CreateHttpClient(string clientX509Certificate2ThumbprintOrSubjectName = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(clientX509Certificate2Filename))
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
var 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
|
||||
};
|
||||
|
||||
handler.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(clientX509Certificate2Filename));
|
||||
return new HttpClient(handler);
|
||||
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 handler = new WebRequestHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true
|
||||
};
|
||||
|
||||
handler.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate2(clientX509Certificate2Filename));
|
||||
return new HttpClient(handler);
|
||||
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);
|
||||
}
|
||||
|
||||
return new HttpClient();
|
||||
// For proxy we shouldn't follow auto redirects
|
||||
handler.AllowAutoRedirect = false;
|
||||
|
||||
// If UseCookies enabled, httpClient ignores Cookie header
|
||||
handler.UseCookies = false;
|
||||
|
||||
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(RequestMessage requestMessage, string url, string clientX509Certificate2Filename = null)
|
||||
public static async Task<ResponseMessage> SendAsync(HttpClient client, RequestMessage requestMessage, string url)
|
||||
{
|
||||
var client = CreateHttpClient(clientX509Certificate2Filename);
|
||||
Check.NotNull(client, nameof(client));
|
||||
|
||||
var originalUri = new Uri(requestMessage.Url);
|
||||
var requiredUri = new Uri(url);
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage(new HttpMethod(requestMessage.Method), url);
|
||||
|
||||
// Set Body if present
|
||||
if (requestMessage.BodyAsBytes != null)
|
||||
{
|
||||
httpRequestMessage.Content = new ByteArrayContent(requestMessage.BodyAsBytes);
|
||||
}
|
||||
|
||||
// Overwrite the host header
|
||||
httpRequestMessage.Headers.Host = new Uri(url).Authority;
|
||||
httpRequestMessage.Headers.Host = requiredUri.Authority;
|
||||
|
||||
// Set headers if present
|
||||
if (requestMessage.Headers != null)
|
||||
{
|
||||
foreach (var headerName in requestMessage.Headers.Keys.Where(k => k.ToUpper() != "HOST"))
|
||||
foreach (var header in requestMessage.Headers.Where(header => !string.Equals(header.Key, "HOST", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
httpRequestMessage.Headers.Add(headerName, new[] { requestMessage.Headers[headerName] });
|
||||
// Try to add to request headers. If failed - try to add to content headers
|
||||
if (!httpRequestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value))
|
||||
{
|
||||
httpRequestMessage.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set Body if present
|
||||
if (requestMessage.BodyAsBytes != null && requestMessage.BodyAsBytes.Length > 0)
|
||||
{
|
||||
httpRequestMessage.Content = new ByteArrayContent(requestMessage.BodyAsBytes);
|
||||
}
|
||||
|
||||
// Call the URL
|
||||
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead);
|
||||
|
||||
// Transform response
|
||||
var responseMessage = new ResponseMessage
|
||||
{
|
||||
StatusCode = (int)httpResponseMessage.StatusCode,
|
||||
Body = await httpResponseMessage.Content.ReadAsStringAsync()
|
||||
};
|
||||
// Create transform response
|
||||
var responseMessage = new ResponseMessage { StatusCode = (int)httpResponseMessage.StatusCode };
|
||||
|
||||
foreach (var header in httpResponseMessage.Headers)
|
||||
// Set both content and response headers, replacing URLs in values
|
||||
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)
|
||||
{
|
||||
responseMessage.AddHeader(header.Key, header.Value.FirstOrDefault());
|
||||
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,
|
||||
// we need to replace it to original one.
|
||||
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))
|
||||
{
|
||||
var replacedLocationUri = new Uri(originalUri, absoluteLocationUri.PathAndQuery);
|
||||
responseMessage.AddHeader(header.Key, replacedLocationUri.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
responseMessage.AddHeader(header.Key, header.Value.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
96
src/WireMock.Net/Http/HttpKnownHeaderNames.cs
Normal file
96
src/WireMock.Net/Http/HttpKnownHeaderNames.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// Copied from https://raw.githubusercontent.com/dotnet/corefx/master/src/Common/src/System/Net/HttpKnownHeaderNames.cs
|
||||
/// </summary>
|
||||
internal static class HttpKnownHeaderNames
|
||||
{
|
||||
public const string Accept = "Accept";
|
||||
public const string AcceptCharset = "Accept-Charset";
|
||||
public const string AcceptEncoding = "Accept-Encoding";
|
||||
public const string AcceptLanguage = "Accept-Language";
|
||||
public const string AcceptPatch = "Accept-Patch";
|
||||
public const string AcceptRanges = "Accept-Ranges";
|
||||
public const string AccessControlAllowCredentials = "Access-Control-Allow-Credentials";
|
||||
public const string AccessControlAllowHeaders = "Access-Control-Allow-Headers";
|
||||
public const string AccessControlAllowMethods = "Access-Control-Allow-Methods";
|
||||
public const string AccessControlAllowOrigin = "Access-Control-Allow-Origin";
|
||||
public const string AccessControlExposeHeaders = "Access-Control-Expose-Headers";
|
||||
public const string AccessControlMaxAge = "Access-Control-Max-Age";
|
||||
public const string Age = "Age";
|
||||
public const string Allow = "Allow";
|
||||
public const string AltSvc = "Alt-Svc";
|
||||
public const string Authorization = "Authorization";
|
||||
public const string CacheControl = "Cache-Control";
|
||||
public const string Connection = "Connection";
|
||||
public const string ContentDisposition = "Content-Disposition";
|
||||
public const string ContentEncoding = "Content-Encoding";
|
||||
public const string ContentLanguage = "Content-Language";
|
||||
public const string ContentLength = "Content-Length";
|
||||
public const string ContentLocation = "Content-Location";
|
||||
public const string ContentMD5 = "Content-MD5";
|
||||
public const string ContentRange = "Content-Range";
|
||||
public const string ContentSecurityPolicy = "Content-Security-Policy";
|
||||
public const string ContentType = "Content-Type";
|
||||
public const string Cookie = "Cookie";
|
||||
public const string Cookie2 = "Cookie2";
|
||||
public const string Date = "Date";
|
||||
public const string ETag = "ETag";
|
||||
public const string Expect = "Expect";
|
||||
public const string Expires = "Expires";
|
||||
public const string From = "From";
|
||||
public const string Host = "Host";
|
||||
public const string IfMatch = "If-Match";
|
||||
public const string IfModifiedSince = "If-Modified-Since";
|
||||
public const string IfNoneMatch = "If-None-Match";
|
||||
public const string IfRange = "If-Range";
|
||||
public const string IfUnmodifiedSince = "If-Unmodified-Since";
|
||||
public const string KeepAlive = "Keep-Alive";
|
||||
public const string LastModified = "Last-Modified";
|
||||
public const string Link = "Link";
|
||||
public const string Location = "Location";
|
||||
public const string MaxForwards = "Max-Forwards";
|
||||
public const string Origin = "Origin";
|
||||
public const string P3P = "P3P";
|
||||
public const string Pragma = "Pragma";
|
||||
public const string ProxyAuthenticate = "Proxy-Authenticate";
|
||||
public const string ProxyAuthorization = "Proxy-Authorization";
|
||||
public const string ProxyConnection = "Proxy-Connection";
|
||||
public const string PublicKeyPins = "Public-Key-Pins";
|
||||
public const string Range = "Range";
|
||||
public const string Referer = "Referer"; // NB: The spelling-mistake "Referer" for "Referrer" must be matched.
|
||||
public const string RetryAfter = "Retry-After";
|
||||
public const string SecWebSocketAccept = "Sec-WebSocket-Accept";
|
||||
public const string SecWebSocketExtensions = "Sec-WebSocket-Extensions";
|
||||
public const string SecWebSocketKey = "Sec-WebSocket-Key";
|
||||
public const string SecWebSocketProtocol = "Sec-WebSocket-Protocol";
|
||||
public const string SecWebSocketVersion = "Sec-WebSocket-Version";
|
||||
public const string Server = "Server";
|
||||
public const string SetCookie = "Set-Cookie";
|
||||
public const string SetCookie2 = "Set-Cookie2";
|
||||
public const string StrictTransportSecurity = "Strict-Transport-Security";
|
||||
public const string TE = "TE";
|
||||
public const string TSV = "TSV";
|
||||
public const string Trailer = "Trailer";
|
||||
public const string TransferEncoding = "Transfer-Encoding";
|
||||
public const string Upgrade = "Upgrade";
|
||||
public const string UpgradeInsecureRequests = "Upgrade-Insecure-Requests";
|
||||
public const string UserAgent = "User-Agent";
|
||||
public const string Vary = "Vary";
|
||||
public const string Via = "Via";
|
||||
public const string WWWAuthenticate = "WWW-Authenticate";
|
||||
public const string Warning = "Warning";
|
||||
public const string XAspNetVersion = "X-AspNet-Version";
|
||||
public const string XContentDuration = "X-Content-Duration";
|
||||
public const string XContentTypeOptions = "X-Content-Type-Options";
|
||||
public const string XFrameOptions = "X-Frame-Options";
|
||||
public const string XMSEdgeRef = "X-MSEdge-Ref";
|
||||
public const string XPoweredBy = "X-Powered-By";
|
||||
public const string XRequestID = "X-Request-ID";
|
||||
public const string XUACompatible = "X-UA-Compatible";
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// The ports.
|
||||
/// Port Utility class
|
||||
/// </summary>
|
||||
public static class PortUtil
|
||||
{
|
||||
private static readonly Regex UrlDetailsRegex = new Regex(@"^(?<proto>\w+)://[^/]+?(?<port>\d+)?/", RegexOptions.Compiled);
|
||||
|
||||
/// <summary>
|
||||
/// The find free TCP port.
|
||||
/// Finds a free TCP port.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="int"/>.
|
||||
/// </returns>
|
||||
/// <remarks>see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net.</remarks>
|
||||
public static int FindFreeTcpPort()
|
||||
{
|
||||
@@ -30,5 +30,24 @@ namespace WireMock.Http
|
||||
tcpListener?.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract a proto and port from a URL.
|
||||
/// </summary>
|
||||
public static bool TryExtractProtocolAndPort(string url, out string proto, out int port)
|
||||
{
|
||||
proto = null;
|
||||
port = 0;
|
||||
|
||||
Match m = UrlDetailsRegex.Match(url);
|
||||
if (m.Success)
|
||||
{
|
||||
proto = m.Groups["proto"].Value;
|
||||
|
||||
return int.TryParse(m.Groups["port"].Value, out port);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs
Normal file
41
src/WireMock.Net/HttpsCertificate/ClientCertificateHelper.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace WireMock.HttpsCertificate
|
||||
{
|
||||
internal static class ClientCertificateHelper
|
||||
{
|
||||
public static X509Certificate2 GetCertificate(string thumbprintOrSubjectName)
|
||||
{
|
||||
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
|
||||
try
|
||||
{
|
||||
//Certificate must be in the local machine store
|
||||
certStore.Open(OpenFlags.ReadOnly);
|
||||
|
||||
//Attempt to find by thumbprint first
|
||||
var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjectName, false);
|
||||
if (matchingCertificates.Count == 0)
|
||||
{
|
||||
//Fallback to subject name
|
||||
matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubjectName, false);
|
||||
if (matchingCertificates.Count == 0)
|
||||
{
|
||||
// No certificates matched the search criteria.
|
||||
throw new Exception($"No certificate found with Thumbprint or SubjectName '{thumbprintOrSubjectName}'");
|
||||
}
|
||||
}
|
||||
// Use the first matching certificate.
|
||||
return matchingCertificates[0];
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if NETSTANDARD || NET46
|
||||
certStore.Dispose();
|
||||
#else
|
||||
certStore.Close();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +1,139 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
/// <summary>
|
||||
/// The Mapping.
|
||||
/// </summary>
|
||||
public class Mapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the unique identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The unique identifier.
|
||||
/// </value>
|
||||
public Guid Guid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The unique title.
|
||||
/// </value>
|
||||
public string Title { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The priority.
|
||||
/// </value>
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Request matcher.
|
||||
/// </summary>
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Provider.
|
||||
/// </summary>
|
||||
public IResponseProvider Provider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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="requestMatcher">The request matcher.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
/// <param name="priority">The priority for this mapping.</param>
|
||||
public Mapping(Guid guid, [CanBeNull] string title, IRequestMatcher requestMatcher, IResponseProvider provider, int priority)
|
||||
{
|
||||
Priority = priority;
|
||||
Guid = guid;
|
||||
Title = title;
|
||||
RequestMatcher = requestMatcher;
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The response to.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <returns>The <see cref="ResponseMessage"/>.</returns>
|
||||
public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage)
|
||||
{
|
||||
return await Provider.ProvideResponseAsync(requestMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the RequestMessage is handled.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <returns>The <see cref="RequestMatchResult"/>.</returns>
|
||||
public RequestMatchResult IsRequestHandled(RequestMessage requestMessage)
|
||||
{
|
||||
var result = new RequestMatchResult();
|
||||
|
||||
RequestMatcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this mapping is an Admin Interface.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;
|
||||
}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
/// <summary>
|
||||
/// The Mapping.
|
||||
/// </summary>
|
||||
public class Mapping
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the unique identifier.
|
||||
/// </summary>
|
||||
public Guid Guid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique title.
|
||||
/// </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>
|
||||
public int Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Scenario.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public string Scenario { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Execution state condition for the current mapping.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public object ExecutionConditionState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The next state which will be signaled after the current mapping execution.
|
||||
/// In case the value is null state will not be changed.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
public object NextState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Request matcher.
|
||||
/// </summary>
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Provider.
|
||||
/// </summary>
|
||||
public IResponseProvider Provider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Is State started ?
|
||||
/// </summary>
|
||||
public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null;
|
||||
|
||||
/// <summary>
|
||||
/// 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="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, [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;
|
||||
Scenario = scenario;
|
||||
ExecutionConditionState = executionConditionState;
|
||||
NextState = nextState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The response to.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <returns>The <see cref="ResponseMessage"/>.</returns>
|
||||
public async Task<ResponseMessage> ResponseToAsync(RequestMessage requestMessage)
|
||||
{
|
||||
return await Provider.ProvideResponseAsync(requestMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the RequestMatchResult based on the RequestMessage.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <param name="nextState">The Next State.</param>
|
||||
/// <returns>The <see cref="RequestMatchResult"/>.</returns>
|
||||
public RequestMatchResult GetRequestMatchResult(RequestMessage requestMessage, [CanBeNull] object nextState)
|
||||
{
|
||||
var result = new RequestMatchResult();
|
||||
|
||||
RequestMatcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Only check state if Scenario is defined
|
||||
if (Scenario != null)
|
||||
{
|
||||
var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
|
||||
matcher.GetMatchingScore(requestMessage, result);
|
||||
//// If ExecutionConditionState is null, this means that request is the start from a scenario. So just return.
|
||||
//if (ExecutionConditionState != null)
|
||||
//{
|
||||
// // ExecutionConditionState is not null, so get score for matching with the nextState.
|
||||
// var matcher = new RequestMessageScenarioAndStateMatcher(nextState, ExecutionConditionState);
|
||||
// matcher.GetMatchingScore(requestMessage, result);
|
||||
//}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this mapping is an Admin Interface.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if this mapping is an Admin Interface; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,11 @@ namespace WireMock.Matchers
|
||||
/// </summary>
|
||||
public const double Perfect = 1.0;
|
||||
|
||||
/// <summary>
|
||||
/// The almost perfect match score
|
||||
/// </summary>
|
||||
public const double AlmostPerfect = 0.99;
|
||||
|
||||
/// <summary>
|
||||
/// Convert a bool to the score.
|
||||
/// </summary>
|
||||
@@ -37,22 +42,20 @@ namespace WireMock.Matchers
|
||||
/// Calculates the score from multiple funcs.
|
||||
/// </summary>
|
||||
/// <param name="values">The values.</param>
|
||||
/// <returns>score</returns>
|
||||
/// <returns>average score</returns>
|
||||
public static double ToScore(IEnumerable<bool> values)
|
||||
{
|
||||
var list = values.Select(ToScore).ToList();
|
||||
return list.Sum() / list.Count;
|
||||
return values.Any() ? values.Select(ToScore).Average() : Mismatch;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the score from multiple funcs.
|
||||
/// </summary>
|
||||
/// <param name="values">The values.</param>
|
||||
/// <returns>score</returns>
|
||||
/// <returns>average score</returns>
|
||||
public static double ToScore(IEnumerable<double> values)
|
||||
{
|
||||
var list = values.ToList();
|
||||
return list.Sum() / list.Count;
|
||||
return values.Any() ? values.Average() : Mismatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -13,7 +14,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <value>
|
||||
/// The match-score.
|
||||
/// </value>
|
||||
public double TotalScore { get; set; }
|
||||
public double TotalScore { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of matches.
|
||||
@@ -21,7 +22,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <value>
|
||||
/// The total number of matches.
|
||||
/// </value>
|
||||
public int TotalNumber { get; set; }
|
||||
public int TotalNumber { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this instance is perfect match.
|
||||
@@ -39,6 +40,31 @@ namespace WireMock.Matchers.Request
|
||||
/// </value>
|
||||
public double AverageTotalScore => TotalNumber == 0 ? 0.0 : TotalScore / TotalNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the match details.
|
||||
/// </summary>
|
||||
public IList<KeyValuePair<Type, double>> MatchDetails { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMatchResult"/> class.
|
||||
/// </summary>
|
||||
public RequestMatchResult() => MatchDetails = new List<KeyValuePair<Type, double>>();
|
||||
|
||||
/// <summary>
|
||||
/// Adds the score.
|
||||
/// </summary>
|
||||
/// <param name="matcherType">The matcher Type.</param>
|
||||
/// <param name="score">The score.</param>
|
||||
/// <returns>The score.</returns>
|
||||
public double AddScore(Type matcherType, double score)
|
||||
{
|
||||
TotalScore += score;
|
||||
TotalNumber++;
|
||||
MatchDetails.Add(new KeyValuePair<Type, double>(matcherType, score));
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
|
||||
/// </summary>
|
||||
@@ -46,7 +72,6 @@ namespace WireMock.Matchers.Request
|
||||
/// <returns>
|
||||
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes <paramref name="obj" /> in the sort order. Zero This instance occurs in the same position in the sort order as <paramref name="obj" />. Greater than zero This instance follows <paramref name="obj" /> in the sort order.
|
||||
/// </returns>
|
||||
/// <exception cref="System.NotImplementedException"></exception>
|
||||
public int CompareTo(object obj)
|
||||
{
|
||||
var compareObj = (RequestMatchResult)obj;
|
||||
|
||||
@@ -98,11 +98,7 @@ namespace WireMock.Matchers.Request
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The request ClientIP matcher.
|
||||
/// </summary>
|
||||
public class RequestMessageClientIPMatcher : IRequestMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// The matchers.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IMatcher> Matchers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The ClientIP functions.
|
||||
/// </summary>
|
||||
public Func<string, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="clientIPs">The clientIPs.</param>
|
||||
public RequestMessageClientIPMatcher([NotNull] params string[] clientIPs) : this(clientIPs.Select(ip => new WildcardMatcher(ip)).Cast<IMatcher>().ToArray())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageClientIPMatcher([NotNull] params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Matchers = matchers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageClientIPMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The clientIP functions.</param>
|
||||
public RequestMessageClientIPMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (Matchers != null)
|
||||
return Matchers.Max(matcher => matcher.IsMatch(requestMessage.ClientIP));
|
||||
|
||||
if (Funcs != null)
|
||||
return MatchScores.ToScore(requestMessage.ClientIP != null && Funcs.Any(func => func(requestMessage.ClientIP)));
|
||||
|
||||
return MatchScores.Mismatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ namespace WireMock.Matchers.Request
|
||||
/// </returns>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
if (!RequestMatchers.Any())
|
||||
{
|
||||
return MatchScores.Mismatch;
|
||||
}
|
||||
|
||||
if (_type == CompositeMatcherType.And)
|
||||
{
|
||||
return RequestMatchers.Average(requestMatcher => requestMatcher.GetMatchingScore(requestMessage, requestMatchResult));
|
||||
|
||||
@@ -77,11 +77,7 @@ namespace WireMock.Matchers.Request
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
@@ -9,12 +10,13 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// The request header matcher.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="IRequestMatcher"/>
|
||||
public class RequestMessageHeaderMatcher : IRequestMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// The functions
|
||||
/// </summary>
|
||||
public Func<IDictionary<string, string>, bool>[] Funcs { get; }
|
||||
public Func<IDictionary<string, string[]>, bool>[] Funcs { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name
|
||||
@@ -31,7 +33,7 @@ namespace WireMock.Matchers.Request
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="pattern">The pattern.</param>
|
||||
/// <param name="ignoreCase">The ignoreCase.</param>
|
||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
||||
public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string pattern, bool ignoreCase = true)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
@@ -41,6 +43,21 @@ namespace WireMock.Matchers.Request
|
||||
Matchers = new IMatcher[] { new WildcardMatcher(pattern, ignoreCase) };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
||||
public RequestMessageHeaderMatcher([NotNull] string name, [NotNull] string[] patterns, bool ignoreCase = true)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
|
||||
Name = name;
|
||||
Matchers = patterns.Select(pattern => new WildcardMatcher(pattern, ignoreCase)).Cast<IMatcher>().ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class.
|
||||
/// </summary>
|
||||
@@ -59,29 +76,18 @@ namespace WireMock.Matchers.Request
|
||||
/// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The funcs.</param>
|
||||
public RequestMessageHeaderMatcher([NotNull] params Func<IDictionary<string, string>, bool>[] funcs)
|
||||
public RequestMessageHeaderMatcher([NotNull] params Func<IDictionary<string, string[]>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified RequestMessage is match.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The RequestMessage.</param>
|
||||
/// <param name="requestMatchResult">The RequestMatchResult.</param>
|
||||
/// <returns>
|
||||
/// A value between 0.0 - 1.0 of the similarity.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
@@ -90,7 +96,7 @@ namespace WireMock.Matchers.Request
|
||||
return MatchScores.Mismatch;
|
||||
|
||||
if (Funcs != null)
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Headers)));
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Headers.ToDictionary(entry => entry.Key, entry => entry.Value.ToArray()))));
|
||||
|
||||
if (Matchers == null)
|
||||
return MatchScores.Mismatch;
|
||||
@@ -98,8 +104,8 @@ namespace WireMock.Matchers.Request
|
||||
if (!requestMessage.Headers.ContainsKey(Name))
|
||||
return MatchScores.Mismatch;
|
||||
|
||||
string value = requestMessage.Headers[Name];
|
||||
return Matchers.Max(m => m.IsMatch(value));
|
||||
WireMockList<string> list = requestMessage.Headers[Name];
|
||||
return Matchers.Max(m => list.Max(value => m.IsMatch(value))); // TODO : is this correct ?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,7 @@ namespace WireMock.Matchers.Request
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
|
||||
@@ -30,12 +30,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="key">
|
||||
/// The key.
|
||||
/// </param>
|
||||
/// <param name="values">
|
||||
/// The values.
|
||||
/// </param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="values">The values.</param>
|
||||
public RequestMessageParamMatcher([NotNull] string key, [CanBeNull] IEnumerable<string> values)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
@@ -51,31 +47,23 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified RequestMessage is match.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The RequestMessage.</param>
|
||||
/// <param name="requestMatchResult">The RequestMatchResult.</param>
|
||||
/// <returns>
|
||||
/// A value between 0.0 - 1.0 of the similarity.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
if (Funcs != null)
|
||||
{
|
||||
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
|
||||
}
|
||||
|
||||
List<string> values = requestMessage.GetParameter(Key);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace WireMock.Matchers.Request
|
||||
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="paths">The paths.</param>
|
||||
public RequestMessagePathMatcher([NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(path)).ToArray())
|
||||
public RequestMessagePathMatcher([NotNull] params string[] paths) : this(paths.Select(path => new WildcardMatcher(path)).Cast<IMatcher>().ToArray())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,22 +49,11 @@ namespace WireMock.Matchers.Request
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified RequestMessage is match.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The RequestMessage.</param>
|
||||
/// <param name="requestMatchResult">The RequestMatchResult.</param>
|
||||
/// <returns>
|
||||
/// A value between 0.0 - 1.0 of the similarity.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The scenario and state matcher.
|
||||
/// </summary>
|
||||
internal class RequestMessageScenarioAndStateMatcher : IRequestMatcher
|
||||
{
|
||||
///// <summary>
|
||||
///// Scenario.
|
||||
///// </summary>
|
||||
//[CanBeNull] private string _scenario;
|
||||
|
||||
/// <summary>
|
||||
/// Execution state condition for the current mapping.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
private readonly object _executionConditionState;
|
||||
|
||||
/// <summary>
|
||||
/// The next state which will be signaled after the current mapping execution.
|
||||
/// In case the value is null state will not be changed.
|
||||
/// </summary>
|
||||
[CanBeNull]
|
||||
private readonly object _nextState;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageScenarioAndStateMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="nextState">The next state.</param>
|
||||
/// <param name="executionConditionState">Execution state condition for the current mapping.</param>
|
||||
public RequestMessageScenarioAndStateMatcher([CanBeNull] object nextState, [CanBeNull] object executionConditionState)
|
||||
{
|
||||
_nextState = nextState;
|
||||
_executionConditionState = executionConditionState;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch();
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch()
|
||||
{
|
||||
return Equals(_executionConditionState, _nextState) ? MatchScores.Perfect : MatchScores.Mismatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,12 @@ namespace WireMock.Matchers.Request
|
||||
public class RequestMessageUrlMatcher : IRequestMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// The matcher.
|
||||
/// The matchers.
|
||||
/// </summary>
|
||||
public IReadOnlyList<IMatcher> Matchers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The url functions
|
||||
/// The url functions.
|
||||
/// </summary>
|
||||
public Func<string, bool>[] Funcs { get; }
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace WireMock.Matchers.Request
|
||||
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="urls">The urls.</param>
|
||||
public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(url)).ToArray())
|
||||
public RequestMessageUrlMatcher([NotNull] params string[] urls) : this(urls.Select(url => new WildcardMatcher(url)).Cast<IMatcher>().ToArray())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,22 +49,11 @@ namespace WireMock.Matchers.Request
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified RequestMessage is match.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">The RequestMessage.</param>
|
||||
/// <param name="requestMatchResult">The RequestMatchResult.</param>
|
||||
/// <returns>
|
||||
/// A value between 0.0 - 1.0 of the similarity.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/>
|
||||
public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)
|
||||
{
|
||||
double score = IsMatch(requestMessage);
|
||||
requestMatchResult.TotalScore += score;
|
||||
|
||||
requestMatchResult.TotalNumber++;
|
||||
|
||||
return score;
|
||||
return requestMatchResult.AddScore(GetType(), score);
|
||||
}
|
||||
|
||||
private double IsMatch(RequestMessage requestMessage)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Linq;
|
||||
using System.Xml;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
#if !NETSTANDARD
|
||||
#if !NETSTANDARD1_3
|
||||
using Wmhelp.XPath2;
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace WireMock.Matchers
|
||||
try
|
||||
{
|
||||
var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
|
||||
#if NETSTANDARD
|
||||
#if NETSTANDARD1_3
|
||||
return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.Evaluate($"boolean({p})"))));
|
||||
#else
|
||||
return MatchScores.ToScore(_patterns.Select(p => true.Equals(nav.XPath2Evaluate($"boolean({p})"))));
|
||||
|
||||
@@ -1,13 +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 Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Http;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -16,49 +18,92 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly string[] _uriPrefixes;
|
||||
private readonly string[] _urls;
|
||||
|
||||
private IWebHost _host;
|
||||
|
||||
public bool IsStarted { get; private set; }
|
||||
|
||||
public List<Uri> Urls { get; } = new List<Uri>();
|
||||
public List<string> Urls { get; } = new List<string>();
|
||||
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
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)
|
||||
{
|
||||
var uri = new Uri(uriPrefix);
|
||||
Urls.Add(uri);
|
||||
Ports.Add(uri.Port);
|
||||
Urls.Add(uriPrefix);
|
||||
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
Ports.Add(port);
|
||||
}
|
||||
|
||||
_options = options;
|
||||
_uriPrefixes = uriPrefixes;
|
||||
_urls = uriPrefixes;
|
||||
}
|
||||
|
||||
public Task StartAsync()
|
||||
{
|
||||
_host = new WebHostBuilder()
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
appBuilder.UseMiddleware<GlobalExceptionMiddleware>();
|
||||
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(appBuilder);
|
||||
})
|
||||
.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
|
||||
Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.ConfigureLogging(factory => factory.AddConsole(LogLevel.None))
|
||||
.Configure(appBuilder =>
|
||||
{
|
||||
// appBuilder.UseExceptionHandler(builder => )
|
||||
appBuilder.UseMiddleware<WireMockMiddleware>(_options);
|
||||
})
|
||||
.UseKestrel()
|
||||
.UseUrls(_uriPrefixes)
|
||||
.Build();
|
||||
|
||||
host.Run(_cts.Token);
|
||||
|
||||
_host.Run(_cts.Token);
|
||||
IsStarted = true;
|
||||
}, _cts.Token);
|
||||
#else
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||
IsStarted = true;
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_host.Run();
|
||||
IsStarted = true;
|
||||
}, _cts.Token);
|
||||
#endif
|
||||
}
|
||||
|
||||
public Task StopAsync()
|
||||
@@ -66,34 +111,11 @@ namespace WireMock.Owin
|
||||
_cts.Cancel();
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
}
|
||||
|
||||
internal class Startup
|
||||
{
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
//var builder = new ConfigurationBuilder()
|
||||
// .SetBasePath(env.ContentRootPath)
|
||||
// .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
||||
// .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
||||
// .AddEnvironmentVariables();
|
||||
//Configuration = builder.Build();
|
||||
}
|
||||
|
||||
// public IConfigurationRoot Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
{
|
||||
app.UseMiddleware<WireMockMiddleware>();
|
||||
#else
|
||||
return _host.WaitForShutdownAsync();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
49
src/WireMock.Net/Owin/GlobalExceptionMiddleware.cs
Normal file
49
src/WireMock.Net/Owin/GlobalExceptionMiddleware.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
internal class GlobalExceptionMiddleware : OwinMiddleware
|
||||
#else
|
||||
internal class GlobalExceptionMiddleware
|
||||
#endif
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
public GlobalExceptionMiddleware(OwinMiddleware next) : base(next) { }
|
||||
#else
|
||||
public GlobalExceptionMiddleware(RequestDelegate next)
|
||||
{
|
||||
Next = next;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD
|
||||
public RequestDelegate Next { get; }
|
||||
#endif
|
||||
|
||||
private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
|
||||
|
||||
#if !NETSTANDARD
|
||||
public override async Task Invoke(IOwinContext ctx)
|
||||
#else
|
||||
public async Task Invoke(HttpContext ctx)
|
||||
#endif
|
||||
{
|
||||
try
|
||||
{
|
||||
await Next?.Invoke(ctx);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _responseMapper.MapAsync(new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) }, ctx.Response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -15,12 +14,12 @@ namespace WireMock.Owin
|
||||
bool IsStarted { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url.
|
||||
/// Gets the urls.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
List<Uri> Urls { get; }
|
||||
List<string> Urls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ports.
|
||||
|
||||
@@ -1,69 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
/// <summary>
|
||||
/// OwinRequestMapper
|
||||
/// </summary>
|
||||
public class OwinRequestMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// MapAsync IOwinRequest to RequestMessage
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RequestMessage> MapAsync(
|
||||
#if !NETSTANDARD
|
||||
IOwinRequest request
|
||||
#else
|
||||
HttpRequest request
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
Uri url = request.Uri;
|
||||
#else
|
||||
Uri url = new Uri(request.GetEncodedUrl());
|
||||
#endif
|
||||
string verb = request.Method;
|
||||
|
||||
string bodyAsString = null;
|
||||
byte[] body = null;
|
||||
Encoding bodyEncoding = null;
|
||||
if (request.Body != null)
|
||||
{
|
||||
using (var streamReader = new StreamReader(request.Body))
|
||||
{
|
||||
bodyAsString = await streamReader.ReadToEndAsync();
|
||||
bodyEncoding = streamReader.CurrentEncoding;
|
||||
}
|
||||
|
||||
body = bodyEncoding.GetBytes(bodyAsString);
|
||||
}
|
||||
|
||||
var listenerHeaders = request.Headers;
|
||||
|
||||
var headers = new Dictionary<string, string>();
|
||||
foreach (var header in listenerHeaders)
|
||||
headers.Add(header.Key, header.Value.FirstOrDefault());
|
||||
|
||||
var cookies = new Dictionary<string, string>();
|
||||
|
||||
foreach (var cookie in request.Cookies)
|
||||
cookies.Add(cookie.Key, cookie.Value);
|
||||
|
||||
return new RequestMessage(url, verb, body, bodyAsString, bodyEncoding, headers, cookies) { DateTime = DateTime.Now };
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
/// <summary>
|
||||
/// OwinRequestMapper
|
||||
/// </summary>
|
||||
public class OwinRequestMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// MapAsync IOwinRequest to RequestMessage
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RequestMessage> MapAsync(
|
||||
#if !NETSTANDARD
|
||||
IOwinRequest request
|
||||
#else
|
||||
HttpRequest request
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
Uri url = request.Uri;
|
||||
string clientIP = request.RemoteIpAddress;
|
||||
#else
|
||||
Uri url = new Uri(request.GetEncodedUrl());
|
||||
var connection = request.HttpContext.Connection;
|
||||
string clientIP = connection.RemoteIpAddress.IsIPv4MappedToIPv6
|
||||
? connection.RemoteIpAddress.MapToIPv4().ToString()
|
||||
: connection.RemoteIpAddress.ToString();
|
||||
#endif
|
||||
string method = request.Method;
|
||||
|
||||
string bodyAsString = null;
|
||||
byte[] body = null;
|
||||
Encoding bodyEncoding = null;
|
||||
if (ParseBody(method) && request.Body != null)
|
||||
{
|
||||
using (var streamReader = new StreamReader(request.Body))
|
||||
{
|
||||
bodyAsString = await streamReader.ReadToEndAsync();
|
||||
bodyEncoding = streamReader.CurrentEncoding;
|
||||
}
|
||||
|
||||
body = bodyEncoding.GetBytes(bodyAsString);
|
||||
}
|
||||
|
||||
Dictionary<string, string[]> headers = null;
|
||||
if (request.Headers.Any())
|
||||
{
|
||||
headers = new Dictionary<string, string[]>();
|
||||
foreach (var header in request.Headers)
|
||||
{
|
||||
headers.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
IDictionary<string, string> cookies = null;
|
||||
if (request.Cookies.Any())
|
||||
{
|
||||
cookies = new Dictionary<string, string>();
|
||||
foreach (var cookie in request.Cookies)
|
||||
{
|
||||
cookies.Add(cookie.Key, cookie.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return new RequestMessage(url, method, clientIP, body, bodyAsString, bodyEncoding, headers, cookies) { DateTime = DateTime.Now };
|
||||
}
|
||||
|
||||
private bool ParseBody(string method)
|
||||
{
|
||||
/*
|
||||
HEAD - No defined body semantics.
|
||||
GET - No defined body semantics.
|
||||
PUT - Body supported.
|
||||
POST - Body supported.
|
||||
DELETE - No defined body semantics.
|
||||
TRACE - Body not supported.
|
||||
OPTIONS - Body supported but no semantics on usage (maybe in the future).
|
||||
CONNECT - No defined body semantics
|
||||
PATCH - Body supported.
|
||||
*/
|
||||
return new[] { "PUT", "POST", "OPTIONS", "PATCH" }.Contains(method.ToUpper());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Util;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
@@ -17,6 +21,19 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly Encoding _utf8NoBom = new UTF8Encoding(false);
|
||||
|
||||
// https://stackoverflow.com/questions/239725/cannot-set-some-http-headers-when-using-system-net-webrequest
|
||||
#if !NETSTANDARD
|
||||
private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<IOwinResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#else
|
||||
private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<HttpResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#endif
|
||||
{ "Content-Length", null },
|
||||
{ "Content-Type", (r, v) => r.ContentType = v.FirstOrDefault() },
|
||||
{ "Keep-Alive", null },
|
||||
{ "Transfer-Encoding", null },
|
||||
{ "WWW-Authenticate", null }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// MapAsync ResponseMessage to OwinResponse
|
||||
/// </summary>
|
||||
@@ -32,13 +49,54 @@ namespace WireMock.Owin
|
||||
{
|
||||
response.StatusCode = responseMessage.StatusCode;
|
||||
|
||||
responseMessage.Headers.ToList().ForEach(pair => response.Headers.Append(pair.Key, pair.Value));
|
||||
// Set headers
|
||||
foreach (var pair in responseMessage.Headers)
|
||||
{
|
||||
if (RestrictedResponseHeaders.ContainsKey(pair.Key))
|
||||
{
|
||||
RestrictedResponseHeaders[pair.Key]?.Invoke(response, pair.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
response.Headers.AppendValues(pair.Key, pair.Value.ToArray());
|
||||
#else
|
||||
response.Headers.Append(pair.Key, pair.Value.ToArray());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (responseMessage.Body == null)
|
||||
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null && responseMessage.BodyAsJson == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Encoding encoding = responseMessage.BodyEncoding ?? _utf8NoBom;
|
||||
using (var writer = new StreamWriter(response.Body, encoding))
|
||||
if (responseMessage.BodyAsBytes != null)
|
||||
{
|
||||
await response.Body.WriteAsync(responseMessage.BodyAsBytes, 0, responseMessage.BodyAsBytes.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
if (responseMessage.BodyAsFile != null)
|
||||
{
|
||||
byte[] bytes = File.ReadAllBytes(responseMessage.BodyAsFile);
|
||||
|
||||
await response.Body.WriteAsync(bytes, 0, bytes.Length);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Owin;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using WireMock.Http;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -14,18 +15,18 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private System.Threading.Thread _internalThread;
|
||||
|
||||
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)
|
||||
{
|
||||
var uri = new Uri(uriPrefix);
|
||||
Urls.Add(uri);
|
||||
Ports.Add(uri.Port);
|
||||
Urls.Add(uriPrefix);
|
||||
|
||||
PortUtil.TryExtractProtocolAndPort(uriPrefix, out string host, out int port);
|
||||
Ports.Add(port);
|
||||
}
|
||||
|
||||
_options = options;
|
||||
@@ -33,7 +34,7 @@ namespace WireMock.Owin
|
||||
|
||||
public bool IsStarted { get; private set; }
|
||||
|
||||
public List<Uri> Urls { get; } = new List<Uri>();
|
||||
public List<string> Urls { get; } = new List<string>();
|
||||
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
@@ -44,12 +45,6 @@ namespace WireMock.Owin
|
||||
{
|
||||
StartServers();
|
||||
}, _cts.Token);
|
||||
|
||||
//if (_internalThread != null)
|
||||
// throw new InvalidOperationException("Cannot start a multiple threads.");
|
||||
|
||||
//_internalThread = new Thread(ThreadWorkInternal);
|
||||
//_internalThread.Start();
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
@@ -57,59 +52,40 @@ namespace WireMock.Owin
|
||||
{
|
||||
_cts.Cancel();
|
||||
|
||||
var tcs = new TaskCompletionSource<bool>();
|
||||
var timer = new System.Timers.Timer(999);
|
||||
timer.Elapsed += (sender, e) =>
|
||||
{
|
||||
if (_internalThread == null)
|
||||
{
|
||||
timer.Stop();
|
||||
tcs.SetResult(true);
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
private void ThreadWorkInternal()
|
||||
{
|
||||
try
|
||||
{
|
||||
StartServers();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_internalThread = null;
|
||||
}
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private void StartServers()
|
||||
{
|
||||
Console.WriteLine("WireMock.Net server using .net 4.5.x or higher");
|
||||
|
||||
Action<IAppBuilder> startup = app =>
|
||||
{
|
||||
app.Use<GlobalExceptionMiddleware>();
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(app);
|
||||
app.Use<WireMockMiddleware>(_options);
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(app);
|
||||
};
|
||||
|
||||
var servers = new List<IDisposable>();
|
||||
foreach (var url in Urls)
|
||||
{
|
||||
servers.Add(WebApp.Start(url.ToString(), startup));
|
||||
servers.Add(WebApp.Start(url, startup));
|
||||
}
|
||||
|
||||
IsStarted = true;
|
||||
|
||||
while (!_cts.IsCancellationRequested)
|
||||
Thread.Sleep(1000);
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
}
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
foreach (var server in servers)
|
||||
{
|
||||
server.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,143 +1,181 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers.Request;
|
||||
using System.Linq;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
internal class WireMockMiddleware : OwinMiddleware
|
||||
#else
|
||||
internal class WireMockMiddleware
|
||||
#endif
|
||||
{
|
||||
private static readonly Task CompletedTask = Task.FromResult(false);
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
|
||||
private readonly OwinRequestMapper _requestMapper = new OwinRequestMapper();
|
||||
private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
|
||||
|
||||
#if !NETSTANDARD
|
||||
public WireMockMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
#else
|
||||
public WireMockMiddleware(RequestDelegate next, WireMockMiddlewareOptions options)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NETSTANDARD
|
||||
public override async Task Invoke(IOwinContext ctx)
|
||||
#else
|
||||
public async Task Invoke(HttpContext ctx)
|
||||
#endif
|
||||
{
|
||||
var request = await _requestMapper.MapAsync(ctx.Request);
|
||||
|
||||
ResponseMessage response = null;
|
||||
Mapping targetMapping = null;
|
||||
RequestMatchResult requestMatchResult = null;
|
||||
try
|
||||
{
|
||||
var mappings = _options.Mappings
|
||||
.Select(m => new
|
||||
{
|
||||
Mapping = m,
|
||||
MatchResult = m.IsRequestHandled(request)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (_options.AllowPartialMapping)
|
||||
{
|
||||
var partialMappings = mappings
|
||||
.Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdminInterface)
|
||||
.OrderBy(m => m.MatchResult)
|
||||
.ThenBy(m => m.Mapping.Priority)
|
||||
.ToList();
|
||||
|
||||
var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0);
|
||||
|
||||
targetMapping = bestPartialMatch?.Mapping;
|
||||
requestMatchResult = bestPartialMatch?.MatchResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
var perfectMatch = mappings
|
||||
.OrderBy(m => m.Mapping.Priority)
|
||||
.FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
|
||||
|
||||
targetMapping = perfectMatch?.Mapping;
|
||||
requestMatchResult = perfectMatch?.MatchResult;
|
||||
}
|
||||
|
||||
if (targetMapping == null)
|
||||
{
|
||||
response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" };
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null)
|
||||
{
|
||||
string authorization;
|
||||
bool present = request.Headers.TryGetValue("Authorization", out authorization);
|
||||
if (!present || _options.AuthorizationMatcher.IsMatch(authorization) < 1.0)
|
||||
{
|
||||
response = new ResponseMessage { StatusCode = 401 };
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero)
|
||||
{
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value);
|
||||
}
|
||||
|
||||
response = await targetMapping.ResponseToAsync(request);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() };
|
||||
}
|
||||
finally
|
||||
{
|
||||
var log = new LogEntry
|
||||
{
|
||||
Guid = Guid.NewGuid(),
|
||||
RequestMessage = request,
|
||||
ResponseMessage = response,
|
||||
MappingGuid = targetMapping?.Guid,
|
||||
MappingTitle = targetMapping?.Title,
|
||||
RequestMatchResult = requestMatchResult
|
||||
};
|
||||
|
||||
LogRequest(log);
|
||||
|
||||
await _responseMapper.MapAsync(response, ctx.Response);
|
||||
}
|
||||
|
||||
await CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log request.
|
||||
/// </summary>
|
||||
/// <param name="entry">The request.</param>
|
||||
private void LogRequest(LogEntry entry)
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
_options.LogEntries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers.Request;
|
||||
using System.Linq;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Util;
|
||||
using Newtonsoft.Json;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Http;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
#if !NETSTANDARD
|
||||
internal class WireMockMiddleware : OwinMiddleware
|
||||
#else
|
||||
internal class WireMockMiddleware
|
||||
#endif
|
||||
{
|
||||
private static readonly Task CompletedTask = Task.FromResult(false);
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
|
||||
private readonly OwinRequestMapper _requestMapper = new OwinRequestMapper();
|
||||
private readonly OwinResponseMapper _responseMapper = new OwinResponseMapper();
|
||||
|
||||
#if !NETSTANDARD
|
||||
public WireMockMiddleware(OwinMiddleware next, WireMockMiddlewareOptions options) : base(next)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
#else
|
||||
public WireMockMiddleware(RequestDelegate next, WireMockMiddlewareOptions options)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !NETSTANDARD
|
||||
public override async Task Invoke(IOwinContext ctx)
|
||||
#else
|
||||
public async Task Invoke(HttpContext ctx)
|
||||
#endif
|
||||
{
|
||||
var request = await _requestMapper.MapAsync(ctx.Request);
|
||||
|
||||
bool logRequest = false;
|
||||
ResponseMessage response = null;
|
||||
Mapping targetMapping = null;
|
||||
RequestMatchResult requestMatchResult = null;
|
||||
try
|
||||
{
|
||||
foreach (var mapping in _options.Mappings.Where(m => m?.Scenario != null))
|
||||
{
|
||||
// Set start
|
||||
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
||||
{
|
||||
_options.Scenarios.Add(mapping.Scenario, null);
|
||||
}
|
||||
}
|
||||
|
||||
var mappings = _options.Mappings
|
||||
.Select(m => new
|
||||
{
|
||||
Mapping = m,
|
||||
MatchResult = m.GetRequestMatchResult(request, m.Scenario != null && _options.Scenarios.ContainsKey(m.Scenario) ? _options.Scenarios[m.Scenario] : null)
|
||||
})
|
||||
.ToList();
|
||||
|
||||
if (_options.AllowPartialMapping)
|
||||
{
|
||||
var partialMappings = mappings
|
||||
.Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdminInterface)
|
||||
.OrderBy(m => m.MatchResult)
|
||||
.ThenBy(m => m.Mapping.Priority)
|
||||
.ToList();
|
||||
|
||||
var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0);
|
||||
|
||||
targetMapping = bestPartialMatch?.Mapping;
|
||||
requestMatchResult = bestPartialMatch?.MatchResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
var perfectMatch = mappings
|
||||
.OrderBy(m => m.Mapping.Priority)
|
||||
.FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
|
||||
|
||||
targetMapping = perfectMatch?.Mapping;
|
||||
requestMatchResult = perfectMatch?.MatchResult;
|
||||
}
|
||||
|
||||
if (targetMapping == null)
|
||||
{
|
||||
logRequest = true;
|
||||
response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" };
|
||||
return;
|
||||
}
|
||||
|
||||
logRequest = !targetMapping.IsAdminInterface;
|
||||
|
||||
if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null)
|
||||
{
|
||||
bool present = request.Headers.TryGetValue("Authorization", out WireMockList<string> authorization);
|
||||
if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect)
|
||||
{
|
||||
response = new ResponseMessage { StatusCode = 401 };
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero)
|
||||
{
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value);
|
||||
}
|
||||
|
||||
response = await targetMapping.ResponseToAsync(request);
|
||||
|
||||
if (targetMapping.Scenario != null)
|
||||
{
|
||||
_options.Scenarios[targetMapping.Scenario] = targetMapping.NextState;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
response = new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) };
|
||||
}
|
||||
finally
|
||||
{
|
||||
var log = new LogEntry
|
||||
{
|
||||
Guid = Guid.NewGuid(),
|
||||
RequestMessage = request,
|
||||
ResponseMessage = response,
|
||||
MappingGuid = targetMapping?.Guid,
|
||||
MappingTitle = targetMapping?.Title,
|
||||
RequestMatchResult = requestMatchResult
|
||||
};
|
||||
|
||||
LogRequest(log, logRequest);
|
||||
|
||||
await _responseMapper.MapAsync(response, ctx.Response);
|
||||
}
|
||||
|
||||
await CompletedTask;
|
||||
}
|
||||
|
||||
private void LogRequest(LogEntry entry, bool addRequest)
|
||||
{
|
||||
if (addRequest)
|
||||
{
|
||||
_options.LogEntries.Add(entry);
|
||||
}
|
||||
|
||||
if (_options.MaxRequestLogCount != null)
|
||||
{
|
||||
var amount = _options.LogEntries.Count - _options.MaxRequestLogCount.Value;
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
_options.LogEntries.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (_options.RequestLogExpirationDuration != null)
|
||||
{
|
||||
var checkTime = DateTime.Now.AddHours(-_options.RequestLogExpirationDuration.Value);
|
||||
|
||||
for (var i = _options.LogEntries.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var le = _options.LogEntries[i];
|
||||
if (le.RequestMessage.DateTime <= checkTime)
|
||||
{
|
||||
_options.LogEntries.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Util;
|
||||
#if !NETSTANDARD
|
||||
using Owin;
|
||||
#else
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
#endif
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -13,14 +21,24 @@ namespace WireMock.Owin
|
||||
|
||||
public bool AllowPartialMapping { get; set; }
|
||||
|
||||
public IList<Mapping> Mappings { get; set; }
|
||||
public IList<Mapping> Mappings { get; set; } = new List<Mapping>();
|
||||
|
||||
public IList<LogEntry> LogEntries { get; set; }
|
||||
public ObservableCollection<LogEntry> LogEntries { get; } = new ConcurentObservableCollection<LogEntry>();
|
||||
|
||||
public WireMockMiddlewareOptions()
|
||||
{
|
||||
Mappings = new List<Mapping>();
|
||||
LogEntries = new List<LogEntry>();
|
||||
}
|
||||
public int? RequestLogExpirationDuration { get; set; }
|
||||
|
||||
public int? MaxRequestLogCount { get; set; }
|
||||
|
||||
public IDictionary<string, object> Scenarios { get; } = new ConcurrentDictionary<string, object>();
|
||||
|
||||
#if !NETSTANDARD
|
||||
public Action<IAppBuilder> PreWireMockMiddlewareInit { get; set; }
|
||||
|
||||
public Action<IAppBuilder> PostWireMockMiddlewareInit { get; set; }
|
||||
#else
|
||||
public Action<IApplicationBuilder> PreWireMockMiddlewareInit { get; set; }
|
||||
|
||||
public Action<IApplicationBuilder> PostWireMockMiddlewareInit { get; set; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
4
src/WireMock.Net/Properties/AssemblyInfo.cs
Normal file
4
src/WireMock.Net/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("WireMock.Net.StandAlone")]
|
||||
[assembly: InternalsVisibleTo("WireMock.Net.Tests")]
|
||||
33
src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs
Normal file
33
src/WireMock.Net/RequestBuilders/IClientIPRequestBuilder.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Matchers;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
/// <summary>
|
||||
/// The IClientIPRequestBuilder interface.
|
||||
/// </summary>
|
||||
public interface IClientIPRequestBuilder : IUrlAndPathRequestBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// The with ClientIP.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithClientIP([NotNull] params IMatcher[] matchers);
|
||||
|
||||
/// <summary>
|
||||
/// The with ClientIP.
|
||||
/// </summary>
|
||||
/// <param name="clientIPs">The clientIPs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithClientIP([NotNull] params string[] clientIPs);
|
||||
|
||||
/// <summary>
|
||||
/// The with ClientIP.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The path funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithClientIP([NotNull] params Func<string, bool>[] funcs);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace WireMock.RequestBuilders
|
||||
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// The with header.
|
||||
/// Add Header matching based on name, pattern and ignoreCase.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="pattern">The pattern.</param>
|
||||
@@ -20,6 +20,15 @@ namespace WireMock.RequestBuilders
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true);
|
||||
|
||||
/// <summary>
|
||||
/// Add Header matching based on name, patterns and ignoreCase.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
/// <param name="ignoreCase">ignore Case</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithHeader([NotNull] string name, string[] patterns, bool ignoreCase = true);
|
||||
|
||||
/// <summary>
|
||||
/// The with header.
|
||||
/// </summary>
|
||||
@@ -33,7 +42,7 @@ namespace WireMock.RequestBuilders
|
||||
/// </summary>
|
||||
/// <param name="funcs">The headers funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
IRequestBuilder WithHeader([NotNull] params Func<IDictionary<string, string>, bool>[] funcs);
|
||||
IRequestBuilder WithHeader([NotNull] params Func<IDictionary<string, string[]>, bool>[] funcs);
|
||||
|
||||
/// <summary>
|
||||
/// The with cookie.
|
||||
|
||||
@@ -7,6 +7,14 @@ namespace WireMock.RequestBuilders
|
||||
/// </summary>
|
||||
public interface IMethodRequestBuilder : IHeadersAndCookiesRequestBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// The using delete.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
IRequestBuilder UsingDelete();
|
||||
|
||||
/// <summary>
|
||||
/// The using get.
|
||||
/// </summary>
|
||||
@@ -15,6 +23,14 @@ namespace WireMock.RequestBuilders
|
||||
/// </returns>
|
||||
IRequestBuilder UsingGet();
|
||||
|
||||
/// <summary>
|
||||
/// The using head.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
IRequestBuilder UsingHead();
|
||||
|
||||
/// <summary>
|
||||
/// The using post.
|
||||
/// </summary>
|
||||
@@ -24,12 +40,12 @@ namespace WireMock.RequestBuilders
|
||||
IRequestBuilder UsingPost();
|
||||
|
||||
/// <summary>
|
||||
/// The using delete.
|
||||
/// The using patch.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
IRequestBuilder UsingDelete();
|
||||
IRequestBuilder UsingPatch();
|
||||
|
||||
/// <summary>
|
||||
/// The using put.
|
||||
@@ -39,14 +55,6 @@ namespace WireMock.RequestBuilders
|
||||
/// </returns>
|
||||
IRequestBuilder UsingPut();
|
||||
|
||||
/// <summary>
|
||||
/// The using head.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
IRequestBuilder UsingHead();
|
||||
|
||||
/// <summary>
|
||||
/// The using any verb.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// IRequestBuilder
|
||||
/// </summary>
|
||||
public interface IRequestBuilder : IUrlAndPathRequestBuilder
|
||||
public interface IRequestBuilder : IClientIPRequestBuilder
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,45 @@ namespace WireMock.RequestBuilders
|
||||
return _requestMatchers.Where(rm => rm is T).Cast<T>().FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with clientIP.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(matchers));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with clientIP.
|
||||
/// </summary>
|
||||
/// <param name="clientIPs">The ClientIPs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params string[] clientIPs)
|
||||
{
|
||||
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(clientIPs));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with clientIP.
|
||||
/// </summary>
|
||||
/// <param name="funcs">The clientIP funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(funcs));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The with path.
|
||||
/// </summary>
|
||||
@@ -61,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;
|
||||
@@ -74,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;
|
||||
@@ -87,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;
|
||||
@@ -100,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;
|
||||
@@ -113,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;
|
||||
@@ -126,76 +165,55 @@ 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using get.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
public IRequestBuilder UsingGet()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("get"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using post.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
public IRequestBuilder UsingPost()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("post"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using put.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
public IRequestBuilder UsingPut()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("put"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using delete.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingDelete"/>
|
||||
public IRequestBuilder UsingDelete()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("delete"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using head.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingGet"/>
|
||||
public IRequestBuilder UsingGet()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("get"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingHead"/>
|
||||
public IRequestBuilder UsingHead()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("head"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using any verb.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IRequestBuilder"/>.
|
||||
/// </returns>
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPost"/>
|
||||
public IRequestBuilder UsingPost()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("post"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPatch"/>
|
||||
public IRequestBuilder UsingPatch()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("patch"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPut"/>
|
||||
public IRequestBuilder UsingPut()
|
||||
{
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher("put"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
|
||||
public IRequestBuilder UsingAnyVerb()
|
||||
{
|
||||
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
|
||||
@@ -207,14 +225,10 @@ namespace WireMock.RequestBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The using verb.
|
||||
/// </summary>
|
||||
/// <param name="verbs">The verbs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
/// <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;
|
||||
@@ -314,19 +328,13 @@ 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With header.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="pattern">The pattern.</param>
|
||||
/// <param name="ignoreCase">if set to <c>true</c> [ignore case].</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string,bool)"/>
|
||||
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
@@ -336,6 +344,16 @@ namespace WireMock.RequestBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string,string[],bool)"/>
|
||||
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, patterns, ignoreCase));
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With header.
|
||||
/// </summary>
|
||||
@@ -345,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;
|
||||
@@ -356,9 +374,9 @@ namespace WireMock.RequestBuilders
|
||||
/// </summary>
|
||||
/// <param name="funcs">The funcs.</param>
|
||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||
public IRequestBuilder WithHeader(params Func<IDictionary<string, string>, bool>[] funcs)
|
||||
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;
|
||||
@@ -385,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;
|
||||
@@ -398,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,127 +1,177 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using System.Text;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
/// <summary>
|
||||
/// The request.
|
||||
/// </summary>
|
||||
public class RequestMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the url.
|
||||
/// </summary>
|
||||
public string Url { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DateTime.
|
||||
/// </summary>
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path.
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the method.
|
||||
/// </summary>
|
||||
public string Method { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the headers.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Cookies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the query.
|
||||
/// </summary>
|
||||
public IDictionary<string, WireMockList<string>> Query { get; } = new Dictionary<string, WireMockList<string>>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bodyAsBytes.
|
||||
/// </summary>
|
||||
public byte[] BodyAsBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body.
|
||||
/// </summary>
|
||||
public string Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body encoding.
|
||||
/// </summary>
|
||||
public Encoding BodyEncoding { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessage"/> class.
|
||||
/// </summary>
|
||||
/// <param name="url">The original url.</param>
|
||||
/// <param name="verb">The verb.</param>
|
||||
/// <param name="bodyAsBytes">The bodyAsBytes byte[].</param>
|
||||
/// <param name="body">The body string.</param>
|
||||
/// <param name="bodyEncoding">The body encoding</param>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <param name="cookies">The cookies.</param>
|
||||
public RequestMessage([NotNull] Uri url, [NotNull] string verb, [CanBeNull] byte[] bodyAsBytes = null, [CanBeNull] string body = null, [CanBeNull] Encoding bodyEncoding = null, [CanBeNull] IDictionary<string, string> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
|
||||
{
|
||||
Check.NotNull(url, nameof(url));
|
||||
Check.NotNull(verb, nameof(verb));
|
||||
|
||||
Url = url.ToString();
|
||||
Path = url.AbsolutePath;
|
||||
Method = verb.ToLower();
|
||||
BodyAsBytes = bodyAsBytes;
|
||||
Body = body;
|
||||
BodyEncoding = bodyEncoding;
|
||||
Headers = headers;
|
||||
Cookies = cookies;
|
||||
|
||||
string query = url.Query;
|
||||
if (!string.IsNullOrEmpty(query))
|
||||
{
|
||||
if (query.StartsWith("?"))
|
||||
{
|
||||
query = query.Substring(1);
|
||||
}
|
||||
|
||||
Query = query.Split('&').Aggregate(
|
||||
new Dictionary<string, WireMockList<string>>(),
|
||||
(dict, term) =>
|
||||
{
|
||||
var parts = term.Split('=');
|
||||
var key = parts[0];
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict.Add(key, new WireMockList<string>());
|
||||
}
|
||||
|
||||
if (parts.Length == 2)
|
||||
dict[key].Add(parts[1]);
|
||||
|
||||
return dict;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The get a query parameter.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>The query parameter.</returns>
|
||||
public List<string> GetParameter(string key)
|
||||
{
|
||||
return Query.ContainsKey(key) ? Query[key] : null;
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
/// <summary>
|
||||
/// The request.
|
||||
/// </summary>
|
||||
public class RequestMessage
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Client IP Address.
|
||||
/// </summary>
|
||||
public string ClientIP { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url.
|
||||
/// </summary>
|
||||
public string Url { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the DateTime.
|
||||
/// </summary>
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path.
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the method.
|
||||
/// </summary>
|
||||
public string Method { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the headers.
|
||||
/// </summary>
|
||||
public IDictionary<string, WireMockList<string>> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cookies.
|
||||
/// </summary>
|
||||
public IDictionary<string, string> Cookies { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the query.
|
||||
/// </summary>
|
||||
public IDictionary<string, WireMockList<string>> Query { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the raw query.
|
||||
/// </summary>
|
||||
public string RawQuery { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bodyAsBytes.
|
||||
/// </summary>
|
||||
public byte[] BodyAsBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body.
|
||||
/// </summary>
|
||||
public string Body { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Host
|
||||
/// </summary>
|
||||
public string Host { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the protocol
|
||||
/// </summary>
|
||||
public string Protocol { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the port
|
||||
/// </summary>
|
||||
public int Port { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the origin
|
||||
/// </summary>
|
||||
public string Origin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the body encoding.
|
||||
/// </summary>
|
||||
public Encoding BodyEncoding { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessage"/> class.
|
||||
/// </summary>
|
||||
/// <param name="url">The original url.</param>
|
||||
/// <param name="method">The HTTP method.</param>
|
||||
/// <param name="clientIP">The client IP Address.</param>
|
||||
/// <param name="bodyAsBytes">The bodyAsBytes byte[].</param>
|
||||
/// <param name="body">The body string.</param>
|
||||
/// <param name="bodyEncoding">The body encoding</param>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <param name="cookies">The cookies.</param>
|
||||
public RequestMessage([NotNull] Uri url, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] byte[] bodyAsBytes = null, [CanBeNull] string body = null, [CanBeNull] Encoding bodyEncoding = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
|
||||
{
|
||||
Check.NotNull(url, nameof(url));
|
||||
Check.NotNull(method, nameof(method));
|
||||
Check.NotNull(clientIP, nameof(clientIP));
|
||||
|
||||
Url = url.ToString();
|
||||
Protocol = url.Scheme;
|
||||
Host = url.Host;
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
BodyAsBytes = bodyAsBytes;
|
||||
Body = body;
|
||||
BodyEncoding = bodyEncoding;
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
Cookies = cookies;
|
||||
RawQuery = WebUtility.UrlDecode(url.Query);
|
||||
Query = ParseQuery(RawQuery);
|
||||
}
|
||||
|
||||
private static IDictionary<string, WireMockList<string>> ParseQuery(string queryString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (queryString.StartsWith("?"))
|
||||
{
|
||||
queryString = queryString.Substring(1);
|
||||
}
|
||||
|
||||
return queryString.Split('&').Aggregate(new Dictionary<string, WireMockList<string>>(),
|
||||
(dict, term) =>
|
||||
{
|
||||
var parts = term.Split('=');
|
||||
string key = parts[0];
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict.Add(key, new WireMockList<string>());
|
||||
}
|
||||
|
||||
if (parts.Length == 2)
|
||||
{
|
||||
dict[key].Add(parts[1]);
|
||||
}
|
||||
|
||||
return dict;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a query parameter.
|
||||
/// </summary>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns>The query parameter.</returns>
|
||||
public List<string> GetParameter(string key)
|
||||
{
|
||||
if (Query == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return Query.ContainsKey(key) ? Query[key] : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/WireMock.Net/ResponseBuilders/BodyDestinationFormat.cs
Normal file
23
src/WireMock.Net/ResponseBuilders/BodyDestinationFormat.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the BodyDestinationFormat
|
||||
/// </summary>
|
||||
public static class BodyDestinationFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// Same as source (no conversion)
|
||||
/// </summary>
|
||||
public const string SameAsSource = "SameAsSource";
|
||||
|
||||
/// <summary>
|
||||
/// Convert to string
|
||||
/// </summary>
|
||||
public const string String = "String";
|
||||
|
||||
/// <summary>
|
||||
/// Convert to bytes
|
||||
/// </summary>
|
||||
public const string Bytes = "Bytes";
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Text;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
@@ -9,15 +10,25 @@ namespace WireMock.ResponseBuilders
|
||||
public interface IBodyResponseBuilder : ITransformResponseBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// The with body.
|
||||
/// WithBody : Create a ... response based on a string.
|
||||
/// </summary>
|
||||
/// <param name="body">The body.</param>
|
||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] string body, [CanBeNull] Encoding encoding = null);
|
||||
IResponseBuilder WithBody([NotNull] string body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// The with body as Json.
|
||||
/// WithBody : Create a ... response based on a bytearray.
|
||||
/// </summary>
|
||||
/// <param name="body">The body.</param>
|
||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] byte[] body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
||||
/// </summary>
|
||||
/// <param name="body">The body.</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
@@ -25,11 +36,20 @@ namespace WireMock.ResponseBuilders
|
||||
IResponseBuilder WithBodyAsJson([NotNull] object body, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// The with body as base64.
|
||||
/// WithBody : Create a string response based on a Base64 string (which will be decoded to a normal string).
|
||||
/// </summary>
|
||||
/// <param name="bodyAsbase64">The body asbase64.</param>
|
||||
/// <param name="bodyAsbase64">The body.</param>
|
||||
/// <param name="encoding">The Encoding.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBodyAsBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
|
||||
[Obsolete]
|
||||
IResponseBuilder WithBodyFromBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBodyFromFile : Create a ... response based on a File.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="cache">Defines if this file is cached in memory or retrieved from disk everytime the response is created.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBodyFromFile([NotNull] string filename, bool cache = true);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -12,15 +13,29 @@ namespace WireMock.ResponseBuilders
|
||||
/// The with header.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
/// <param name="values">The values.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithHeader([NotNull] string name, string value);
|
||||
IResponseBuilder WithHeader([NotNull] string name, params string[] values);
|
||||
|
||||
/// <summary>
|
||||
/// The with headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithHeaders([NotNull] IDictionary<string,string> headers);
|
||||
IResponseBuilder WithHeaders([NotNull] IDictionary<string, string> headers);
|
||||
|
||||
/// <summary>
|
||||
/// The with headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithHeaders([NotNull] IDictionary<string, string[]> headers);
|
||||
|
||||
/// <summary>
|
||||
/// The with headers.
|
||||
/// </summary>
|
||||
/// <param name="headers">The headers.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithHeaders([NotNull] IDictionary<string, WireMockList<string>> headers);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -8,18 +9,18 @@ namespace WireMock.ResponseBuilders
|
||||
public interface IProxyResponseBuilder : IStatusCodeResponseBuilder
|
||||
{
|
||||
/// <summary>
|
||||
/// With Proxy URL.
|
||||
/// 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);
|
||||
IResponseBuilder WithProxy([NotNull] string proxyUrl, [CanBeNull] string clientX509Certificate2ThumbprintOrSubjectName = null);
|
||||
|
||||
/// <summary>
|
||||
/// With Proxy URL using X509Certificate2.
|
||||
/// WithProxy using IProxyAndRecordSettings.
|
||||
/// </summary>
|
||||
/// <param name="proxyUrl">The proxy url.</param>
|
||||
/// <param name="clientX509Certificate2Filename">The X509Certificate2 file to use for client authentication.</param>
|
||||
/// <param name="settings">The IProxyAndRecordSettings.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithProxy([NotNull] string proxyUrl, [CanBeNull] string clientX509Certificate2Filename);
|
||||
IResponseBuilder WithProxy([NotNull] IProxyAndRecordSettings settings);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user