mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-23 01:04:55 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f8bdff936 | ||
|
|
942fc3a385 | ||
|
|
2f5298b0a2 | ||
|
|
55cf0f0416 | ||
|
|
76f0ac6465 | ||
|
|
7abf56eafa | ||
|
|
9665729e58 | ||
|
|
06be3aff95 | ||
|
|
0d102f3af4 | ||
|
|
b55435ddac | ||
|
|
c4ee91c614 | ||
|
|
4d0373d4ca | ||
|
|
6c27820659 | ||
|
|
9a532108b8 | ||
|
|
9491280fd2 | ||
|
|
da62a43875 | ||
|
|
197f96e303 |
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -16,7 +16,7 @@ A clear and concise description of what you want to happen.
|
|||||||
**Describe alternatives you've considered**
|
**Describe alternatives you've considered**
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
**Is your feature request supported by [Handlebarsjs](https://handlebarsjs.com/)? Please provide details.**
|
**Is your feature request supported by [WireMock (java version)](https://www.wiremock.org)? Please provide details.**
|
||||||
Provide relevant information if requested feature is supported in [Handlebarsjs](https://handlebarsjs.com/) but is missing in our implementation.
|
Provide relevant information if requested feature is supported in [Handlebarsjs](https://handlebarsjs.com/) but is missing in our implementation.
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
|
|||||||
24
CHANGELOG.md
24
CHANGELOG.md
@@ -1,3 +1,27 @@
|
|||||||
|
# 1.3.1 (30 September 2020)
|
||||||
|
- [#509](https://github.com/WireMock-Net/WireMock.Net/pull/509) - Adding netcoreapp3.1 as a target framework [feature] contributed by [APIWT](https://github.com/APIWT)
|
||||||
|
|
||||||
|
# 1.3.0 (29 September 2020)
|
||||||
|
- [#508](https://github.com/WireMock-Net/WireMock.Net/pull/508) - Fix vulnerability in NuGet dependencies contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#327](https://github.com/WireMock-Net/WireMock.Net/issues/327) - Index must be within the bounds of the List - Bug [bug]
|
||||||
|
- [#507](https://github.com/WireMock-Net/WireMock.Net/issues/507) - Fix vulnerability found in Microsoft.AspNetCore dependency [feature]
|
||||||
|
|
||||||
|
# 1.2.18 (13 August 2020)
|
||||||
|
- [#496](https://github.com/WireMock-Net/WireMock.Net/pull/496) - Add setting to handle requests synchronously [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#500](https://github.com/WireMock-Net/WireMock.Net/pull/500) - Add ThrowExceptionWhenMatcherFails option to all Matchers [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#478](https://github.com/WireMock-Net/WireMock.Net/issues/478) - Sometimes returns status code 0 in unit tests with xunit test fixture (flaky test) [bug]
|
||||||
|
|
||||||
|
# 1.2.17 (01 August 2020)
|
||||||
|
- [#495](https://github.com/WireMock-Net/WireMock.Net/pull/495) - Scenario : stay on current state for a number of times contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#494](https://github.com/WireMock-Net/WireMock.Net/issues/494) - Stay in Current State for specified number of requests [feature]
|
||||||
|
|
||||||
|
# 1.2.16 (27 July 2020)
|
||||||
|
- [#492](https://github.com/WireMock-Net/WireMock.Net/pull/492) - Mark FluentMockServer, FluentMockServerSettings, BlacklistedHeaders and BlacklistedCookies as obsolete [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
- [#489](https://github.com/WireMock-Net/WireMock.Net/issues/489) - Change "blacklist" and "whitelist" terms [feature]
|
||||||
|
|
||||||
|
# 1.2.15 (19 July 2020)
|
||||||
|
- [#485](https://github.com/WireMock-Net/WireMock.Net/pull/485) - Add fluent assertions for headers [test] contributed by [akamud](https://github.com/akamud)
|
||||||
|
|
||||||
# 1.2.14 (09 July 2020)
|
# 1.2.14 (09 July 2020)
|
||||||
- [#479](https://github.com/WireMock-Net/WireMock.Net/pull/479) - An OpenApi (swagger) parser to generate MappingModel or mapping.json file [feature] contributed by [StefH](https://github.com/StefH)
|
- [#479](https://github.com/WireMock-Net/WireMock.Net/pull/479) - An OpenApi (swagger) parser to generate MappingModel or mapping.json file [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#482](https://github.com/WireMock-Net/WireMock.Net/pull/482) - Add PartialMatch to logging / logentries [feature] contributed by [StefH](https://github.com/StefH)
|
- [#482](https://github.com/WireMock-Net/WireMock.Net/pull/482) - Add PartialMatch to logging / logentries [feature] contributed by [StefH](https://github.com/StefH)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.2.14</VersionPrefix>
|
<VersionPrefix>1.3.1</VersionPrefix>
|
||||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||||
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
<PackageIconUrl>https://raw.githubusercontent.com/WireMock-Net/WireMock.Net/master/WireMock.Net-Logo.png</PackageIconUrl>
|
||||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
https://github.com/StefH/GitHubReleaseNotes
|
https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.2.14
|
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.3.1
|
||||||
@@ -29,10 +29,10 @@ A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) w
|
|||||||
|
|
||||||
| | Official | Preview |
|
| | Official | Preview |
|
||||||
| - | - | - |
|
| - | - | - |
|
||||||
| **WireMock.Net** | [](https://www.nuget.org/packages/WireMock.Net) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net)
|
| **WireMock.Net** | [](https://www.nuget.org/packages/WireMock.Net) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net)
|
||||||
| **WireMock.Net.StandAlone** | [](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone)
|
| **WireMock.Net.StandAlone** | [](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone)
|
||||||
| **WireMock.Net.FluentAssertions** | [](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions)
|
| **WireMock.Net.FluentAssertions** | [](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions)
|
||||||
| **WireMock.Net.RestClient** | [](https://www.nuget.org/packages/WireMock.Net.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient)
|
| **WireMock.Net.RestClient** | [](https://www.nuget.org/packages/WireMock.Net.RestClient) | [](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient)
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
For the supported frameworks and build information, see [this](https://github.com/WireMock-Net/WireMock.Net/wiki/Development-Information) page.
|
For the supported frameworks and build information, see [this](https://github.com/WireMock-Net/WireMock.Net/wiki/Development-Information) page.
|
||||||
|
|||||||
@@ -63,13 +63,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.NETCor
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.RequestLogTest", "examples\WireMock.Net.Console.RequestLogTest\WireMock.Net.Console.RequestLogTest.csproj", "{A9D039B9-7509-4CF1-9EFD-87EB82998575}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.RequestLogTest", "examples\WireMock.Net.Console.RequestLogTest\WireMock.Net.Console.RequestLogTest.csproj", "{A9D039B9-7509-4CF1-9EFD-87EB82998575}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Client.Net472", "examples\WireMock.Net.Client.Net472\WireMock.Net.Client.Net472.csproj", "{02082E34-DEF2-47D0-AF0B-3326FAA908CE}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.OpenApiParser", "src\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj", "{D3804228-91F4-4502-9595-39584E5AADAD}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.OpenApiParser", "src\WireMock.Net.OpenApiParser\WireMock.Net.OpenApiParser.csproj", "{D3804228-91F4-4502-9595-39584E5AADAD}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.OpenApiParser.ConsoleApp", "examples\WireMock.Net.OpenApiParser.ConsoleApp\WireMock.Net.OpenApiParser.ConsoleApp.csproj", "{5C09FB93-1535-4F92-AF26-21E8A061EE4A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.OpenApiParser.ConsoleApp", "examples\WireMock.Net.OpenApiParser.ConsoleApp\WireMock.Net.OpenApiParser.ConsoleApp.csproj", "{5C09FB93-1535-4F92-AF26-21E8A061EE4A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.FluentAssertions", "src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj", "{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.FluentAssertions", "src\WireMock.Net.FluentAssertions\WireMock.Net.FluentAssertions.csproj", "{B6269AAC-170A-4346-8B9A-579DED3D9A95}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -157,10 +155,6 @@ Global
|
|||||||
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Release|Any CPU.Build.0 = Release|Any CPU
|
{A9D039B9-7509-4CF1-9EFD-87EB82998575}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{02082E34-DEF2-47D0-AF0B-3326FAA908CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{02082E34-DEF2-47D0-AF0B-3326FAA908CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{02082E34-DEF2-47D0-AF0B-3326FAA908CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{02082E34-DEF2-47D0-AF0B-3326FAA908CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{D3804228-91F4-4502-9595-39584E5AADAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{D3804228-91F4-4502-9595-39584E5AADAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{D3804228-91F4-4502-9595-39584E5AADAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D3804228-91F4-4502-9595-39584E5AADAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D3804228-91F4-4502-9595-39584E5AADAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D3804228-91F4-4502-9595-39584E5AADAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -169,10 +163,10 @@ Global
|
|||||||
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{5C09FB93-1535-4F92-AF26-21E8A061EE4A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{B6269AAC-170A-4346-8B9A-579DED3D9A95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B6269AAC-170A-4346-8B9A-579DED3D9A95}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B6269AAC-170A-4346-8B9A-579DED3D9A95}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B6269AAC-170A-4346-8B9A-579DED3D9A95}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -198,10 +192,9 @@ Global
|
|||||||
{668F689E-57B4-422E-8846-C0FF643CA268} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{668F689E-57B4-422E-8846-C0FF643CA268} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{83645809-9E01-4E81-8733-BA9497554ABF} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{83645809-9E01-4E81-8733-BA9497554ABF} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{A9D039B9-7509-4CF1-9EFD-87EB82998575} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{A9D039B9-7509-4CF1-9EFD-87EB82998575} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{02082E34-DEF2-47D0-AF0B-3326FAA908CE} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
|
||||||
{D3804228-91F4-4502-9595-39584E5AADAD} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
{D3804228-91F4-4502-9595-39584E5AADAD} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
{5C09FB93-1535-4F92-AF26-21E8A061EE4A} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
{5C09FB93-1535-4F92-AF26-21E8A061EE4A} = {985E0ADB-D4B4-473A-AA40-567E279B7946}
|
||||||
{2C837E73-5EDD-43AD-B65A-194E4A3AD9FE} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
{B6269AAC-170A-4346-8B9A-579DED3D9A95} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithPath("/proxy-execute-keep-alive")
|
.WithPath("/proxy-execute-keep-alive")
|
||||||
)
|
)
|
||||||
.RespondWith(Response.Create()
|
.RespondWith(Response.Create()
|
||||||
.WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", BlackListedHeaders = new[] { "Keep-Alive" } })
|
.WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999", ExcludedHeaders = new[] { "Keep-Alive" } })
|
||||||
.WithHeader("Keep-Alive-Test", "stef")
|
.WithHeader("Keep-Alive-Test", "stef")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace WireMock.Net.Console.Proxy.NETCoreApp2
|
|||||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||||
SaveMapping = true,
|
SaveMapping = true,
|
||||||
SaveMappingToFile = false,
|
SaveMappingToFile = false,
|
||||||
BlackListedHeaders = new[] { "dnt", "Content-Length" }
|
ExcludedHeaders = new[] { "dnt", "Content-Length" }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace WireMock.Net.Console.Proxy.Net452
|
|||||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||||
SaveMapping = true,
|
SaveMapping = true,
|
||||||
SaveMappingToFile = false,
|
SaveMappingToFile = false,
|
||||||
BlackListedHeaders = new[] { "dnt", "Content-Length" }
|
ExcludedHeaders = new[] { "dnt", "Content-Length" }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace WireMock.Net.Console.Proxy.NETCoreApp
|
|||||||
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
//ClientX509Certificate2ThumbprintOrSubjectName = "www.yourclientcertname.com OR yourcertificatethumbprint (only if the service you're proxying to requires it)",
|
||||||
SaveMapping = true,
|
SaveMapping = true,
|
||||||
SaveMappingToFile = false,
|
SaveMappingToFile = false,
|
||||||
BlackListedHeaders = new [] { "dnt", "Content-Length" }
|
ExcludedHeaders = new [] { "dnt", "Content-Length" }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace WireMock.Net.Console.RequestLogTest
|
|||||||
{
|
{
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
var server = StandAloneApp.Start(new FluentMockServerSettings
|
var server = StandAloneApp.Start(new WireMockServerSettings
|
||||||
{
|
{
|
||||||
Port = 19019,
|
Port = 19019,
|
||||||
StartAdminInterface = true,
|
StartAdminInterface = true,
|
||||||
|
|||||||
@@ -80,8 +80,8 @@
|
|||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="XPath2, Version=1.0.9.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
<Reference Include="XPath2, Version=1.1.0.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\XPath2.1.0.10\lib\net40\XPath2.dll</HintPath>
|
<HintPath>..\..\packages\XPath2.1.1.0\lib\net40\XPath2.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -13,5 +13,5 @@
|
|||||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
||||||
<package id="System.Net.Http" version="4.3.3" targetFramework="net452" />
|
<package id="System.Net.Http" version="4.3.3" targetFramework="net452" />
|
||||||
<package id="XPath2" version="1.0.10" targetFramework="net452" />
|
<package id="XPath2" version="1.1.0" targetFramework="net452" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -280,8 +280,8 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="XPath2, Version=1.0.7.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
<Reference Include="XPath2, Version=1.1.0.0, Culture=neutral, PublicKeyToken=463c6d7fb740c7e5, processorArchitecture=MSIL">
|
||||||
<HintPath>..\..\packages\XPath2.1.0.6.1\lib\net40\XPath2.dll</HintPath>
|
<HintPath>..\..\packages\XPath2.1.1.0\lib\net40\XPath2.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -78,5 +78,5 @@
|
|||||||
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net461" />
|
<package id="System.Security.Principal.Windows" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net461" />
|
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net461" />
|
||||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net461" />
|
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net461" />
|
||||||
<package id="XPath2" version="1.0.6.1" targetFramework="net461" />
|
<package id="XPath2" version="1.1.0" targetFramework="net461" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -24,5 +24,10 @@
|
|||||||
/// Gets or sets a value indicating whether this <see cref="ScenarioStateModel"/> is finished.
|
/// Gets or sets a value indicating whether this <see cref="ScenarioStateModel"/> is finished.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Finished { get; set; }
|
public bool Finished { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the state counter.
|
||||||
|
/// </summary>
|
||||||
|
public int Counter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,18 @@
|
|||||||
public int? MaxRequestLogCount { get; set; }
|
public int? MaxRequestLogCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets wether to allow a body for all HTTP methods.
|
/// Allow a Body for all HTTP Methods. (default set to false).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? AllowBodyForAllHttpMethods { get; set; }
|
public bool? AllowBodyForAllHttpMethods { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle all requests synchronously. (default set to false).
|
||||||
|
/// </summary>
|
||||||
|
public bool? HandleRequestsSynchronously { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Throw an exception when the Matcher fails because of invalid input. (default set to false).
|
||||||
|
/// </summary>
|
||||||
|
public bool? ThrowExceptionWhenMatcherFails { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,18 @@ namespace WireMock
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
object StatusCode { get; }
|
object StatusCode { get; }
|
||||||
|
|
||||||
//void AddHeader(string name, params string[] values);
|
/// <summary>
|
||||||
//void AddHeader(string name, string value);
|
/// Adds the header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="value">The value.</param>
|
||||||
|
void AddHeader(string name, string value);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="values">The values.</param>
|
||||||
|
void AddHeader(string name, params string[] values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,78 +3,54 @@ using WireMock.Matchers.Request;
|
|||||||
|
|
||||||
namespace WireMock.Logging
|
namespace WireMock.Logging
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ILogEntry
|
||||||
|
/// </summary>
|
||||||
public interface ILogEntry
|
public interface ILogEntry
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the unique identifier.
|
/// Gets the unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The unique identifier.
|
|
||||||
/// </value>
|
|
||||||
Guid Guid { get; }
|
Guid Guid { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mapping unique identifier.
|
/// Gets the mapping unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The mapping unique identifier.
|
|
||||||
/// </value>
|
|
||||||
Guid? MappingGuid { get; }
|
Guid? MappingGuid { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the mapping unique title.
|
/// Gets the mapping unique title.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The mapping unique title.
|
|
||||||
/// </value>
|
|
||||||
string MappingTitle { get; }
|
string MappingTitle { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the partial mapping unique identifier.
|
/// Gets the partial mapping unique identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The mapping unique identifier.
|
|
||||||
/// </value>
|
|
||||||
Guid? PartialMappingGuid { get; }
|
Guid? PartialMappingGuid { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the partial mapping unique title.
|
/// Gets the partial mapping unique title.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The mapping unique title.
|
|
||||||
/// </value>
|
|
||||||
string PartialMappingTitle { get; }
|
string PartialMappingTitle { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the partial match result.
|
/// Gets the partial match result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The request match result.
|
|
||||||
/// </value>
|
|
||||||
IRequestMatchResult PartialMatchResult { get; }
|
IRequestMatchResult PartialMatchResult { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the request match result.
|
/// Gets the request match result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The request match result.
|
|
||||||
/// </value>
|
|
||||||
IRequestMatchResult RequestMatchResult { get; }
|
IRequestMatchResult RequestMatchResult { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the request message.
|
/// Gets the request message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The request message.
|
|
||||||
/// </value>
|
|
||||||
IRequestMessage RequestMessage { get; }
|
IRequestMessage RequestMessage { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the response message.
|
/// Gets the response message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
|
||||||
/// The response message.
|
|
||||||
/// </value>
|
|
||||||
IResponseMessage ResponseMessage { get; }
|
IResponseMessage ResponseMessage { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,19 @@
|
|||||||
|
|
||||||
namespace WireMock.Matchers.Request
|
namespace WireMock.Matchers.Request
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// MatchDetail
|
||||||
|
/// </summary>
|
||||||
public class MatchDetail
|
public class MatchDetail
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the type of the matcher.
|
||||||
|
/// </summary>
|
||||||
public Type MatcherType { get; set; }
|
public Type MatcherType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the score between 0.0 and 1.0
|
||||||
|
/// </summary>
|
||||||
public double Score { get; set; }
|
public double Score { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,9 @@ namespace WireMock.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IEnumerable<MappingModel> MappingModels { get; }
|
IEnumerable<MappingModel> MappingModels { get; }
|
||||||
|
|
||||||
/// <summary>
|
// <summary>
|
||||||
/// Gets the mappings.
|
// Gets the mappings.
|
||||||
/// </summary>
|
// </summary>
|
||||||
//[PublicAPI]
|
//[PublicAPI]
|
||||||
//IEnumerable<IMapping> Mappings { get; }
|
//IEnumerable<IMapping> Mappings { get; }
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<Description>Commonly used interfaces, models, enumerations and types.</Description>
|
<Description>Commonly used interfaces, models, enumerations and types.</Description>
|
||||||
<AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.Abstractions</AssemblyTitle>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>netstandard1.0;netstandard2.0;netstandard2.1;net45</TargetFrameworks>
|
<TargetFrameworks>net45;netstandard1.0;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyName>WireMock.Net.Abstractions</AssemblyName>
|
<AssemblyName>WireMock.Net.Abstractions</AssemblyName>
|
||||||
<PackageId>WireMock.Net.Abstractions</PackageId>
|
<PackageId>WireMock.Net.Abstractions</PackageId>
|
||||||
|
|||||||
@@ -8,19 +8,20 @@ namespace WireMock.FluentAssertions
|
|||||||
{
|
{
|
||||||
public class WireMockAssertions
|
public class WireMockAssertions
|
||||||
{
|
{
|
||||||
private readonly IWireMockServer _instance;
|
private readonly IWireMockServer _subject;
|
||||||
|
|
||||||
public WireMockAssertions(IWireMockServer instance, int? callsCount)
|
public WireMockAssertions(IWireMockServer subject, int? callsCount)
|
||||||
{
|
{
|
||||||
_instance = instance;
|
_subject = subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
[CustomAssertion]
|
[CustomAssertion]
|
||||||
public AndConstraint<WireMockAssertions> AtAbsoluteUrl(string absoluteUrl, string because = "", params object[] becauseArgs)
|
public AndConstraint<WireMockAssertions> AtAbsoluteUrl(string absoluteUrl, string because = "",
|
||||||
|
params object[] becauseArgs)
|
||||||
{
|
{
|
||||||
Execute.Assertion
|
Execute.Assertion
|
||||||
.BecauseOf(because, becauseArgs)
|
.BecauseOf(because, becauseArgs)
|
||||||
.Given(() => _instance.LogEntries.Select(x => x.RequestMessage).ToList())
|
.Given(() => _subject.LogEntries.Select(x => x.RequestMessage).ToList())
|
||||||
.ForCondition(requests => requests.Any())
|
.ForCondition(requests => requests.Any())
|
||||||
.FailWith(
|
.FailWith(
|
||||||
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
"Expected {context:wiremockserver} to have been called at address matching the absolute url {0}{reason}, but no calls were made.",
|
||||||
@@ -33,5 +34,43 @@ namespace WireMock.FluentAssertions
|
|||||||
|
|
||||||
return new AndConstraint<WireMockAssertions>(this);
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string value,
|
||||||
|
string because = "", params object[] becauseArgs)
|
||||||
|
=> WithHeader(expectedKey, new[] {value}, because, becauseArgs);
|
||||||
|
|
||||||
|
[CustomAssertion]
|
||||||
|
public AndConstraint<WireMockAssertions> WithHeader(string expectedKey, string[] expectedValues,
|
||||||
|
string because = "", params object[] becauseArgs)
|
||||||
|
{
|
||||||
|
var headersDictionary = _subject.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||||
|
.ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
|
||||||
|
using (new AssertionScope("headers from requests sent"))
|
||||||
|
{
|
||||||
|
headersDictionary.Should().ContainKey(expectedKey, because, becauseArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
using (new AssertionScope($"header \"{expectedKey}\" from requests sent with value(s)"))
|
||||||
|
{
|
||||||
|
if (expectedValues.Length == 1)
|
||||||
|
{
|
||||||
|
headersDictionary[expectedKey].Should().Contain(expectedValues.First());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var trimmedHeaderValues = string.Join(",", headersDictionary[expectedKey].Select(x => x)).Split(',')
|
||||||
|
.Select(x => x.Trim())
|
||||||
|
.ToList();
|
||||||
|
foreach (var expectedValue in expectedValues)
|
||||||
|
{
|
||||||
|
trimmedHeaderValues.Should().Contain(expectedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new AndConstraint<WireMockAssertions>(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<!--<Version>1.2.13-preview-01</Version>-->
|
|
||||||
<Description>FluentAssertions extensions for WireMock.Net</Description>
|
<Description>FluentAssertions extensions for WireMock.Net</Description>
|
||||||
<AssemblyTitle>WireMock.Net.FluentAssertions</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.FluentAssertions</AssemblyTitle>
|
||||||
<Authors>Mahmoud Ali;Stef Heyenrath</Authors>
|
<Authors>Mahmoud Ali;Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>netstandard1.3;netstandard2.0;netstandard2.1;net451</TargetFrameworks>
|
<TargetFrameworks>net451;netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyName>WireMock.Net.FluentAssertions</AssemblyName>
|
<AssemblyName>WireMock.Net.FluentAssertions</AssemblyName>
|
||||||
<PackageId>WireMock.Net.FluentAssertions</PackageId>
|
<PackageId>WireMock.Net.FluentAssertions</PackageId>
|
||||||
|
|||||||
@@ -1,37 +1,36 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
<Description>An OpenApi (swagger) parser to generate MappingModel or mapping.json file.</Description>
|
||||||
<!--<VersionPrefix>1.2.4-preview-01</VersionPrefix>-->
|
<TargetFrameworks>net46;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
||||||
<PackageTags>wiremock;openapi;OAS;converter;parser;openapiparser</PackageTags>
|
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
||||||
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5AADAD}</ProjectGuid>
|
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
||||||
<CodeAnalysisRuleSet>../WireMock.Net/WireMock.Net.ruleset</CodeAnalysisRuleSet>
|
<SignAssembly>true</SignAssembly>
|
||||||
<SignAssembly>true</SignAssembly>
|
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
||||||
<AssemblyOriginatorKeyFile>../WireMock.Net/WireMock.Net.snk</AssemblyOriginatorKeyFile>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
</PropertyGroup>
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.0" />
|
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
||||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
||||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Options\" />
|
<Folder Include="Options\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<Description>A RestClient using RestEase to access the admin interface.</Description>
|
<Description>A RestClient using RestEase to access the admin interface.</Description>
|
||||||
<AssemblyTitle>WireMock.Net.RestClient</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.RestClient</AssemblyTitle>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>netstandard1.1;netstandard2.0;netstandard2.1;net45</TargetFrameworks>
|
<TargetFrameworks>net45;netstandard1.1;netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyName>WireMock.Net.RestClient</AssemblyName>
|
<AssemblyName>WireMock.Net.RestClient</AssemblyName>
|
||||||
<PackageId>WireMock.Net.RestClient</PackageId>
|
<PackageId>WireMock.Net.RestClient</PackageId>
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ namespace WireMock.Net.StandAlone
|
|||||||
public static class StandAloneApp
|
public static class StandAloneApp
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start WireMock.Net standalone Server based on the FluentMockServerSettings.
|
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="settings">The FluentMockServerSettings</param>
|
/// <param name="settings">The IWireMockServerSettings</param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
|
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
|
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
<AssemblyName>WireMock.Net.StandAlone</AssemblyName>
|
||||||
<PackageId>WireMock.Net.StandAlone</PackageId>
|
<PackageId>WireMock.Net.StandAlone</PackageId>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace WireMock.Http
|
|||||||
{
|
{
|
||||||
public static HttpClient CreateHttpClient(IProxyAndRecordSettings settings)
|
public static HttpClient CreateHttpClient(IProxyAndRecordSettings settings)
|
||||||
{
|
{
|
||||||
#if NETSTANDARD
|
#if NETSTANDARD || NETCOREAPP3_1
|
||||||
var handler = new HttpClientHandler
|
var handler = new HttpClientHandler
|
||||||
{
|
{
|
||||||
CheckCertificateRevocationList = false,
|
CheckCertificateRevocationList = false,
|
||||||
|
|||||||
@@ -51,6 +51,12 @@ namespace WireMock
|
|||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
string NextState { get; }
|
string NextState { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The number of times this match should be matched before the state will be changed to the next state.
|
||||||
|
/// </summary>
|
||||||
|
[CanBeNull]
|
||||||
|
int? StateTimes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Request matcher.
|
/// The Request matcher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ namespace WireMock
|
|||||||
/// <inheritdoc cref="IMapping.NextState" />
|
/// <inheritdoc cref="IMapping.NextState" />
|
||||||
public string NextState { get; }
|
public string NextState { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMapping.StateTimes" />
|
||||||
|
public int? StateTimes { get; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IMapping.RequestMatcher" />
|
/// <inheritdoc cref="IMapping.RequestMatcher" />
|
||||||
public IRequestMatcher RequestMatcher { get; }
|
public IRequestMatcher RequestMatcher { get; }
|
||||||
|
|
||||||
@@ -64,9 +67,10 @@ namespace WireMock
|
|||||||
/// <param name="scenario">The scenario. [Optional]</param>
|
/// <param name="scenario">The scenario. [Optional]</param>
|
||||||
/// <param name="executionConditionState">State in which the current mapping can occur. [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>
|
/// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param>
|
||||||
|
/// <param name="stateTimes">Only when the current state is executed this number, the next state which will occur. [Optional]</param>
|
||||||
public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path,
|
public Mapping(Guid guid, [CanBeNull] string title, [CanBeNull] string path,
|
||||||
[NotNull] IWireMockServerSettings settings, [NotNull] IRequestMatcher requestMatcher, [NotNull] IResponseProvider provider,
|
[NotNull] IWireMockServerSettings settings, [NotNull] IRequestMatcher requestMatcher, [NotNull] IResponseProvider provider,
|
||||||
int priority, [CanBeNull] string scenario, [CanBeNull] string executionConditionState, [CanBeNull] string nextState)
|
int priority, [CanBeNull] string scenario, [CanBeNull] string executionConditionState, [CanBeNull] string nextState, [CanBeNull] int? stateTimes)
|
||||||
{
|
{
|
||||||
Guid = guid;
|
Guid = guid;
|
||||||
Title = title;
|
Title = title;
|
||||||
@@ -78,6 +82,7 @@ namespace WireMock
|
|||||||
Scenario = scenario;
|
Scenario = scenario;
|
||||||
ExecutionConditionState = executionConditionState;
|
ExecutionConditionState = executionConditionState;
|
||||||
NextState = nextState;
|
NextState = nextState;
|
||||||
|
StateTimes = stateTimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ namespace WireMock.Matchers
|
|||||||
|
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
private readonly string[] _patterns;
|
private readonly string[] _patterns;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,6 +52,7 @@ namespace WireMock.Matchers
|
|||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = false;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,7 +151,7 @@ namespace WireMock.Matchers
|
|||||||
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
throw new WireMockException("CSharpCodeMatcher: Problem calling method 'IsMatch' in WireMock.CodeHelper", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif (NETSTANDARD2_0 || NETSTANDARD2_1)
|
#elif (NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP3_1)
|
||||||
dynamic script;
|
dynamic script;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -156,7 +160,7 @@ namespace WireMock.Matchers
|
|||||||
#if NETSTANDARD2_0
|
#if NETSTANDARD2_0
|
||||||
script = csscript.GenericExtensions.CreateObject(assembly, "*");
|
script = csscript.GenericExtensions.CreateObject(assembly, "*");
|
||||||
#else
|
#else
|
||||||
script = CSScriptLib.ReflectionExtensions.CreateObject(assembly,"*");
|
script = CSScriptLib.ReflectionExtensions.CreateObject(assembly, "*");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -45,7 +45,9 @@ namespace WireMock.Matchers
|
|||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase (default false)</param>
|
/// <param name="ignoreCase">IgnoreCase (default false)</param>
|
||||||
public ContentTypeMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns, ignoreCase)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public ContentTypeMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false, bool throwException = false) :
|
||||||
|
base(matchBehaviour, patterns, ignoreCase, throwException)
|
||||||
{
|
{
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,14 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public ExactMatcher([NotNull] params string[] values) : this(MatchBehaviour.AcceptOnMatch, values)
|
public ExactMatcher([NotNull] params string[] values) : this(MatchBehaviour.AcceptOnMatch, false, values)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,13 +30,15 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public ExactMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] values)
|
public ExactMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] values)
|
||||||
{
|
{
|
||||||
Check.HasNoNulls(values, nameof(values));
|
Check.HasNoNulls(values, nameof(values));
|
||||||
|
|
||||||
_values = values;
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
|
_values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -56,13 +59,15 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class.
|
/// Initializes a new instance of the <see cref="ExactObjectMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
/// <param name="value">The value.</param>
|
/// <param name="value">The value.</param>
|
||||||
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value)
|
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value, bool throwException = false)
|
||||||
{
|
{
|
||||||
Check.NotNull(value, nameof(value));
|
Check.NotNull(value, nameof(value));
|
||||||
|
|
||||||
ValueAsBytes = value;
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
|
ValueAsBytes = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
||||||
|
|||||||
@@ -14,5 +14,10 @@
|
|||||||
/// Gets the match behaviour.
|
/// Gets the match behaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
MatchBehaviour MatchBehaviour { get; }
|
MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Should this matcher throw an exception?
|
||||||
|
/// </summary>
|
||||||
|
bool ThrowException { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,11 +18,14 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public JsonPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
public JsonPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, false, patterns)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +33,14 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public JsonPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
public JsonPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +57,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
// just ignore JsonException
|
if (ThrowException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +83,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
// just ignore JsonException
|
if (ThrowException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,23 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JmesPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JmesPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public JmesPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
public JmesPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, false, patterns)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="JmesPathMatcher"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
public JmesPathMatcher(bool throwException = false, [NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, throwException, patterns)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,12 +40,14 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="JmesPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JmesPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public JmesPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
public JmesPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +63,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
// just ignore JsonException
|
if (ThrowException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
using JetBrains.Annotations;
|
using System.Collections;
|
||||||
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System.Collections;
|
|
||||||
using System.Linq;
|
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
@@ -25,12 +25,18 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
/// <inheritdoc cref="IIgnoreCaseMatcher.IgnoreCase"/>
|
||||||
public bool IgnoreCase { get; }
|
public bool IgnoreCase { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
|
private readonly JToken _valueAsJToken;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The string value to check for equality.</param>
|
/// <param name="value">The string value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
public JsonMatcher([NotNull] string value, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public JsonMatcher([NotNull] string value, bool ignoreCase = false, bool throwException = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase, throwException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +45,8 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The object value to check for equality.</param>
|
/// <param name="value">The object value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
public JsonMatcher([NotNull] object value, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public JsonMatcher([NotNull] object value, bool ignoreCase = false, bool throwException = false) : this(MatchBehaviour.AcceptOnMatch, value, ignoreCase, throwException)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,30 +54,19 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="value">The string value to check for equality.</param>
|
/// <param name="value">The value to check for equality.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||||
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] string value, bool ignoreCase = false)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||||
{
|
{
|
||||||
Check.NotNull(value, nameof(value));
|
Check.NotNull(value, nameof(value));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
Value = value;
|
|
||||||
IgnoreCase = ignoreCase;
|
IgnoreCase = ignoreCase;
|
||||||
}
|
ThrowException = throwException;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <param name="value">The object value to check for equality.</param>
|
|
||||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
|
||||||
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false)
|
|
||||||
{
|
|
||||||
Check.NotNull(value, nameof(value));
|
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
|
||||||
Value = value;
|
Value = value;
|
||||||
IgnoreCase = ignoreCase;
|
_valueAsJToken = ConvertValueToJToken(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
|
||||||
@@ -83,41 +79,41 @@ namespace WireMock.Matchers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Check if JToken or object
|
var inputAsJToken = ConvertValueToJToken(input);
|
||||||
JToken jtokenInput = input is JToken tokenInput ? tokenInput : JObject.FromObject(input);
|
|
||||||
|
|
||||||
// Check if JToken, string, IEnumerable or object
|
match = DeepEquals(_valueAsJToken, inputAsJToken);
|
||||||
JToken jtokenValue;
|
|
||||||
switch (Value)
|
|
||||||
{
|
|
||||||
case JToken tokenValue:
|
|
||||||
jtokenValue = tokenValue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case string stringValue:
|
|
||||||
jtokenValue = JsonUtils.Parse(stringValue);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case IEnumerable enumerableValue:
|
|
||||||
jtokenValue = JArray.FromObject(enumerableValue);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
jtokenValue = JObject.FromObject(Value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
match = DeepEquals(jtokenValue, jtokenInput);
|
|
||||||
}
|
}
|
||||||
catch (JsonException)
|
catch (JsonException)
|
||||||
{
|
{
|
||||||
// just ignore JsonException
|
if (ThrowException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
|
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JToken ConvertValueToJToken(object value)
|
||||||
|
{
|
||||||
|
// Check if JToken, string, IEnumerable or object
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case JToken tokenValue:
|
||||||
|
return tokenValue;
|
||||||
|
|
||||||
|
case string stringValue:
|
||||||
|
return JsonUtils.Parse(stringValue);
|
||||||
|
|
||||||
|
case IEnumerable enumerableValue:
|
||||||
|
return JArray.FromObject(enumerableValue);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return JObject.FromObject(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool DeepEquals(JToken value, JToken input)
|
private bool DeepEquals(JToken value, JToken input)
|
||||||
{
|
{
|
||||||
if (!IgnoreCase)
|
if (!IgnoreCase)
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ namespace WireMock.Matchers
|
|||||||
|
|
||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
||||||
@@ -30,7 +32,7 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
/// Initializes a new instance of the <see cref="LinqMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public LinqMatcher([NotNull] string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
public LinqMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, false, patterns)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +41,7 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="pattern">The pattern.</param>
|
/// <param name="pattern">The pattern.</param>
|
||||||
public LinqMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern) : this(matchBehaviour, new[] { pattern })
|
public LinqMatcher(MatchBehaviour matchBehaviour, [NotNull] string pattern) : this(matchBehaviour, false, pattern)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,9 +50,11 @@ namespace WireMock.Matchers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public LinqMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public LinqMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +75,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// just ignore exception
|
if (ThrowException)
|
||||||
// TODO add logging?
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
@@ -113,8 +119,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// just ignore exception
|
if (ThrowException)
|
||||||
// TODO add logging?
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
return MatchBehaviourHelper.Convert(MatchBehaviour, match);
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -53,13 +56,15 @@ namespace WireMock.Matchers
|
|||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||||
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string[] patterns, bool ignoreCase = false)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] string[] patterns, bool ignoreCase = false, bool throwException = false)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
IgnoreCase = ignoreCase;
|
IgnoreCase = ignoreCase;
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
|
|
||||||
RegexOptions options = RegexOptions.Compiled | RegexOptions.Multiline;
|
RegexOptions options = RegexOptions.Compiled | RegexOptions.Multiline;
|
||||||
|
|
||||||
@@ -83,7 +88,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// just ignore exception
|
if (ThrowException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <param name="key">The key.</param>
|
/// <param name="key">The key.</param>
|
||||||
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
/// <param name="ignoreCase">Defines if the key should be matched using case-ignore.</param>
|
||||||
/// <param name="values">The values.</param>
|
/// <param name="values">The values.</param>
|
||||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, bool ignoreCase, [CanBeNull] string[] values) : this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, value)).Cast<IStringMatcher>().ToArray())
|
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, bool ignoreCase, [CanBeNull] string[] values) : this(matchBehaviour, key, ignoreCase, values?.Select(value => new ExactMatcher(matchBehaviour, false, value)).Cast<IStringMatcher>().ToArray())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
/// Initializes a new instance of the <see cref="SimMetricsMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -53,11 +56,14 @@ namespace WireMock.Matchers
|
|||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="simMetricType">The SimMetric Type</param>
|
/// <param name="simMetricType">The SimMetric Type</param>
|
||||||
public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein, bool throwException = false)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(patterns, nameof(patterns));
|
Check.NotNullOrEmpty(patterns, nameof(patterns));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
|
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
_simMetricType = simMetricType;
|
_simMetricType = simMetricType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ namespace WireMock.Matchers
|
|||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
/// <param name="ignoreCase">IgnoreCase</param>
|
/// <param name="ignoreCase">IgnoreCase</param>
|
||||||
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false) : base(matchBehaviour, patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase)
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
|
public WildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] string[] patterns, bool ignoreCase = false, bool throwException = false) :
|
||||||
|
base(matchBehaviour, patterns.Select(pattern => "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$").ToArray(), ignoreCase, throwException)
|
||||||
{
|
{
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,14 @@ namespace WireMock.Matchers
|
|||||||
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
/// <inheritdoc cref="IMatcher.MatchBehaviour"/>
|
||||||
public MatchBehaviour MatchBehaviour { get; }
|
public MatchBehaviour MatchBehaviour { get; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMatcher.ThrowException"/>
|
||||||
|
public bool ThrowException { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public XPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, patterns)
|
public XPathMatcher([NotNull] params string[] patterns) : this(MatchBehaviour.AcceptOnMatch, false, patterns)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,12 +35,14 @@ namespace WireMock.Matchers
|
|||||||
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
/// Initializes a new instance of the <see cref="XPathMatcher"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||||
/// <param name="patterns">The patterns.</param>
|
/// <param name="patterns">The patterns.</param>
|
||||||
public XPathMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] patterns)
|
public XPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params string[] patterns)
|
||||||
{
|
{
|
||||||
Check.NotNull(patterns, nameof(patterns));
|
Check.NotNull(patterns, nameof(patterns));
|
||||||
|
|
||||||
MatchBehaviour = matchBehaviour;
|
MatchBehaviour = matchBehaviour;
|
||||||
|
ThrowException = throwException;
|
||||||
_patterns = patterns;
|
_patterns = patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,8 +63,10 @@ namespace WireMock.Matchers
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// just ignore exception
|
if (ThrowException)
|
||||||
// TODO add logging?
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,5 +45,7 @@ namespace WireMock.Owin
|
|||||||
bool? DisableJsonBodyParsing { get; set; }
|
bool? DisableJsonBodyParsing { get; set; }
|
||||||
|
|
||||||
bool? DisableRequestBodyDecompressing { get; set; }
|
bool? DisableRequestBodyDecompressing { get; set; }
|
||||||
|
|
||||||
|
bool? HandleRequestsSynchronously { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,8 +7,6 @@ using System.Threading.Tasks;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using RandomDataGenerator.FieldOptions;
|
using RandomDataGenerator.FieldOptions;
|
||||||
using RandomDataGenerator.Randomizers;
|
using RandomDataGenerator.Randomizers;
|
||||||
using WireMock.Exceptions;
|
|
||||||
using WireMock.Handlers;
|
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string scenario = mapping.Scenario != null && _options.Scenarios.ContainsKey(mapping.Scenario) ? _options.Scenarios[mapping.Scenario].NextState : null;
|
string nextState = GetNextState(mapping);
|
||||||
|
|
||||||
mappings.Add(new MappingMatcherResult
|
mappings.Add(new MappingMatcherResult
|
||||||
{
|
{
|
||||||
Mapping = mapping,
|
Mapping = mapping,
|
||||||
RequestMatchResult = mapping.GetRequestMatchResult(request, scenario)
|
RequestMatchResult = mapping.GetRequestMatchResult(request, nextState)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -56,5 +56,18 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
return (match, partialMatch);
|
return (match, partialMatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GetNextState(IMapping mapping)
|
||||||
|
{
|
||||||
|
// If the mapping does not have a scenario or _options.Scenarios does not contain this scenario from the mapping,
|
||||||
|
// just return null to indicate that there is no next state.
|
||||||
|
if (mapping.Scenario == null || !_options.Scenarios.ContainsKey(mapping.Scenario))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else just return the next state
|
||||||
|
return _options.Scenarios[mapping.Scenario].NextState;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,7 @@ using System;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using WireMock.Http;
|
using WireMock.Http;
|
||||||
using WireMock.Owin.Mappers;
|
using WireMock.Owin.Mappers;
|
||||||
using WireMock.Serialization;
|
using WireMock.Serialization;
|
||||||
@@ -25,6 +23,7 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
internal class WireMockMiddleware : OwinMiddleware
|
internal class WireMockMiddleware : OwinMiddleware
|
||||||
{
|
{
|
||||||
|
private readonly object _lock = new object();
|
||||||
private static readonly Task CompletedTask = Task.FromResult(false);
|
private static readonly Task CompletedTask = Task.FromResult(false);
|
||||||
private readonly IWireMockMiddlewareOptions _options;
|
private readonly IWireMockMiddlewareOptions _options;
|
||||||
private readonly IOwinRequestMapper _requestMapper;
|
private readonly IOwinRequestMapper _requestMapper;
|
||||||
@@ -65,7 +64,17 @@ namespace WireMock.Owin
|
|||||||
public Task Invoke(IContext ctx)
|
public Task Invoke(IContext ctx)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
return InvokeInternal(ctx);
|
if (_options.HandleRequestsSynchronously.GetValueOrDefault(true))
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
return InvokeInternal(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return InvokeInternal(ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InvokeInternal(IContext ctx)
|
private async Task InvokeInternal(IContext ctx)
|
||||||
@@ -79,7 +88,7 @@ namespace WireMock.Owin
|
|||||||
{
|
{
|
||||||
foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null))
|
foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null))
|
||||||
{
|
{
|
||||||
// Set start
|
// Set scenario start
|
||||||
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState)
|
||||||
{
|
{
|
||||||
_options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState
|
_options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState
|
||||||
@@ -122,9 +131,7 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
if (targetMapping.Scenario != null)
|
if (targetMapping.Scenario != null)
|
||||||
{
|
{
|
||||||
_options.Scenarios[targetMapping.Scenario].NextState = targetMapping.NextState;
|
UpdateScenarioState(targetMapping);
|
||||||
_options.Scenarios[targetMapping.Scenario].Started = true;
|
|
||||||
_options.Scenarios[targetMapping.Scenario].Finished = targetMapping.NextState == null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -157,6 +164,25 @@ namespace WireMock.Owin
|
|||||||
await CompletedTask;
|
await CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateScenarioState(IMapping mapping)
|
||||||
|
{
|
||||||
|
var scenario = _options.Scenarios[mapping.Scenario];
|
||||||
|
|
||||||
|
// Increase the number of times this state has been executed
|
||||||
|
scenario.Counter++;
|
||||||
|
|
||||||
|
// Only if the number of times this state is executed equals the required StateTimes, proceed to next state and reset the counter to 0
|
||||||
|
if (scenario.Counter == (mapping.StateTimes ?? 1))
|
||||||
|
{
|
||||||
|
scenario.NextState = mapping.NextState;
|
||||||
|
scenario.Counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else just update Started and Finished
|
||||||
|
scenario.Started = true;
|
||||||
|
scenario.Finished = mapping.NextState == null;
|
||||||
|
}
|
||||||
|
|
||||||
private void LogRequest(LogEntry entry, bool addRequest)
|
private void LogRequest(LogEntry entry, bool addRequest)
|
||||||
{
|
{
|
||||||
_options.Logger.DebugRequestResponse(LogEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
_options.Logger.DebugRequestResponse(LogEntryMapper.Map(entry), entry.RequestMessage.Path.StartsWith("/__admin/"));
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -51,5 +50,8 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.DisableRequestBodyDecompressing"/>
|
/// <inheritdoc cref="IWireMockMiddlewareOptions.DisableRequestBodyDecompressing"/>
|
||||||
public bool? DisableRequestBodyDecompressing { get; set; }
|
public bool? DisableRequestBodyDecompressing { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockMiddlewareOptions.HandleRequestsSynchronously"/>
|
||||||
|
public bool? HandleRequestsSynchronously { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null)
|
public static IResponseBuilder Create([CanBeNull] ResponseMessage responseMessage = null)
|
||||||
{
|
{
|
||||||
var message = responseMessage ?? new ResponseMessage(); // { StatusCode = (int)HttpStatusCode.OK };
|
var message = responseMessage ?? new ResponseMessage();
|
||||||
return new Response(message);
|
return new Response(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,21 +35,13 @@ namespace WireMock
|
|||||||
/// <inheritdoc cref="IResponseMessage.FaultPercentage" />
|
/// <inheritdoc cref="IResponseMessage.FaultPercentage" />
|
||||||
public double? FaultPercentage { get; set; }
|
public double? FaultPercentage { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.AddHeader(string, string)" />
|
||||||
/// Adds the header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="value">The value.</param>
|
|
||||||
public void AddHeader(string name, string value)
|
public void AddHeader(string name, string value)
|
||||||
{
|
{
|
||||||
Headers.Add(name, new WireMockList<string>(value));
|
Headers.Add(name, new WireMockList<string>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IResponseMessage.AddHeader(string, string[])" />
|
||||||
/// Adds the header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="values">The values.</param>
|
|
||||||
public void AddHeader(string name, params string[] values)
|
public void AddHeader(string name, params string[] values)
|
||||||
{
|
{
|
||||||
Check.NotNullOrEmpty(values, nameof(values));
|
Check.NotNullOrEmpty(values, nameof(values));
|
||||||
|
|||||||
@@ -24,5 +24,10 @@
|
|||||||
/// Gets or sets a value indicating whether this <see cref="ScenarioState"/> is finished.
|
/// Gets or sets a value indicating whether this <see cref="ScenarioState"/> is finished.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Finished { get; set; }
|
public bool Finished { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the state counter.
|
||||||
|
/// </summary>
|
||||||
|
public int Counter { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,6 +38,8 @@ namespace WireMock.Serialization
|
|||||||
|
|
||||||
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.OfType<string>().ToArray() : new[] { matcher.Pattern as string };
|
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.OfType<string>().ToArray() : new[] { matcher.Pattern as string };
|
||||||
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
||||||
|
bool ignoreCase = matcher.IgnoreCase == true;
|
||||||
|
bool throwExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails == true;
|
||||||
|
|
||||||
switch (matcherName)
|
switch (matcherName)
|
||||||
{
|
{
|
||||||
@@ -50,34 +52,34 @@ namespace WireMock.Serialization
|
|||||||
throw new NotSupportedException("It's not allowed to use the 'CSharpCodeMatcher' because IWireMockServerSettings.AllowCSharpCodeMatcher is not set to 'true'.");
|
throw new NotSupportedException("It's not allowed to use the 'CSharpCodeMatcher' because IWireMockServerSettings.AllowCSharpCodeMatcher is not set to 'true'.");
|
||||||
|
|
||||||
case "LinqMatcher":
|
case "LinqMatcher":
|
||||||
return new LinqMatcher(matchBehaviour, stringPatterns);
|
return new LinqMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||||
|
|
||||||
case "ExactMatcher":
|
case "ExactMatcher":
|
||||||
return new ExactMatcher(matchBehaviour, stringPatterns);
|
return new ExactMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||||
|
|
||||||
case "ExactObjectMatcher":
|
case "ExactObjectMatcher":
|
||||||
return CreateExactObjectMatcher(matchBehaviour, stringPatterns[0]);
|
return CreateExactObjectMatcher(matchBehaviour, stringPatterns[0], throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
case "RegexMatcher":
|
case "RegexMatcher":
|
||||||
return new RegexMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
|
return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
case "JsonMatcher":
|
case "JsonMatcher":
|
||||||
return new JsonMatcher(matchBehaviour, matcher.Pattern, matcher.IgnoreCase == true);
|
return new JsonMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
case "JsonPathMatcher":
|
case "JsonPathMatcher":
|
||||||
return new JsonPathMatcher(matchBehaviour, stringPatterns);
|
return new JsonPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||||
|
|
||||||
case "JmesPathMatcher":
|
case "JmesPathMatcher":
|
||||||
return new JmesPathMatcher(matchBehaviour, stringPatterns);
|
return new JmesPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||||
|
|
||||||
case "XPathMatcher":
|
case "XPathMatcher":
|
||||||
return new XPathMatcher(matchBehaviour, stringPatterns);
|
return new XPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||||
|
|
||||||
case "WildcardMatcher":
|
case "WildcardMatcher":
|
||||||
return new WildcardMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
|
return new WildcardMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
case "ContentTypeMatcher":
|
case "ContentTypeMatcher":
|
||||||
return new ContentTypeMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
|
return new ContentTypeMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
case "SimMetricsMatcher":
|
case "SimMetricsMatcher":
|
||||||
SimMetricType type = SimMetricType.Levenstein;
|
SimMetricType type = SimMetricType.Levenstein;
|
||||||
@@ -86,28 +88,13 @@ namespace WireMock.Serialization
|
|||||||
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
|
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SimMetricsMatcher(matchBehaviour, stringPatterns, type);
|
return new SimMetricsMatcher(matchBehaviour, stringPatterns, type, throwExceptionWhenMatcherFails);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
|
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExactObjectMatcher CreateExactObjectMatcher(MatchBehaviour matchBehaviour, string stringPattern)
|
|
||||||
{
|
|
||||||
byte[] bytePattern;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bytePattern = Convert.FromBase64String(stringPattern);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Matcher 'ExactObjectMatcher' has invalid pattern. The pattern value '{stringPattern}' is not a Base64String.", nameof(stringPattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ExactObjectMatcher(matchBehaviour, bytePattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers)
|
public MatcherModel[] Map([CanBeNull] IEnumerable<IMatcher> matchers)
|
||||||
{
|
{
|
||||||
return matchers?.Select(Map).Where(m => m != null).ToArray();
|
return matchers?.Select(Map).Where(m => m != null).ToArray();
|
||||||
@@ -152,5 +139,20 @@ namespace WireMock.Serialization
|
|||||||
Patterns = patterns.Length > 1 ? patterns : null
|
Patterns = patterns.Length > 1 ? patterns : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ExactObjectMatcher CreateExactObjectMatcher(MatchBehaviour matchBehaviour, string stringPattern, bool throwException)
|
||||||
|
{
|
||||||
|
byte[] bytePattern;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
bytePattern = Convert.FromBase64String(stringPattern);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"Matcher 'ExactObjectMatcher' has invalid pattern. The pattern value '{stringPattern}' is not a Base64String.", nameof(stringPattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ExactObjectMatcher(matchBehaviour, bytePattern, throwException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
using WireMock.Settings;
|
|
||||||
|
|
||||||
namespace WireMock.Server
|
|
||||||
{
|
|
||||||
public class FluentMockServer : WireMockServer
|
|
||||||
{
|
|
||||||
public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -86,14 +86,16 @@ namespace WireMock.Server
|
|||||||
/// Once this mapping is executed the state will be changed to specified one.
|
/// Once this mapping is executed the state will be changed to specified one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state">Any object which identifies the new state</param>
|
/// <param name="state">Any object which identifies the new state</param>
|
||||||
|
/// <param name="times">The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.</param>
|
||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider WillSetStateTo(string state);
|
IRespondWithAProvider WillSetStateTo(string state, int? times = 1);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Once this mapping is executed the state will be changed to specified one.
|
/// Once this mapping is executed the state will be changed to specified one.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="state">Any object which identifies the new state</param>
|
/// <param name="state">Any object which identifies the new state</param>
|
||||||
|
/// <param name="times">The number of times this match should be matched before the state will be changed to the specified one. Default value is 1.</param>
|
||||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||||
IRespondWithAProvider WillSetStateTo(int state);
|
IRespondWithAProvider WillSetStateTo(int state, int? times = 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ namespace WireMock.Server
|
|||||||
private string _executionConditionState;
|
private string _executionConditionState;
|
||||||
private string _nextState;
|
private string _nextState;
|
||||||
private string _scenario;
|
private string _scenario;
|
||||||
|
private int _timesInSameState = 1;
|
||||||
private readonly RegistrationCallback _registrationCallback;
|
private readonly RegistrationCallback _registrationCallback;
|
||||||
private readonly IRequestMatcher _requestMatcher;
|
private readonly IRequestMatcher _requestMatcher;
|
||||||
private readonly IWireMockServerSettings _settings;
|
private readonly IWireMockServerSettings _settings;
|
||||||
@@ -46,7 +47,7 @@ namespace WireMock.Server
|
|||||||
/// <param name="provider">The provider.</param>
|
/// <param name="provider">The provider.</param>
|
||||||
public void RespondWith(IResponseProvider provider)
|
public void RespondWith(IResponseProvider provider)
|
||||||
{
|
{
|
||||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState), _saveToFile);
|
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState), _saveToFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
||||||
@@ -120,8 +121,8 @@ namespace WireMock.Server
|
|||||||
return WhenStateIs(state.ToString());
|
return WhenStateIs(state.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(string)"/>
|
/// <see cref="IRespondWithAProvider.WillSetStateTo(string, int?)"/>
|
||||||
public IRespondWithAProvider WillSetStateTo(string state)
|
public IRespondWithAProvider WillSetStateTo(string state, int? times = 1)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(_scenario))
|
if (string.IsNullOrEmpty(_scenario))
|
||||||
{
|
{
|
||||||
@@ -129,14 +130,15 @@ namespace WireMock.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
_nextState = state;
|
_nextState = state;
|
||||||
|
_timesInSameState = times ?? 1;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WillSetStateTo(int)"/>
|
/// <see cref="IRespondWithAProvider.WillSetStateTo(int, int?)"/>
|
||||||
public IRespondWithAProvider WillSetStateTo(int state)
|
public IRespondWithAProvider WillSetStateTo(int state, int? times = 1)
|
||||||
{
|
{
|
||||||
return WillSetStateTo(state.ToString());
|
return WillSetStateTo(state.ToString(), times);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
using JetBrains.Annotations;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -9,6 +6,9 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Scenarios;
|
using WireMock.Admin.Scenarios;
|
||||||
using WireMock.Admin.Settings;
|
using WireMock.Admin.Settings;
|
||||||
@@ -274,7 +274,12 @@ namespace WireMock.Server
|
|||||||
if (HttpStatusRangeParser.IsMatch(settings.ProxyAndRecordSettings.SaveMappingForStatusCodePattern, responseMessage.StatusCode) &&
|
if (HttpStatusRangeParser.IsMatch(settings.ProxyAndRecordSettings.SaveMappingForStatusCodePattern, responseMessage.StatusCode) &&
|
||||||
(settings.ProxyAndRecordSettings.SaveMapping || settings.ProxyAndRecordSettings.SaveMappingToFile))
|
(settings.ProxyAndRecordSettings.SaveMapping || settings.ProxyAndRecordSettings.SaveMappingToFile))
|
||||||
{
|
{
|
||||||
var mapping = ToMapping(requestMessage, responseMessage, settings.ProxyAndRecordSettings.BlackListedHeaders ?? new string[] { }, settings.ProxyAndRecordSettings.BlackListedCookies ?? new string[] { });
|
var mapping = ToMapping(
|
||||||
|
requestMessage,
|
||||||
|
responseMessage,
|
||||||
|
settings.ProxyAndRecordSettings.ExcludedHeaders ?? new string[] { },
|
||||||
|
settings.ProxyAndRecordSettings.ExcludedCookies ?? new string[] { }
|
||||||
|
);
|
||||||
|
|
||||||
if (settings.ProxyAndRecordSettings.SaveMapping)
|
if (settings.ProxyAndRecordSettings.SaveMapping)
|
||||||
{
|
{
|
||||||
@@ -290,7 +295,7 @@ namespace WireMock.Server
|
|||||||
return responseMessage;
|
return responseMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] blacklistedHeaders, string[] blacklistedCookies)
|
private IMapping ToMapping(RequestMessage requestMessage, ResponseMessage responseMessage, string[] excludedHeaders, string[] excludedCookies)
|
||||||
{
|
{
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
request.WithPath(requestMessage.Path);
|
request.WithPath(requestMessage.Path);
|
||||||
@@ -299,39 +304,40 @@ namespace WireMock.Server
|
|||||||
requestMessage.Query.Loop((key, value) => request.WithParam(key, false, value.ToArray()));
|
requestMessage.Query.Loop((key, value) => request.WithParam(key, false, value.ToArray()));
|
||||||
requestMessage.Cookies.Loop((key, value) =>
|
requestMessage.Cookies.Loop((key, value) =>
|
||||||
{
|
{
|
||||||
if (!blacklistedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
|
if (!excludedCookies.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
request.WithCookie(key, value);
|
request.WithCookie(key, value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var allBlackListedHeaders = new List<string>(blacklistedHeaders) { "Cookie" };
|
var allExcludedHeaders = new List<string>(excludedHeaders) { "Cookie" };
|
||||||
requestMessage.Headers.Loop((key, value) =>
|
requestMessage.Headers.Loop((key, value) =>
|
||||||
{
|
{
|
||||||
if (!allBlackListedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
|
if (!allExcludedHeaders.Contains(key, StringComparer.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
request.WithHeader(key, value.ToArray());
|
request.WithHeader(key, value.ToArray());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bool throwExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails == true;
|
||||||
switch (requestMessage.BodyData?.DetectedBodyType)
|
switch (requestMessage.BodyData?.DetectedBodyType)
|
||||||
{
|
{
|
||||||
case BodyType.Json:
|
case BodyType.Json:
|
||||||
request.WithBody(new JsonMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsJson));
|
request.WithBody(new JsonMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsJson, true, throwExceptionWhenMatcherFails));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BodyType.String:
|
case BodyType.String:
|
||||||
request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsString));
|
request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, throwExceptionWhenMatcherFails, requestMessage.BodyData.BodyAsString));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BodyType.Bytes:
|
case BodyType.Bytes:
|
||||||
request.WithBody(new ExactObjectMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsBytes));
|
request.WithBody(new ExactObjectMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyData.BodyAsBytes, throwExceptionWhenMatcherFails));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var response = Response.Create(responseMessage);
|
var response = Response.Create(responseMessage);
|
||||||
|
|
||||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null);
|
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null, null);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -340,11 +346,13 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
var model = new SettingsModel
|
var model = new SettingsModel
|
||||||
{
|
{
|
||||||
AllowPartialMapping = _options.AllowPartialMapping,
|
AllowPartialMapping = _settings.AllowPartialMapping,
|
||||||
MaxRequestLogCount = _options.MaxRequestLogCount,
|
MaxRequestLogCount = _settings.MaxRequestLogCount,
|
||||||
RequestLogExpirationDuration = _options.RequestLogExpirationDuration,
|
RequestLogExpirationDuration = _settings.RequestLogExpirationDuration,
|
||||||
GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds,
|
GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds,
|
||||||
AllowBodyForAllHttpMethods = _options.AllowBodyForAllHttpMethods
|
AllowBodyForAllHttpMethods = _settings.AllowBodyForAllHttpMethods,
|
||||||
|
HandleRequestsSynchronously = _settings.HandleRequestsSynchronously,
|
||||||
|
ThrowExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails
|
||||||
};
|
};
|
||||||
|
|
||||||
return ToJson(model);
|
return ToJson(model);
|
||||||
@@ -371,6 +379,16 @@ namespace WireMock.Server
|
|||||||
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods.Value;
|
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.HandleRequestsSynchronously != null)
|
||||||
|
{
|
||||||
|
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.ThrowExceptionWhenMatcherFails != null)
|
||||||
|
{
|
||||||
|
_settings.ThrowExceptionWhenMatcherFails = settings.ThrowExceptionWhenMatcherFails.Value;
|
||||||
|
}
|
||||||
|
|
||||||
return ResponseMessageBuilder.Create("Settings updated");
|
return ResponseMessageBuilder.Create("Settings updated");
|
||||||
}
|
}
|
||||||
#endregion Settings
|
#endregion Settings
|
||||||
@@ -706,7 +724,8 @@ namespace WireMock.Server
|
|||||||
Name = s.Name,
|
Name = s.Name,
|
||||||
NextState = s.NextState,
|
NextState = s.NextState,
|
||||||
Started = s.Started,
|
Started = s.Started,
|
||||||
Finished = s.Finished
|
Finished = s.Finished,
|
||||||
|
Counter = s.Counter
|
||||||
});
|
});
|
||||||
|
|
||||||
return ToJson(scenariosStates, true);
|
return ToJson(scenariosStates, true);
|
||||||
@@ -814,9 +833,9 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
if (requestModel.Params != null)
|
if (requestModel.Params != null)
|
||||||
{
|
{
|
||||||
foreach (var paramModel in requestModel.Params.Where(c => c.Matchers != null))
|
foreach (var paramModel in requestModel.Params.Where(p => p != null && p.Matchers != null))
|
||||||
{
|
{
|
||||||
bool ignoreCase = paramModel?.IgnoreCase ?? false;
|
bool ignoreCase = paramModel.IgnoreCase == true;
|
||||||
requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
requestBuilder = requestBuilder.WithParam(paramModel.Name, ignoreCase, paramModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -184,6 +184,17 @@ namespace WireMock.Server
|
|||||||
ReadStaticMappings = true
|
ReadStaticMappings = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="WireMockServer"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="settings">The settings.</param>
|
||||||
|
/// <exception cref="WireMockException">
|
||||||
|
/// Service start failed with error: {_httpServer.RunningException.Message}
|
||||||
|
/// or
|
||||||
|
/// Service start failed with error: {startTask.Exception.Message}
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="TimeoutException">Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}</exception>
|
||||||
protected WireMockServer(IWireMockServerSettings settings)
|
protected WireMockServer(IWireMockServerSettings settings)
|
||||||
{
|
{
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
@@ -217,6 +228,7 @@ namespace WireMock.Server
|
|||||||
_options.PostWireMockMiddlewareInit = _settings.PostWireMockMiddlewareInit;
|
_options.PostWireMockMiddlewareInit = _settings.PostWireMockMiddlewareInit;
|
||||||
_options.Logger = _settings.Logger;
|
_options.Logger = _settings.Logger;
|
||||||
_options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing;
|
_options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing;
|
||||||
|
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
||||||
|
|
||||||
_matcherMapper = new MatcherMapper(_settings);
|
_matcherMapper = new MatcherMapper(_settings);
|
||||||
_mappingConverter = new MappingConverter(_matcherMapper);
|
_mappingConverter = new MappingConverter(_matcherMapper);
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace WireMock.Settings
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// FluentMockServerSettings
|
|
||||||
/// </summary>
|
|
||||||
public class FluentMockServerSettings : WireMockServerSettings
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
namespace WireMock.Settings
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// IFluentMockServerSettings
|
|
||||||
/// </summary>
|
|
||||||
public interface IFluentMockServerSettings : IWireMockServerSettings
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,14 +36,14 @@ namespace WireMock.Settings
|
|||||||
string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list from headers which will excluded from the saved mappings.
|
/// Defines a list from headers which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string[] BlackListedHeaders { get; set; }
|
string[] ExcludedHeaders { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines a list of cookies which will excluded from the saved mappings.
|
/// Defines a list of cookies which will be excluded from the saved mappings.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string[] BlackListedCookies { get; set; }
|
string[] ExcludedCookies { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the WebProxySettings.
|
/// Defines the WebProxySettings.
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
namespace WireMock.Settings
|
namespace WireMock.Settings
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// IWebProxySettings
|
||||||
|
/// </summary>
|
||||||
public interface IWebProxySettings
|
public interface IWebProxySettings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using HandlebarsDotNet;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
using WireMock.Logging;
|
using WireMock.Logging;
|
||||||
|
using WireMock.Matchers;
|
||||||
|
|
||||||
namespace WireMock.Settings
|
namespace WireMock.Settings
|
||||||
{
|
{
|
||||||
@@ -143,7 +144,7 @@ namespace WireMock.Settings
|
|||||||
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
|
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
|
||||||
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
|
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// [PublicAPI]
|
[PublicAPI]
|
||||||
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -157,5 +158,17 @@ namespace WireMock.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
bool? DisableRequestBodyDecompressing { get; set; }
|
bool? DisableRequestBodyDecompressing { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Handle all requests synchronously. (default set to false).
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
bool? HandleRequestsSynchronously { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Throw an exception when the <see cref="IMatcher"/> fails because of invalid input. (default set to false).
|
||||||
|
/// </summary>
|
||||||
|
[PublicAPI]
|
||||||
|
bool? ThrowExceptionWhenMatcherFails { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,17 +39,13 @@ namespace WireMock.Settings
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
public string ClientX509Certificate2ThumbprintOrSubjectName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IProxyAndRecordSettings.ExcludedHeaders"/>
|
||||||
/// Defines a list from headers which will excluded from the saved mappings.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string[] BlackListedHeaders { get; set; }
|
public string[] ExcludedHeaders { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc cref="IProxyAndRecordSettings.ExcludedCookies"/>
|
||||||
/// Defines a list of cookies which will excluded from the saved mappings.
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string[] BlackListedCookies { get; set; }
|
public string[] ExcludedCookies { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IProxyAndRecordSettings.WebProxySettings"/>
|
/// <inheritdoc cref="IProxyAndRecordSettings.WebProxySettings"/>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace WireMock.Settings
|
namespace WireMock.Settings
|
||||||
{
|
{
|
||||||
|
/// <seealso cref="IWebProxySettings" />
|
||||||
public class WebProxySettings : IWebProxySettings
|
public class WebProxySettings : IWebProxySettings
|
||||||
{
|
{
|
||||||
/// <inheritdoc cref="IWebProxySettings.Address"/>
|
/// <inheritdoc cref="IWebProxySettings.Address"/>
|
||||||
|
|||||||
@@ -113,5 +113,13 @@ namespace WireMock.Settings
|
|||||||
/// <inheritdoc cref="IWireMockServerSettings.DisableRequestBodyDecompressing"/>
|
/// <inheritdoc cref="IWireMockServerSettings.DisableRequestBodyDecompressing"/>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public bool? DisableRequestBodyDecompressing { get; set; }
|
public bool? DisableRequestBodyDecompressing { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockServerSettings.HandleRequestsSynchronously"/>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool? HandleRequestsSynchronously { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IWireMockServerSettings.ThrowExceptionWhenMatcherFails"/>
|
||||||
|
[PublicAPI]
|
||||||
|
public bool? ThrowExceptionWhenMatcherFails { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,9 @@ namespace WireMock.Settings
|
|||||||
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
|
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
|
||||||
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
|
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
|
||||||
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"),
|
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"),
|
||||||
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing")
|
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing"),
|
||||||
|
HandleRequestsSynchronously = parser.GetBoolValue("HandleRequestsSynchronously"),
|
||||||
|
ThrowExceptionWhenMatcherFails = parser.GetBoolValue("ThrowExceptionWhenMatcherFails")
|
||||||
};
|
};
|
||||||
|
|
||||||
if (logger != null)
|
if (logger != null)
|
||||||
@@ -68,8 +70,8 @@ namespace WireMock.Settings
|
|||||||
SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"),
|
SaveMappingToFile = parser.GetBoolValue("SaveMappingToFile"),
|
||||||
SaveMappingForStatusCodePattern = parser.GetStringValue("SaveMappingForStatusCodePattern"),
|
SaveMappingForStatusCodePattern = parser.GetStringValue("SaveMappingForStatusCodePattern"),
|
||||||
ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"),
|
ClientX509Certificate2ThumbprintOrSubjectName = parser.GetStringValue("ClientX509Certificate2ThumbprintOrSubjectName"),
|
||||||
BlackListedHeaders = parser.GetValues("BlackListedHeaders"),
|
ExcludedHeaders = parser.GetValues("ExcludedHeaders"),
|
||||||
BlackListedCookies = parser.GetValues("BlackListedCookies"),
|
ExcludedCookies = parser.GetValues("ExcludedCookies"),
|
||||||
AllowAutoRedirect = parser.GetBoolValue("AllowAutoRedirect")
|
AllowAutoRedirect = parser.GetBoolValue("AllowAutoRedirect")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using HandlebarsDotNet;
|
using System;
|
||||||
using System;
|
using HandlebarsDotNet;
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
|
|
||||||
namespace WireMock.Transformers
|
namespace WireMock.Transformers
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using HandlebarsDotNet;
|
namespace WireMock.Transformers
|
||||||
|
|
||||||
namespace WireMock.Transformers
|
|
||||||
{
|
{
|
||||||
interface IHandlebarsContextFactory
|
interface IHandlebarsContextFactory
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using HandlebarsDotNet;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using HandlebarsDotNet;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Util;
|
using WireMock.Util;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
|
// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
|
||||||
@@ -96,19 +95,6 @@ namespace WireMock.Validation
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static string NullButNotEmpty(string value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
|
|
||||||
//{
|
|
||||||
// if (!ReferenceEquals(value, null)
|
|
||||||
// && (value.Length == 0))
|
|
||||||
// {
|
|
||||||
// NotNullOrEmpty(parameterName, nameof(parameterName));
|
|
||||||
|
|
||||||
// throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return value;
|
|
||||||
//}
|
|
||||||
|
|
||||||
public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
|
public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
@@ -123,17 +109,5 @@ namespace WireMock.Validation
|
|||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public static Type ValidEntityType(Type value, [InvokerParameterName, ValidatedNotNull, NotNull] string parameterName)
|
|
||||||
//{
|
|
||||||
// if (!value.GetTypeInfo().IsClass)
|
|
||||||
// {
|
|
||||||
// NotNullOrEmpty(parameterName, nameof(parameterName));
|
|
||||||
|
|
||||||
// throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return value;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
|
||||||
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
<AssemblyTitle>WireMock.Net</AssemblyTitle>
|
||||||
<Authors>Stef Heyenrath</Authors>
|
<Authors>Stef Heyenrath</Authors>
|
||||||
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1</TargetFrameworks>
|
<TargetFrameworks>net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1</TargetFrameworks>
|
||||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
<AssemblyName>WireMock.Net</AssemblyName>
|
<AssemblyName>WireMock.Net</AssemblyName>
|
||||||
<PackageId>WireMock.Net</PackageId>
|
<PackageId>WireMock.Net</PackageId>
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants>
|
<DefineConstants>NETSTANDARD;USE_ASPNETCORE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' or '$(TargetFramework)' == 'netcoreapp2.2'">
|
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' or '$(TargetFramework)' == 'netcoreapp2.2' or '$(TargetFramework)' == 'netcoreapp3.1'">
|
||||||
<DefineConstants>USE_ASPNETCORE</DefineConstants>
|
<DefineConstants>USE_ASPNETCORE</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
|
||||||
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
||||||
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
|
<PackageReference Include="Handlebars.Net.Helpers" Version="1.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
||||||
<PackageReference Include="XPath2.Extensions" Version="1.0.6.1" />
|
<PackageReference Include="XPath2.Extensions" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
|
||||||
@@ -101,7 +101,11 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
|
||||||
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/507 -->
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
|
||||||
|
|
||||||
<PackageReference Include="CS-Script" Version="3.29.0" />
|
<PackageReference Include="CS-Script" Version="3.29.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -114,17 +118,29 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
|
||||||
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/507 -->
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
|
||||||
<PackageReference Include="CS-Script.Core" Version="1.1.1" />
|
<PackageReference Include="CS-Script.Core" Version="1.1.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1'">
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
|
||||||
|
|
||||||
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/507 -->
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.6" />
|
||||||
|
|
||||||
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/448 -->
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/448 -->
|
||||||
<PackageReference Include="CS-Script.Core" Version="1.3.1" />
|
<PackageReference Include="CS-Script.Core" Version="1.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1'">
|
||||||
|
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<!-- https://github.com/WireMock-Net/WireMock.Net/issues/448 -->
|
||||||
|
<PackageReference Include="CS-Script.Core" Version="1.4.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
<ProjectReference Include="..\WireMock.Net.Abstractions\WireMock.Net.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
using WireMock.Server;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using WireMock.FluentAssertions;
|
using WireMock.FluentAssertions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Environment;
|
||||||
|
|
||||||
namespace WireMock.Net.Tests.FluentAssertions
|
namespace WireMock.Net.Tests.FluentAssertions
|
||||||
{
|
{
|
||||||
@@ -14,15 +17,26 @@ namespace WireMock.Net.Tests.FluentAssertions
|
|||||||
{
|
{
|
||||||
private WireMockServer _server;
|
private WireMockServer _server;
|
||||||
private HttpClient _httpClient;
|
private HttpClient _httpClient;
|
||||||
private const int Port = 42000;
|
private int _portUsed;
|
||||||
|
|
||||||
public WireMockAssertionsTests()
|
public WireMockAssertionsTests()
|
||||||
{
|
{
|
||||||
_server = WireMockServer.Start(Port);
|
_server = WireMockServer.Start();
|
||||||
_server.Given(Request.Create().UsingAnyMethod())
|
_server.Given(Request.Create().UsingAnyMethod())
|
||||||
.RespondWith(Response.Create().WithStatusCode(200));
|
.RespondWith(Response.Create().WithStatusCode(200));
|
||||||
|
_portUsed = _server.Ports.First();
|
||||||
|
|
||||||
_httpClient = new HttpClient { BaseAddress = new Uri($"http://localhost:{Port}") };
|
_httpClient = new HttpClient { BaseAddress = new Uri($"http://localhost:{_portUsed}") };
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||||
|
{
|
||||||
|
await _httpClient.GetAsync("anyurl");
|
||||||
|
|
||||||
|
_server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.AtAbsoluteUrl($"http://localhost:{_portUsed}/anyurl");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -50,7 +64,96 @@ namespace WireMock.Net.Tests.FluentAssertions
|
|||||||
act.Should().Throw<Exception>()
|
act.Should().Throw<Exception>()
|
||||||
.And.Message.Should()
|
.And.Message.Should()
|
||||||
.Be(
|
.Be(
|
||||||
$"Expected _server to have been called at address matching the absolute url \"anyurl\", but didn't find it among the calls to {{\"http://localhost:{Port}/\"}}.");
|
$"Expected _server to have been called at address matching the absolute url \"anyurl\", but didn't find it among the calls to {{\"http://localhost:{_portUsed}/\"}}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
|
||||||
|
{
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||||
|
await _httpClient.GetAsync("");
|
||||||
|
|
||||||
|
_server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.WithHeader("Authorization", "Bearer a");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithHeader_WhenACallWasMadeWithExpectedHeaderAmongMultipleHeaderValues_Should_BeOK()
|
||||||
|
{
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
await _httpClient.GetAsync("");
|
||||||
|
|
||||||
|
_server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.WithHeader("Accept", new[] { "application/xml", "application/json" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMade()
|
||||||
|
{
|
||||||
|
await _httpClient.GetAsync("");
|
||||||
|
|
||||||
|
Action act = () => _server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.WithHeader("Authorization", "value");
|
||||||
|
|
||||||
|
var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||||
|
.ToDictionary(x => x.Key, x => x.Value)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var sentHeaderString = "{" + string.Join(", ", sentHeaders) + "}";
|
||||||
|
|
||||||
|
act.Should().Throw<Exception>()
|
||||||
|
.And.Message.Should()
|
||||||
|
.Be(
|
||||||
|
$"Expected headers from requests sent {sentHeaderString} to contain key \"Authorization\".{NewLine}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderValuesWereMade()
|
||||||
|
{
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
await _httpClient.GetAsync("");
|
||||||
|
|
||||||
|
Action act = () => _server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.WithHeader("Accept", "missing-value");
|
||||||
|
|
||||||
|
var sentHeaders = _server.LogEntries.SelectMany(x => x.RequestMessage.Headers)
|
||||||
|
.ToDictionary(x => x.Key, x => x.Value)["Accept"]
|
||||||
|
.Select(x => $"\"{x}\"")
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var sentHeaderString = "{" + string.Join(", ", sentHeaders) + "}";
|
||||||
|
|
||||||
|
act.Should().Throw<Exception>()
|
||||||
|
.And.Message.Should()
|
||||||
|
.Be(
|
||||||
|
$"Expected header \"Accept\" from requests sent with value(s) {sentHeaderString} to contain \"missing-value\".{NewLine}");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderWithMultipleValuesWereMade()
|
||||||
|
{
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||||
|
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
await _httpClient.GetAsync("");
|
||||||
|
|
||||||
|
Action act = () => _server.Should()
|
||||||
|
.HaveReceivedACall()
|
||||||
|
.WithHeader("Accept", new[] { "missing-value1", "missing-value2" });
|
||||||
|
|
||||||
|
const string missingValue1Message =
|
||||||
|
"Expected header \"Accept\" from requests sent with value(s) {\"application/xml\", \"application/json\"} to contain \"missing-value1\".";
|
||||||
|
const string missingValue2Message =
|
||||||
|
"Expected header \"Accept\" from requests sent with value(s) {\"application/xml\", \"application/json\"} to contain \"missing-value2\".";
|
||||||
|
|
||||||
|
act.Should().Throw<Exception>()
|
||||||
|
.And.Message.Should()
|
||||||
|
.Be($"{string.Join(NewLine, missingValue1Message, missingValue2Message)}{NewLine}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
|
public void ExactMatcher_IsMatch_SinglePattern_AcceptOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, "cat");
|
var matcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, false, "cat");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("cat");
|
double result = matcher.IsMatch("cat");
|
||||||
@@ -101,7 +101,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
public void ExactMatcher_IsMatch_SinglePattern_RejectOnMatch()
|
public void ExactMatcher_IsMatch_SinglePattern_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new ExactMatcher(MatchBehaviour.RejectOnMatch, "cat");
|
var matcher = new ExactMatcher(MatchBehaviour.RejectOnMatch, false, "cat");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch("cat");
|
double result = matcher.IsMatch("cat");
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
public void JmesPathMatcher_IsMatch_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, "things.x == 'RequiredThing'");
|
var matcher = new JmesPathMatcher(MatchBehaviour.RejectOnMatch, false, "things.x == 'RequiredThing'");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
double match = matcher.IsMatch(JObject.Parse("{ \"things\": { \"x\": \"RequiredThing\" } }"));
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using FluentAssertions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@@ -33,6 +37,52 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
Check.That(value).Equals("{}");
|
Check.That(value).Equals("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonMatcher_WithInvalidStringValue_Should_ThrowException()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
Action action = () => new JsonMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonMatcher_WithInvalidObjectValue_Should_ThrowException()
|
||||||
|
{
|
||||||
|
// Act
|
||||||
|
Action action = () => new JsonMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonMatcher("");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
double match = matcher.IsMatch(new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Check.That(match).IsEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void JsonMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var matcher = new JsonMatcher("", false, true);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
action.Should().Throw<JsonException>();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void JsonMatcher_IsMatch_ByteArray()
|
public void JsonMatcher_IsMatch_ByteArray()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
public void JsonPathMatcher_IsMatch_RejectOnMatch()
|
public void JsonPathMatcher_IsMatch_RejectOnMatch()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, "$..[?(@.Id == 1)]");
|
var matcher = new JsonPathMatcher(MatchBehaviour.RejectOnMatch, false, "$..[?(@.Id == 1)]");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
|
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace WireMock.Net.Tests.Matchers
|
|||||||
<todo-list>
|
<todo-list>
|
||||||
<todo-item id='a1'>abc</todo-item>
|
<todo-item id='a1'>abc</todo-item>
|
||||||
</todo-list>";
|
</todo-list>";
|
||||||
var matcher = new XPathMatcher(MatchBehaviour.RejectOnMatch, "/todo-list[count(todo-item) = 1]");
|
var matcher = new XPathMatcher(MatchBehaviour.RejectOnMatch, false, "/todo-list[count(todo-item) = 1]");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
double result = matcher.IsMatch(xml);
|
double result = matcher.IsMatch(xml);
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ namespace WireMock.Net.Tests.RequestBuilders
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_WithParam_String_IExactMatcher()
|
public void RequestBuilder_WithParam_String_IStringMatcher()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().WithParam("p", new ExactMatcher("v"));
|
var requestBuilder = (Request)Request.Create().WithParam("p", new RegexMatcher("[012]"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
|||||||
{
|
{
|
||||||
public class ResponseWithStatusCodeTests
|
public class ResponseWithStatusCodeTests
|
||||||
{
|
{
|
||||||
private readonly Mock<IFluentMockServerSettings> _settingsMock = new Mock<IFluentMockServerSettings>();
|
private readonly Mock<IWireMockServerSettings> _settingsMock = new Mock<IWireMockServerSettings>();
|
||||||
private const string ClientIp = "::1";
|
private const string ClientIp = "::1";
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create();
|
var response = Response.Create();
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 0, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
@@ -44,7 +44,7 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
// Assign
|
// Assign
|
||||||
var request = Request.Create();
|
var request = Request.Create();
|
||||||
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
|
||||||
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null);
|
var mapping = new Mapping(Guid.NewGuid(), "", null, _settings, request, response, 42, null, null, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var model = _sut.ToMappingModel(mapping);
|
var model = _sut.ToMappingModel(mapping);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using FluentAssertions;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -43,7 +44,8 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
var matcher = (ExactMatcher)_sut.Map(model);
|
var matcher = (ExactMatcher)_sut.Map(model);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(matcher.GetPatterns()).ContainsExactly("x");
|
matcher.GetPatterns().Should().ContainSingle("x");
|
||||||
|
matcher.ThrowException.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -63,6 +65,39 @@ namespace WireMock.Net.Tests.Serialization
|
|||||||
Check.That(matcher.GetPatterns()).ContainsExactly("x", "y");
|
Check.That(matcher.GetPatterns()).ContainsExactly("x", "y");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(nameof(LinqMatcher))]
|
||||||
|
[InlineData(nameof(ExactMatcher))]
|
||||||
|
[InlineData(nameof(ExactObjectMatcher))]
|
||||||
|
[InlineData(nameof(RegexMatcher))]
|
||||||
|
[InlineData(nameof(JsonMatcher))]
|
||||||
|
[InlineData(nameof(JsonPathMatcher))]
|
||||||
|
[InlineData(nameof(JmesPathMatcher))]
|
||||||
|
[InlineData(nameof(XPathMatcher))]
|
||||||
|
[InlineData(nameof(WildcardMatcher))]
|
||||||
|
[InlineData(nameof(ContentTypeMatcher))]
|
||||||
|
[InlineData(nameof(SimMetricsMatcher))]
|
||||||
|
public void MatcherModelMapper_Map_ThrowExceptionWhenMatcherFails_True(string name)
|
||||||
|
{
|
||||||
|
// Assign
|
||||||
|
var settings = new WireMockServerSettings
|
||||||
|
{
|
||||||
|
ThrowExceptionWhenMatcherFails = true
|
||||||
|
};
|
||||||
|
var sut = new MatcherMapper(settings);
|
||||||
|
var model = new MatcherModel
|
||||||
|
{
|
||||||
|
Name = name,
|
||||||
|
Patterns = new[] { "" }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var matcher = sut.Map(model);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
matcher.ThrowException.Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void MatcherModelMapper_Map_ExactObjectMatcher_ValidBase64StringPattern()
|
public void MatcherModelMapper_Map_ExactObjectMatcher_ValidBase64StringPattern()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using WireMock.RequestBuilders;
|
using WireMock.RequestBuilders;
|
||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
@@ -61,6 +62,89 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(responseWithState).Equals("Test state msg");
|
Check.That(responseWithState).Equals("Test state msg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Scenarios_With_Same_Path_Should_Use_Times_When_Moving_To_Next_State()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
const int times = 2;
|
||||||
|
string path = $"/foo_{Guid.NewGuid()}";
|
||||||
|
string body1 = "Scenario S1, No State, Setting State T2";
|
||||||
|
string body2 = "Scenario S1, State T2, End";
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario(1)
|
||||||
|
.WillSetStateTo(2, times)
|
||||||
|
.RespondWith(Response.Create().WithBody(body1));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path).UsingGet())
|
||||||
|
.InScenario(1)
|
||||||
|
.WhenStateIs(2)
|
||||||
|
.RespondWith(Response.Create().WithBody(body2));
|
||||||
|
|
||||||
|
// when
|
||||||
|
var client = new HttpClient();
|
||||||
|
var responseScenario1 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
var responseScenario2 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
var responseWithState = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path);
|
||||||
|
|
||||||
|
// then
|
||||||
|
responseScenario1.Should().Be(body1);
|
||||||
|
responseScenario2.Should().Be(body1);
|
||||||
|
responseWithState.Should().Be(body2);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task Scenarios_With_Different_Paths_Should_Use_Times_When_Moving_To_Next_State()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
const int times = 2;
|
||||||
|
string path1 = $"/a_{Guid.NewGuid()}";
|
||||||
|
string path2 = $"/b_{Guid.NewGuid()}";
|
||||||
|
string path3 = $"/c_{Guid.NewGuid()}";
|
||||||
|
string body1 = "Scenario S1, No State, Setting State T2";
|
||||||
|
string body2 = "Scenario S1, State T2, Setting State T3";
|
||||||
|
string body3 = "Scenario S1, State T3, End";
|
||||||
|
|
||||||
|
var server = WireMockServer.Start();
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path1).UsingGet())
|
||||||
|
.InScenario("S1")
|
||||||
|
.WillSetStateTo("T2", times)
|
||||||
|
.RespondWith(Response.Create().WithBody(body1));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path2).UsingGet())
|
||||||
|
.InScenario("S1")
|
||||||
|
.WhenStateIs("T2")
|
||||||
|
.WillSetStateTo("T3", times)
|
||||||
|
.RespondWith(Response.Create().WithBody(body2));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create().WithPath(path3).UsingGet())
|
||||||
|
.InScenario("S1")
|
||||||
|
.WhenStateIs("T3")
|
||||||
|
.RespondWith(Response.Create().WithBody(body3));
|
||||||
|
|
||||||
|
// when
|
||||||
|
var client = new HttpClient();
|
||||||
|
var t1a = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path1);
|
||||||
|
var t1b = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path1);
|
||||||
|
var t2a = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path2);
|
||||||
|
var t2b = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path2);
|
||||||
|
var t3 = await client.GetStringAsync("http://localhost:" + server.Ports[0] + path3);
|
||||||
|
|
||||||
|
// then
|
||||||
|
t1a.Should().Be(body1);
|
||||||
|
t1b.Should().Be(body1);
|
||||||
|
t2a.Should().Be(body2);
|
||||||
|
t2b.Should().Be(body2);
|
||||||
|
t3.Should().Be(body3);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Scenarios_Should_Respect_Int_Valued_Scenarios_and_States()
|
public async Task Scenarios_Should_Respect_Int_Valued_Scenarios_and_States()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,17 +44,17 @@
|
|||||||
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
<PackageReference Include="FluentAssertions" Version="5.10.3" />
|
||||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||||
<PackageReference Include="RestEase" Version="1.4.10" />
|
<PackageReference Include="RestEase" Version="1.4.10" />
|
||||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.10" />
|
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
|
||||||
<PackageReference Include="Moq" Version="4.13.1" />
|
<PackageReference Include="Moq" Version="4.14.5" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||||
<PackageReference Include="NFluent" Version="2.7.0" />
|
<PackageReference Include="NFluent" Version="2.7.0" />
|
||||||
<PackageReference Include="OpenCover" Version="4.7.922" />
|
<PackageReference Include="OpenCover" Version="4.7.922" />
|
||||||
<PackageReference Include="ReportGenerator" Version="4.5.4" />
|
<PackageReference Include="ReportGenerator" Version="4.6.7" />
|
||||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace WireMock.Net.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_content_header_in_mapping()
|
public async Task WireMockServer_Proxy_Should_exclude_ExcludedHeaders_in_mapping()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
string path = $"/prx_{Guid.NewGuid()}";
|
string path = $"/prx_{Guid.NewGuid()}";
|
||||||
@@ -139,7 +139,7 @@ namespace WireMock.Net.Tests
|
|||||||
Url = serverForProxyForwarding.Urls[0],
|
Url = serverForProxyForwarding.Urls[0],
|
||||||
SaveMapping = true,
|
SaveMapping = true,
|
||||||
SaveMappingToFile = false,
|
SaveMappingToFile = false,
|
||||||
BlackListedHeaders = new[] { "blacklisted" }
|
ExcludedHeaders = new[] { "excluded-header-X" }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var server = WireMockServer.Start(settings);
|
var server = WireMockServer.Start(settings);
|
||||||
@@ -152,7 +152,7 @@ namespace WireMock.Net.Tests
|
|||||||
RequestUri = new Uri($"{server.Urls[0]}{path}"),
|
RequestUri = new Uri($"{server.Urls[0]}{path}"),
|
||||||
Content = new StringContent("stringContent")
|
Content = new StringContent("stringContent")
|
||||||
};
|
};
|
||||||
requestMessage.Headers.Add("blacklisted", "exact_match");
|
requestMessage.Headers.Add("foobar", "exact_match");
|
||||||
requestMessage.Headers.Add("ok", "ok-value");
|
requestMessage.Headers.Add("ok", "ok-value");
|
||||||
await new HttpClient().SendAsync(requestMessage);
|
await new HttpClient().SendAsync(requestMessage);
|
||||||
|
|
||||||
@@ -160,12 +160,12 @@ namespace WireMock.Net.Tests
|
|||||||
var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);
|
var mapping = server.Mappings.FirstOrDefault(m => m.Guid != defaultMapping.Guid);
|
||||||
Check.That(mapping).IsNotNull();
|
Check.That(mapping).IsNotNull();
|
||||||
var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().Select(m => m.Name).ToList();
|
var matchers = ((Request)mapping.RequestMatcher).GetRequestMessageMatchers<RequestMessageHeaderMatcher>().Select(m => m.Name).ToList();
|
||||||
Check.That(matchers).Not.Contains("blacklisted");
|
Check.That(matchers).Not.Contains("excluded-header-X");
|
||||||
Check.That(matchers).Contains("ok");
|
Check.That(matchers).Contains("ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task WireMockServer_Proxy_Should_exclude_blacklisted_cookies_in_mapping()
|
public async Task WireMockServer_Proxy_Should_exclude_ExcludedCookies_in_mapping()
|
||||||
{
|
{
|
||||||
// Assign
|
// Assign
|
||||||
string path = $"/prx_{Guid.NewGuid()}";
|
string path = $"/prx_{Guid.NewGuid()}";
|
||||||
@@ -181,7 +181,7 @@ namespace WireMock.Net.Tests
|
|||||||
Url = serverForProxyForwarding.Urls[0],
|
Url = serverForProxyForwarding.Urls[0],
|
||||||
SaveMapping = true,
|
SaveMapping = true,
|
||||||
SaveMappingToFile = false,
|
SaveMappingToFile = false,
|
||||||
BlackListedCookies = new[] { "ASP.NET_SessionId" }
|
ExcludedCookies = new[] { "ASP.NET_SessionId" }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var server = WireMockServer.Start(settings);
|
var server = WireMockServer.Start(settings);
|
||||||
@@ -515,7 +515,7 @@ namespace WireMock.Net.Tests
|
|||||||
content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.".
|
content.Should().Contain("known"); // On Linux it's "Name or service not known". On Windows it's "No such host is known.".
|
||||||
|
|
||||||
server.LogEntries.Should().HaveCount(1);
|
server.LogEntries.Should().HaveCount(1);
|
||||||
((StatusModel) server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
|
((StatusModel)server.LogEntries.First().ResponseMessage.BodyData.BodyAsJson).Status.Should().Contain("known");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user