Compare commits

..

18 Commits

Author SHA1 Message Date
Stef Heyenrath
ec8bb27ffc 1.0.4.5 2018-07-17 08:30:49 +02:00
Stef Heyenrath
a9c0c6b670 Support running WireMock.Net as a sub-app in IIS (#164) (#158)
* Update examples (#158)

* IIS debug

* PathBase logic

* 1.0.4.5-preview-01

* Fix project and readme

* Fix issues

* fix picture alignment

* Add IIS publish examples

* 1.0.4.5
2018-07-17 08:20:44 +02:00
Stef Heyenrath
a96c8100cf Fix Sonar issues (#166)
* Fix Sonar issues

* Fix Sonar issues
2018-07-16 20:04:35 +02:00
Stef Heyenrath
cc6b311814 Fix readme table 2018-07-15 11:45:55 +02:00
Stef Heyenrath
96eaa657e5 Update Readme for Sonar / update table 2018-07-15 11:42:56 +02:00
Stef Heyenrath
3125c1bead Add SonarCloud (#165)
* dotnet-sonarscanner

* .

* fix install

* add ProjectGuid

* Move "sonarscanner end" to tests

* Fix ProjectGuid and version

* /v

* label

* SONAR_TOKEN

* APPVEYOR_BUILD_NUMBER

* opencover

* readme

* readme
2018-07-15 11:14:50 +02:00
Stef Heyenrath
9e9eadf693 1.0.4.4 (#156) 2018-07-01 11:10:34 +02:00
Stef Heyenrath
fe9f4902b1 1.0.4.3 2018-06-30 00:06:53 +02:00
Stef Heyenrath
db013a56ad Merge branch 'param' 2018-06-29 23:59:30 +02:00
Stef Heyenrath
7b2deceafd Merge branch 'Fix_IRequestBuilder.WithParam' 2018-06-29 22:32:31 +02:00
Stef Heyenrath
281b970c57 WithParam (#159) 2018-06-28 20:50:09 +02:00
Stef Heyenrath
768cc621ad #156 2018-06-27 20:19:27 +02:00
Stef Heyenrath
3df8bd2fdc #156 2018-06-27 20:02:16 +02:00
Stef Heyenrath
2d1ead25cd #156 2018-06-27 19:56:53 +02:00
Stef Heyenrath
24d00845fb 1.0.4.2 2018-06-26 23:24:32 +02:00
Stef Heyenrath
4283732b6c Support for string and object in JsonMatcher. (#157)
* JsonMatcher (#154)

* small update in example code
2018-06-26 23:20:30 +02:00
Stef Heyenrath
b2690017a8 Set Microsoft.NET.Test.Sdk back to 15.3.0 2018-06-25 20:29:10 +02:00
Stef Heyenrath
9470130d65 responsebody.json 2018-06-25 20:21:40 +02:00
91 changed files with 963 additions and 370 deletions

View File

@@ -1,7 +1,44 @@
# 1.0.4.5 (17 July 2018)
- [#166](https://github.com/WireMock-Net/WireMock.Net/pull/166) - Fix Sonar issues contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
- [#165](https://github.com/WireMock-Net/WireMock.Net/pull/165) - Add SonarCloud contributed by Stef Heyenrath ([StefH](https://github.com/StefH))
- [#164](https://github.com/WireMock-Net/WireMock.Net/pull/164) - Support running WireMock.Net as a sub-app in IIS contributed by Stef Heyenrath ([StefH](https://github.com/StefH)) +feature
- [#158](https://github.com/WireMock-Net/WireMock.Net/issues/158) - Feature: Support running WireMock.Net as a sub-app in IIS
- [#123](https://github.com/WireMock-Net/WireMock.Net/issues/123) - Fix for DateTime Header causing null value in ResponseBuilder
- [#120](https://github.com/WireMock-Net/WireMock.Net/issues/120) - Question: JsonPathMatcher - not matching? Correct syntax?
- [#105](https://github.com/WireMock-Net/WireMock.Net/issues/105) - Question: URL binding issues
Commits: 3125c1bead...a9c0c6b670
# 1.0.4.4 (01 July 2018)
- [#156](https://github.com/WireMock-Net/WireMock.Net/issues/156) - Feature: when adding / updating a mapping : return more details
Commits: ...
# 1.0.4.3 (30 June 2018)
- [#159](https://github.com/WireMock-Net/WireMock.Net/issues/159) - Bug: IRequestBuilder.WithParam broken for key-only matching +fix
- [#156](https://github.com/WireMock-Net/WireMock.Net/issues/156) - Feature: when adding / updating a mapping : return more details
Commits: 2d1ead25cd...db013a56ad
# 1.0.4.2 (26 June 2018)
- [#157](https://github.com/WireMock-Net/WireMock.Net/pull/157) - Support for string and object in JsonMatcher. contributed by Stef Heyenrath ([StefH](https://github.com/StefH)) +feature
- [#155](https://github.com/WireMock-Net/WireMock.Net/pull/155) - Replace JsonMatcher with JsonObjectMatcher and directly support JSON body matching. contributed by ([DavidKorn](https://github.com/DavidKorn))
- [#154](https://github.com/WireMock-Net/WireMock.Net/issues/154) - Feature: support BodyAsJson for Request in static mapping files. +feature
Commits: 9470130d65...4283732b6c
# 1.0.4.1 (25 June 2018)
- [#153](https://github.com/WireMock-Net/WireMock.Net/issues/153) - Feature: Add JsonMatcher to support Json mapping
Commits: f61a814ab5...2eff243a96

View File

@@ -1,5 +1,5 @@
https://github.com/GitTools/GitReleaseNotes
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.1
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.5
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags

View File

@@ -1,16 +1,23 @@
# WireMock.Net
A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) which mimics the functionality from the JAVA based http://WireMock.org
A C# .NET version based on [mock4net](https://github.com/alexvictoor/mock4net) which mimics the functionality from the JAVA based [WireMock.org](http://WireMock.org).
[![Gitter](https://img.shields.io/gitter/room/wiremock_dotnet/Lobby.svg)](https://gitter.im/wiremock_dotnet/Lobby)
[![GitHub issues](https://img.shields.io/github/issues/WireMock-Net/WireMock.Net.svg)](https://github.com/WireMock-Net/WireMock.Net/issues)
[![Build status](https://ci.appveyor.com/api/projects/status/b3n6q3ygbww4lyls?svg=true)](https://ci.appveyor.com/project/StefH/wiremock-net)
[![Coverage Status](https://coveralls.io/repos/github/WireMock-Net/WireMock.Net/badge.svg?branch=master)](https://coveralls.io/github/WireMock-Net/WireMock.Net?branch=master)
[![GitHub stars](https://img.shields.io/github/stars/WireMock-Net/WireMock.Net.svg)](https://github.com/WireMock-Net/WireMock.Net/stargazers)
| Name | NuGet |
| ---- | ----- |
| WireMock.Net | [![NuGet Badge](https://buildstats.info/nuget/WireMock.Net)](https://www.nuget.org/packages/WireMock.Net) |
| WireMock.Net.StandAlone | [![NuGet Badge](https://buildstats.info/nuget/WireMock.Net.StandAlone)](https://www.nuget.org/packages/WireMock.Net.StandAlone) |
### Info
| | |
| --- | --- |
| **Chat** | [![Gitter](https://img.shields.io/gitter/room/wiremock_dotnet/Lobby.svg)](https://gitter.im/wiremock_dotnet/Lobby) |
| **Issues** | [![GitHub issues](https://img.shields.io/github/issues/WireMock-Net/WireMock.Net.svg)](https://github.com/WireMock-Net/WireMock.Net/issues) |
| **Build** | [![Build status](https://ci.appveyor.com/api/projects/status/b3n6q3ygbww4lyls?svg=true)](https://ci.appveyor.com/project/StefH/wiremock-net) |
| | |
| ***Sonar*** |   |
|  **Sonar Quality Gate** | [![Sonar Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=wiremock&metric=alert_status)](https://sonarcloud.io/project/issues?id=wiremock) |
|  **Sonar Bugs** | [![Sonar Bugs](https://sonarcloud.io/api/project_badges/measure?project=wiremock&metric=bugs)](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=BUG) |
|  **Sonar Code Smells** | [![Sonar Code Smells](https://sonarcloud.io/api/project_badges/measure?project=wiremock&metric=code_smells)](https://sonarcloud.io/project/issues?id=wiremock&resolved=false&types=CODE_SMELL) |
|  **Sonar Coverage** | [![Sonar Coverage](https://sonarcloud.io/api/project_badges/measure?project=wiremock&metric=coverage)](https://sonarcloud.io/component_measures?id=wiremock&metric=coverage) |
|  **Coveralls.io** | [![Coverage Status](https://coveralls.io/repos/github/WireMock-Net/WireMock.Net/badge.svg?branch=master)](https://coveralls.io/github/WireMock-Net/WireMock.Net?branch=master) |
| | |
| ***Nuget*** |   |
|  **WireMock.Net** | [![NuGet Badge WireMock.Net](https://buildstats.info/nuget/WireMock.Net)](https://www.nuget.org/packages/WireMock.Net) |
|  **WireMock.Net.StandAlone** | [![NuGet Badge WireMock.Net.StandAlone](https://buildstats.info/nuget/WireMock.Net.StandAlone)](https://www.nuget.org/packages/WireMock.Net.StandAlone) |
### Frameworks
The following frameworks are supported:

View File

@@ -42,7 +42,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone.Net
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.NET452", "examples\WireMock.Net.ConsoleApplication\WireMock.Net.Console.NET452.csproj", "{668F689E-57B4-422E-8846-C0FF643CA268}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.WebApplication.NETCore2", "examples\WireMock.Net.WebApplication\WireMock.Net.WebApplication.NETCore2.csproj", "{049539C1-7A66-4559-AD7A-B1C73B97CBB0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Console.Proxy.Net452", "examples\WireMock.Net.Console.Proxy.Net452\WireMock.Net.Console.Proxy.Net452.csproj", "{26433A8F-BF01-4962-97EB-81BFFBB61096}"
EndProject

View File

@@ -1,6 +1,6 @@
os: Visual Studio 2017
version: 1.0.2.{build}
version: 1.0.4.{build}
configuration:
- Debug
@@ -8,29 +8,34 @@ configuration:
init:
- ps: $Env:LABEL = "CI" + $Env:APPVEYOR_BUILD_NUMBER.PadLeft(5, "0")
# install dotnet SDK and dotnet-sonarscanner
install:
- ps: Start-FileDownload 'https://download.microsoft.com/download/0/F/D/0FD852A4-7EA1-4E2A-983A-0484AC19B92C/dotnet-sdk-2.0.0-win-gs-x64.exe'
- cmd: dotnet-sdk-2.0.0-win-gs-x64.exe /quiet
- ps: $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
- ps: Start-FileDownload 'https://download.microsoft.com/download/4/0/9/40920432-3302-47a8-b13c-bbc4848ad114/dotnet-sdk-2.1.302-win-x64.exe'
- cmd: dotnet-sdk-2.1.302-win-x64.exe /quiet
- ps: $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
- dotnet tool install --global dotnet-sonarscanner
environment:
PATH: $(PATH);$(PROGRAMFILES)\dotnet\
COVERALLS_REPO_TOKEN:
secure: Eq/3VV5DVAeQAlQhe6hvy21IYPo5uY4fWKxvC4pxdq3giJzcwFp1QxBvRpXJ8Wkw
SONAR_TOKEN:
secure: guog1+ttdnlD8sVgvizlewksm3qbO7dy2oZUcR8WhurWYvdOByinxXo732hmSaMT
before_build:
- dotnet restore .\src\WireMock.Net\WireMock.Net.csproj
- dotnet restore .\src\WireMock.Net.Standalone\WireMock.Net.Standalone.csproj
- dotnet restore .\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj
build_script:
# build WireMock.Net
# build WireMock.Net with SonarScanner
- dotnet sonarscanner begin /k:"wiremock" /d:sonar.organization="stefh-github" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.login="%SONAR_TOKEN%" /v:"%APPVEYOR_BUILD_NUMBER%" /d:sonar.cs.opencover.reportsPaths="%CD%\coverage.xml"
- dotnet build .\src\WireMock.Net\WireMock.Net.csproj -c %CONFIGURATION%
# build WireMock.Net.Standalone
- dotnet build .\src\WireMock.Net.Standalone\WireMock.Net.Standalone.csproj -c %CONFIGURATION%
# restore and build WireMock.Net.Tests
- dotnet restore .\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj
# build WireMock.Net.Tests
- dotnet build .\test\WireMock.Net.Tests\WireMock.Net.Tests.csproj -c %CONFIGURATION%
test_script:
@@ -41,3 +46,4 @@ test_script:
- cmd: '"OpenCover\tools\OpenCover.Console.exe" -target:dotnet.exe -targetargs:"test test\WireMock.Net.Tests\WireMock.Net.Tests.csproj --no-build" -output:coverage.xml -returntargetcode -register:user -filter:"+[WireMock.Net]* -[WireMock.Net.Tests*]*" -nodefaultfilters -returntargetcode -oldstyle -searchdirs:".\test\WireMock.Net.Tests\bin\%CONFIGURATION%\net452"'
- codecov -f "coverage.xml"
- coveralls.net\tools\csmacnz.Coveralls.exe --opencover -i .\coverage.xml
- dotnet sonarscanner end /d:sonar.login="%SONAR_TOKEN%"

View File

@@ -43,11 +43,11 @@ namespace WireMock.Net.Client
var request = api.GetRequestsAsync().Result;
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
string deleteRequestsAsync = api.DeleteRequestsAsync().Result;
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync}");
var deleteRequestsAsync = api.DeleteRequestsAsync().Result;
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync.Status}");
string resetRequestsAsync = api.ResetRequestsAsync().Result;
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync}");
var resetRequestsAsync = api.ResetRequestsAsync().Result;
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync.Status}");
Console.WriteLine("Press any key to quit");
Console.ReadKey();

View File

@@ -57,12 +57,22 @@ namespace WireMock.Net.ConsoleApplication
server
.Given(Request
.Create()
.WithPath("/jsonbodytest")
.WithPath("/jsonbodytest1")
.WithBody(new JsonMatcher("{ \"x\": 42, \"s\": \"s\" }"))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f2")
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""jsonbodytest"" }"));
.WithBody(@"{ ""result"": ""jsonbodytest1"" }"));
server
.Given(Request
.Create()
.WithPath("/jsonbodytest2")
.WithBody(new JsonMatcher(new { x = 42, s = "s" }))
.UsingPost())
.WithGuid("debaf408-3b23-4c04-9d18-ef1c020e79f3")
.RespondWith(Response.Create()
.WithBody(@"{ ""result"": ""jsonbodytest2"" }"));
server
.Given(Request
@@ -71,13 +81,33 @@ namespace WireMock.Net.ConsoleApplication
.WithParam("$filter", "(substringof(Code, 'WA')")
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""odata""}"));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/param2", true))
.WithParam("key", "test")
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "param2" }));
server
.Given(Request
.Create()
.WithPath(new WildcardMatcher("/param3", true))
.WithParam("key", new WildcardMatcher("t*"))
.UsingGet())
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "param3" }));
server
.Given(Request.Create().WithPath("/headers", "/headers_test").UsingPost().WithHeader("Content-Type", "application/json*"))
.RespondWith(Response.Create()
.WithStatusCode(201)
//.WithHeader("MyHeader", "application/json", "application/json2")
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { result = "data:headers posted with 201" }));
@@ -184,8 +214,6 @@ namespace WireMock.Net.ConsoleApplication
.WithStatusCode(HttpStatusCode.Unauthorized)
.WithBody(@"{ ""result"": ""api-key missing""}"));
server
.Given(Request.Create().WithPath("/nobody").UsingGet())
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
@@ -195,7 +223,7 @@ namespace WireMock.Net.ConsoleApplication
.Given(Request.Create().WithPath("/partial").UsingPost().WithBody(new SimMetricsMatcher(new[] { "cat", "dog" })))
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
// http://localhost:8080/any/any?start=1000&stop=1&stop=2
// http://localhost:8080/trans?start=1000&stop=1&stop=2
server
.Given(Request.Create().WithPath("/trans").UsingGet())
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
@@ -203,6 +231,7 @@ namespace WireMock.Net.ConsoleApplication
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
.WithHeader("xyz_{{request.headers.Postman-Token}}", "token is {{request.headers.Postman-Token}}")
.WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
.WithTransformer()
.WithDelay(TimeSpan.FromMilliseconds(100))

View File

@@ -2,8 +2,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.0;netcoreapp1.1</TargetFrameworks>
<ApplicationIcon>../../WireMock.Net-Logo.ico</ApplicationIcon>
<StartupObject>WireMock.Net.StandAlone.NETCoreApp.Program</StartupObject>
</PropertyGroup>
<ItemGroup>

View File

@@ -0,0 +1 @@
dotnet run --framework netcoreapp2.1

View File

@@ -42,8 +42,18 @@
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.4.0.0\lib\net451\Microsoft.Owin.Host.HttpListener.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.4\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
@@ -53,6 +63,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.8" targetFramework="net452" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net452" />
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
</packages>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<ProjectGuid>049539c1-7a66-4559-ad7a-b1c73b97cbb0</ProjectGuid>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>Default Web Site/wiremock1</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<ProjectGuid>049539c1-7a66-4559-ad7a-b1c73b97cbb1</ProjectGuid>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
<MSDeployServiceURL>localhost</MSDeployServiceURL>
<DeployIisAppPath>Default Web Site/wiremock2</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>InProc</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName />
<_SavePWD>False</_SavePWD>
<PublishDatabaseSettings>
<Objects xmlns="" />
</PublishDatabaseSettings>
</PropertyGroup>
</Project>

View File

@@ -2,6 +2,10 @@
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iis": {
"applicationUrl": "http://localhost//wiremock",
"sslPort": 0
},
"iisExpress": {
"applicationUrl": "http://localhost:56513/",
"sslPort": 0
@@ -23,6 +27,12 @@
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:56514/"
},
"IIS": {
"commandName": "IIS",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "development"
}
}
}
}

View File

@@ -1,17 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<StartupObject>WireMock.Net.WebApplication.Program</StartupObject>
<AssemblyName>WireMock.Net.WebApplication</AssemblyName>
<RootNamespace>WireMock.Net.WebApplication</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

View File

@@ -0,0 +1,21 @@
# Running in IIS
Follow these links / steps:
* https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS
* https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/development-time-iis-support?view=aspnetcore-2.1
* Create a `web.config` file
## IIS Sites
![IIS Multiple](resources/iis-wiremock1and2.png)
## App Pool settings
![IIS Multiple](resources/iis-apppool.png)
## Publish Profiles
Two example publish profiles are created:
* [IIS Localhost 1](./Properties/PublishProfiles/IIS%20Localhost%201.pubxml)
* [IIS Localhost 2](./Properties/PublishProfiles/IIS%20Localhost%202.pubxml)
## Debugging
Select the debug "IIS" if you want to debug in IIS.
![IIS Debug](resources/iis-debug.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
</system.webServer>
</configuration>

View File

@@ -41,6 +41,7 @@ namespace WireMock.Net.StandAlone
Arguments[currentName] = values.ToArray();
}
}
public bool Contains(string name)
{
return Arguments.ContainsKey(name);

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Version>1.0.4.1</Version>
<Version>1.0.4.5</Version>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -21,6 +21,7 @@
<DebugType>full</DebugType>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<ProjectGuid>{B6269AAC-170A-43D5-8B9A-579DED3D9A95}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">

View File

@@ -9,15 +9,5 @@
/// Gets or sets the matcher.
/// </summary>
public MatcherModel Matcher { get; set; }
///// <summary>
///// Gets or sets the function.
///// </summary>
//public string Func { get; set; }
///// <summary>
///// Gets or sets the data function.
///// </summary>
//public string DataFunc { get; set; }
}
}

View File

@@ -9,10 +9,5 @@
/// Gets or sets the matchers.
/// </summary>
public MatcherModel[] Matchers { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
}
}

View File

@@ -16,10 +16,5 @@ namespace WireMock.Admin.Mappings
/// Gets or sets the matchers.
/// </summary>
public IList<MatcherModel> Matchers { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
}
}

View File

@@ -16,10 +16,5 @@ namespace WireMock.Admin.Mappings
/// Gets or sets the matchers.
/// </summary>
public IList<MatcherModel> Matchers { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
}
}

View File

@@ -11,19 +11,14 @@
public string Name { get; set; }
/// <summary>
/// Gets or sets the value. Used by <see cref="Matchers.JsonMatcher"/>.
/// Gets or sets the pattern. Can be a string (default) or an object;
/// </summary>
public string Value { get; set; }
public object Pattern { get; set; }
/// <summary>
/// Gets or sets the pattern.
/// Gets or sets the patterns. Can be array of strings (default) or an array of objects;
/// </summary>
public string Pattern { get; set; }
/// <summary>
/// Gets or sets the patterns.
/// </summary>
public string[] Patterns { get; set; }
public object[] Patterns { get; set; }
/// <summary>
/// Gets or sets the ignore case.

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
namespace WireMock.Admin.Mappings
namespace WireMock.Admin.Mappings
{
/// <summary>
/// Param Model
@@ -13,13 +11,8 @@ namespace WireMock.Admin.Mappings
public string Name { get; set; }
/// <summary>
/// Gets or sets the values.
/// Gets or sets the matchers.
/// </summary>
public IList<string> Values { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
public MatcherModel[] Matchers { get; set; }
}
}

View File

@@ -9,10 +9,5 @@
/// Gets or sets the matchers.
/// </summary>
public MatcherModel[] Matchers { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace WireMock.Admin.Mappings
{
/// <summary>
/// Status
/// </summary>
public class StatusModel
{
/// <summary>
/// The optional guid.
/// </summary>
public Guid? Guid { get; set; }
/// <summary>
/// The status (can also contain the error message).
/// </summary>
public string Status { get; set; }
}
}

View File

@@ -9,10 +9,5 @@
/// Gets or sets the matchers.
/// </summary>
public MatcherModel[] Matchers { get; set; }
///// <summary>
///// Gets or sets the functions.
///// </summary>
//public string[] Funcs { get; set; }
}
}

View File

@@ -26,7 +26,17 @@ namespace WireMock.Admin.Requests
public string Path { get; set; }
/// <summary>
///The absolete URL.
/// The Absolute Path.
/// </summary>
public string AbsolutePath { get; set; }
/// <summary>
/// Gets the url (relative).
/// </summary>
public string Url { get; set; }
/// <summary>
/// The absolete URL.
/// </summary>
public string AbsoluteUrl { get; set; }

View File

@@ -33,7 +33,7 @@ namespace WireMock.Client
/// <param name="settings">SettingsModel</param>
[Put("__admin/settings")]
[Header("Content-Type", "application/json")]
Task<string> PutSettingsAsync([Body] SettingsModel settings);
Task<StatusModel> PutSettingsAsync([Body] SettingsModel settings);
/// <summary>
/// Update the settings
@@ -41,7 +41,7 @@ namespace WireMock.Client
/// <param name="settings">SettingsModel</param>
[Post("__admin/settings")]
[Header("Content-Type", "application/json")]
Task<string> PostSettingsAsync([Body] SettingsModel settings);
Task<StatusModel> PostSettingsAsync([Body] SettingsModel settings);
/// <summary>
/// Get the mappings.
@@ -56,19 +56,19 @@ namespace WireMock.Client
/// <param name="mapping">MappingModel</param>
[Post("__admin/mappings")]
[Header("Content-Type", "application/json")]
Task<string> PostMappingAsync([Body] MappingModel mapping);
Task<StatusModel> PostMappingAsync([Body] MappingModel mapping);
/// <summary>
/// Delete all mappings.
/// </summary>
[Delete("__admin/mappings")]
Task<string> DeleteMappingsAsync();
Task<StatusModel> DeleteMappingsAsync();
/// <summary>
/// Delete (reset) all mappings.
/// </summary>
[Post("__admin/mappings/reset")]
Task<string> ResetMappingsAsync();
Task<StatusModel> ResetMappingsAsync();
/// <summary>
/// Get a mapping based on the guid
@@ -84,20 +84,20 @@ namespace WireMock.Client
/// <param name="guid">The Guid</param>
/// <param name="mapping">MappingModel</param>
[Put("__admin/mappings/{guid}")]
Task<string> PutMappingAsync([Path] Guid guid, [Body] MappingModel mapping);
Task<StatusModel> PutMappingAsync([Path] Guid guid, [Body] MappingModel mapping);
/// <summary>
/// Delete a mapping based on the guid
/// </summary>
/// <param name="guid">The Guid</param>
[Delete("__admin/mappings/{guid}")]
Task<string> DeleteMappingAsync([Path] Guid guid);
Task<StatusModel> DeleteMappingAsync([Path] Guid guid);
/// <summary>
/// Save the mappings
/// </summary>
[Post("__admin/mappings/save")]
Task<string> SaveMappingAsync();
Task<StatusModel> SaveMappingAsync();
/// <summary>
/// Get the requests.
@@ -110,13 +110,13 @@ namespace WireMock.Client
/// Delete all requests.
/// </summary>
[Delete("__admin/requests")]
Task<string> DeleteRequestsAsync();
Task<StatusModel> DeleteRequestsAsync();
/// <summary>
/// Delete (reset) all requests.
/// </summary>
[Post("__admin/requests/reset")]
Task<string> ResetRequestsAsync();
Task<StatusModel> ResetRequestsAsync();
/// <summary>
/// Get a request based on the guid
@@ -131,7 +131,7 @@ namespace WireMock.Client
/// </summary>
/// <param name="guid">The Guid</param>
[Delete("__admin/requests/{guid}")]
Task<string> DeleteRequestAsync([Path] Guid guid);
Task<StatusModel> DeleteRequestAsync([Path] Guid guid);
/// <summary>
/// Find a request based on the criteria
@@ -151,12 +151,12 @@ namespace WireMock.Client
/// Delete (reset) all scenarios
/// </summary>
[Delete("__admin/scenarios")]
Task<string> DeleteScenariosAsync();
Task<StatusModel> DeleteScenariosAsync();
/// <summary>
/// Delete (reset) all scenarios
/// </summary>
[Post("__admin/scenarios")]
Task<string> ResetScenariosAsync();
Task<StatusModel> ResetScenariosAsync();
}
}

View File

@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
namespace WireMock.HttpsCertificate
@@ -10,19 +11,19 @@ namespace WireMock.HttpsCertificate
X509Store certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
try
{
//Certificate must be in the local machine store
// Certificate must be in the local machine store
certStore.Open(OpenFlags.ReadOnly);
//Attempt to find by thumbprint first
// Attempt to find by thumbprint first
var matchingCertificates = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprintOrSubjectName, false);
if (matchingCertificates.Count == 0)
{
//Fallback to subject name
// Fallback to subject name
matchingCertificates = certStore.Certificates.Find(X509FindType.FindBySubjectName, thumbprintOrSubjectName, false);
if (matchingCertificates.Count == 0)
{
// No certificates matched the search criteria.
throw new Exception($"No certificate found with Thumbprint or SubjectName '{thumbprintOrSubjectName}'");
throw new FileNotFoundException("No certificate found with specified Thumbprint or SubjectName.", thumbprintOrSubjectName);
}
}
// Use the first matching certificate.

View File

@@ -49,8 +49,8 @@ namespace WireMock.Logging
/// Writes the LogEntryModel (LogRequestModel, LogResponseModel and more).
/// </summary>
/// <param name="logEntryModel">The Request Log Model.</param>
/// <param name="isAdminrequest">Defines if this request is an admin request.</param>
/// <param name="isAdminRequest">Defines if this request is an admin request.</param>
[PublicAPI]
void DebugRequestResponse([NotNull] LogEntryModel logEntryModel, bool isAdminrequest);
void DebugRequestResponse([NotNull] LogEntryModel logEntryModel, bool isAdminRequest);
}
}

View File

@@ -11,26 +11,31 @@ namespace WireMock.Logging
/// <see cref="IWireMockLogger.Debug"/>
public void Debug(string formatString, params object[] args)
{
// Log nothing
}
/// <see cref="IWireMockLogger.Info"/>
public void Info(string formatString, params object[] args)
{
// Log nothing
}
/// <see cref="IWireMockLogger.Warn"/>
public void Warn(string formatString, params object[] args)
{
// Log nothing
}
/// <see cref="IWireMockLogger.Error"/>
public void Error(string formatString, params object[] args)
{
// Log nothing
}
/// <see cref="IWireMockLogger.DebugRequestResponse"/>
public void DebugRequestResponse(LogEntryModel logEntryModel, bool isAdminRequest)
{
// Log nothing
}
}
}

View File

@@ -7,9 +7,9 @@
public interface IValueMatcher: IObjectMatcher
{
/// <summary>
/// Gets the value.
/// Gets the value (can be a string or an obejct).
/// </summary>
/// <returns>Value</returns>
string GetValue();
object Value { get; }
}
}

View File

@@ -10,7 +10,8 @@ namespace WireMock.Matchers
/// </summary>
public class JsonMatcher : IValueMatcher
{
private readonly string _value;
/// <inheritdoc cref="IValueMatcher.Value"/>
public object Value { get; }
/// <inheritdoc cref="IMatcher.Name"/>
public string Name => "JsonMatcher";
@@ -21,22 +22,43 @@ namespace WireMock.Matchers
/// <summary>
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
/// </summary>
/// <param name="value">The value to check for equality.</param>
/// <param name="value">The string value to check for equality.</param>
public JsonMatcher([NotNull] string value) : this(MatchBehaviour.AcceptOnMatch, value)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
/// </summary>
/// <param name="value">The object value to check for equality.</param>
public JsonMatcher([NotNull] object value) : this(MatchBehaviour.AcceptOnMatch, value)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="JsonMatcher"/> class.
/// </summary>
/// <param name="matchBehaviour">The match behaviour.</param>
/// <param name="value">The value to check for equality.</param>
/// <param name="value">The string value to check for equality.</param>
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] string value)
{
Check.NotNull(value, nameof(value));
MatchBehaviour = matchBehaviour;
_value = value;
Value = value;
}
/// <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>
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value)
{
Check.NotNull(value, nameof(value));
MatchBehaviour = matchBehaviour;
Value = value;
}
/// <inheritdoc cref="IObjectMatcher.IsMatch"/>
@@ -48,9 +70,15 @@ namespace WireMock.Matchers
try
{
// Check if JToken or object
JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
JToken jtokenInput = input is JToken tokenInput ? tokenInput : JObject.FromObject(input);
match = JToken.DeepEquals(JToken.Parse(_value), jtoken);
// Check if JToken or string or object
JToken jtokenValue =
Value is JToken tokenValue ? tokenValue :
Value is string stringValue ? JToken.Parse(stringValue) :
JObject.FromObject(input);
match = JToken.DeepEquals(jtokenValue, jtokenInput);
}
catch (JsonException)
{
@@ -60,8 +88,5 @@ namespace WireMock.Matchers
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(match));
}
/// <inheritdoc cref="IValueMatcher.GetValue"/>
public string GetValue() => _value;
}
}

View File

@@ -25,16 +25,16 @@ namespace WireMock.Matchers.Request
public string Key { get; }
/// <summary>
/// The values
/// The matchers.
/// </summary>
public IEnumerable<string> Values { get; }
public IReadOnlyList<IStringMatcher> Matchers { get; }
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
/// <param name="matchBehaviour">The match behaviour.</param>
/// <param name="key">The key.</param>
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key) : this(matchBehaviour, key, null)
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key) : this(matchBehaviour, key, (IStringMatcher[])null)
{
}
@@ -44,13 +44,23 @@ namespace WireMock.Matchers.Request
/// <param name="matchBehaviour">The match behaviour.</param>
/// <param name="key">The key.</param>
/// <param name="values">The values.</param>
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IEnumerable<string> values)
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] string[] values) : this(matchBehaviour, key, values?.Select(value => new ExactMatcher(matchBehaviour, value)).Cast<IStringMatcher>().ToArray())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
/// <param name="matchBehaviour">The match behaviour.</param>
/// <param name="key">The key.</param>
/// <param name="matchers">The matchers.</param>
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, [CanBeNull] IStringMatcher[] matchers)
{
Check.NotNull(key, nameof(key));
_matchBehaviour = matchBehaviour;
Key = key;
Values = values;
Matchers = matchers;
}
/// <summary>
@@ -78,21 +88,33 @@ namespace WireMock.Matchers.Request
return MatchScores.ToScore(requestMessage.Query != null && Funcs.Any(f => f(requestMessage.Query)));
}
var values = requestMessage.GetParameter(Key);
if (values == null)
WireMockList<string> valuesPresentInRequestMessage = requestMessage.GetParameter(Key);
if (valuesPresentInRequestMessage == null)
{
// Key is not present, just return Mismatch
// Key is not present at all, just return Mismatch
return MatchScores.Mismatch;
}
if (values.Count == 0 && (Values == null || !Values.Any()))
if (Matchers != null && Matchers.Any())
{
// Key is present, but no values or null, just return Perfect
// Matchers are defined, just use the matchers to calculate the match score.
var scores = new List<double>();
foreach (string valuePresentInRequestMessage in valuesPresentInRequestMessage)
{
double score = Matchers.Max(m => m.IsMatch(valuePresentInRequestMessage));
scores.Add(score);
}
return scores.Any() ? scores.Average() : MatchScores.Mismatch;
}
if (Matchers == null || !Matchers.Any())
{
// Matchers are null or not defined, and Key is present, just return Perfect.
return MatchScores.Perfect;
}
var matches = Values.Select(v => values.Contains(v));
return MatchScores.ToScore(matches);
return MatchScores.Mismatch;
}
}
}

View File

@@ -7,11 +7,6 @@ namespace WireMock.Matchers.Request
/// </summary>
internal class RequestMessageScenarioAndStateMatcher : IRequestMatcher
{
///// <summary>
///// Scenario.
///// </summary>
//[CanBeNull] private string _scenario;
/// <summary>
/// Execution state condition for the current mapping.
/// </summary>

View File

@@ -0,0 +1,51 @@
using System;
using WireMock.Validation;
namespace WireMock.Models
{
/// <summary>
/// UrlDetails
/// </summary>
public class UrlDetails
{
/// <summary>
/// Gets the url (relative).
/// </summary>
public Uri Url { get; }
/// <summary>
/// Gets the AbsoluteUrl.
/// </summary>
public Uri AbsoluteUrl { get; }
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="url">The URL.</param>
public UrlDetails(string url) : this(new Uri(url))
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="url">The URL.</param>
public UrlDetails(Uri url) : this(url, url)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="UrlDetails"/> class.
/// </summary>
/// <param name="absoluteUrl">The absolute URL.</param>
/// <param name="url">The URL (relative).</param>
public UrlDetails(Uri absoluteUrl, Uri url)
{
Check.NotNull(absoluteUrl, nameof(absoluteUrl));
Check.NotNull(url, nameof(url));
AbsoluteUrl = absoluteUrl;
Url = url;
}
}
}

View File

@@ -49,7 +49,7 @@ namespace WireMock.Owin
catch (Exception ex)
{
_options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
await _responseMapper.MapAsync(new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) }, ctx.Response);
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
}
}
}

View File

@@ -31,10 +31,10 @@ namespace WireMock.Owin
)
{
#if !NETSTANDARD
Uri url = request.Uri;
var urldetails = UrlUtils.Parse(request.Uri, request.PathBase);
string clientIP = request.RemoteIpAddress;
#else
Uri url = new Uri(request.GetEncodedUrl());
var urldetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
var connection = request.HttpContext.Connection;
string clientIP = connection.RemoteIpAddress.IsIPv4MappedToIPv6
? connection.RemoteIpAddress.MapToIPv4().ToString()
@@ -68,7 +68,7 @@ namespace WireMock.Owin
body = await BodyParser.Parse(request.Body, request.ContentType);
}
return new RequestMessage(url, method, clientIP, body, headers, cookies) { DateTime = DateTime.Now };
return new RequestMessage(urldetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.Now };
}
private bool ShouldParseBody(string method)

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using WireMock.Logging;
using WireMock.Matchers.Request;
@@ -98,7 +99,7 @@ namespace WireMock.Owin
{
logRequest = true;
_options.Logger.Warn("HttpStatusCode set to 404 : No matching mapping found");
response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" };
response = ResponseMessageBuilder.Create("No matching mapping found", 404);
return;
}
@@ -110,7 +111,7 @@ namespace WireMock.Owin
if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect)
{
_options.Logger.Error("HttpStatusCode set to 401");
response = new ResponseMessage { StatusCode = 401 };
response = ResponseMessageBuilder.Create(null, 401);
return;
}
}
@@ -130,7 +131,7 @@ namespace WireMock.Owin
catch (Exception ex)
{
_options.Logger.Error("HttpStatusCode set to 500");
response = new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) };
response = ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500);
}
finally
{

View File

@@ -85,8 +85,8 @@ namespace WireMock.RequestBuilders
/// <summary>
/// WithCookie: matching based on functions.
/// </summary>
/// <param name="cookieFuncs">The funcs.</param>
/// <param name="funcs">The funcs.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithCookie([NotNull] params Func<IDictionary<string, string>, bool>[] cookieFuncs);
IRequestBuilder WithCookie([NotNull] params Func<IDictionary<string, string>, bool>[] funcs);
}
}

View File

@@ -61,7 +61,7 @@ namespace WireMock.RequestBuilders
/// UsingAnyVerb: add HTTP Method matching on any method.
/// </summary>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
[Obsolete]
[Obsolete("Use the method UsingAnyMethod().")]
IRequestBuilder UsingAnyVerb();
/// <summary>
@@ -84,7 +84,7 @@ namespace WireMock.RequestBuilders
/// </summary>
/// <param name="verbs">The methods.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
[Obsolete]
[Obsolete("Use the method UsingMethod(...).")]
IRequestBuilder UsingVerb([NotNull] params string[] verbs);
}
}

View File

@@ -27,6 +27,14 @@ namespace WireMock.RequestBuilders
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params string[] values);
/// <summary>
/// WithParam: matching on key and matchers.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="matchers">The matchers.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithParam([NotNull] string key, [CanBeNull] params IStringMatcher[] matchers);
/// <summary>
/// WithParam: matching on key, values and matchBehaviour.
/// </summary>
@@ -36,6 +44,15 @@ namespace WireMock.RequestBuilders
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour, [CanBeNull] params string[] values);
/// <summary>
/// WithParam: matching on key, matchers and matchBehaviour.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="matchers">The matchers.</param>
/// <param name="matchBehaviour">The match behaviour.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithParam([NotNull] string key, MatchBehaviour matchBehaviour, [CanBeNull] params IStringMatcher[] matchers);
/// <summary>
/// WithParam: matching on functions.
/// </summary>

View File

@@ -63,8 +63,8 @@ namespace WireMock.RequestBuilders
/// <summary>
/// WithUrl: add url matching based on functions.
/// </summary>
/// <param name="func">The path func.</param>
/// <param name="funcs">The url functions.</param>
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
IRequestBuilder WithUrl([NotNull] params Func<string, bool>[] func);
IRequestBuilder WithUrl([NotNull] params Func<string, bool>[] funcs);
}
}

View File

@@ -306,6 +306,12 @@ namespace WireMock.RequestBuilders
return WithParam(key, MatchBehaviour.AcceptOnMatch, values);
}
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, IStringMatcher[])"/>
public IRequestBuilder WithParam(string key, params IStringMatcher[] matchers)
{
return WithParam(key, MatchBehaviour.AcceptOnMatch, matchers);
}
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, string[])"/>
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, params string[] values)
{
@@ -315,6 +321,15 @@ namespace WireMock.RequestBuilders
return this;
}
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, IStringMatcher[])"/>
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers)
{
Check.NotNull(key, nameof(key));
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, matchers));
return this;
}
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(Func{IDictionary{string, WireMockList{string}}, bool}[])"/>
public IRequestBuilder WithParam(params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
{

View File

@@ -4,13 +4,14 @@ using System.Linq;
using System.Text;
using System.Net;
using JetBrains.Annotations;
using WireMock.Models;
using WireMock.Util;
using WireMock.Validation;
namespace WireMock
{
/// <summary>
/// The request.
/// The RequestMessage.
/// </summary>
public class RequestMessage
{
@@ -20,25 +21,40 @@ namespace WireMock
public string ClientIP { get; }
/// <summary>
/// Gets the url.
/// Gets the url (relative).
/// </summary>
public string Url { get; }
/// <summary>
/// Gets the AbsoluteUrl.
/// </summary>
public string AbsoluteUrl { get; }
/// <summary>
/// Gets the DateTime.
/// </summary>
public DateTime DateTime { get; set; }
/// <summary>
/// Gets the path.
/// Gets the path (relative).
/// </summary>
public string Path { get; }
/// <summary>
/// Gets the AbsolutePath.
/// </summary>
public string AbsolutePath { get; }
/// <summary>
/// Gets the path segments.
/// </summary>
public string[] PathSegments { get; }
/// <summary>
/// Gets the absolute path segments.
/// </summary>
public string[] AbsolutePathSegments { get; }
/// <summary>
/// Gets the method.
/// </summary>
@@ -107,25 +123,30 @@ namespace WireMock
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessage"/> class.
/// </summary>
/// <param name="url">The original url.</param>
/// <param name="urlDetails">The original url details.</param>
/// <param name="method">The HTTP method.</param>
/// <param name="clientIP">The client IP Address.</param>
/// <param name="body">The body.</param>
/// <param name="headers">The headers.</param>
/// <param name="cookies">The cookies.</param>
public RequestMessage([NotNull] Uri url, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] BodyData body = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
public RequestMessage([NotNull] UrlDetails urlDetails, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] BodyData body = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
{
Check.NotNull(url, nameof(url));
Check.NotNull(urlDetails, nameof(urlDetails));
Check.NotNull(method, nameof(method));
Check.NotNull(clientIP, nameof(clientIP));
Url = url.ToString();
Protocol = url.Scheme;
Host = url.Host;
Port = url.Port;
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
Path = WebUtility.UrlDecode(url.AbsolutePath);
AbsoluteUrl = urlDetails.AbsoluteUrl.ToString();
Url = urlDetails.Url.ToString();
Protocol = urlDetails.Url.Scheme;
Host = urlDetails.Url.Host;
Port = urlDetails.Url.Port;
Origin = $"{Protocol}://{Host}:{Port}";
AbsolutePath = WebUtility.UrlDecode(urlDetails.AbsoluteUrl.AbsolutePath);
Path = WebUtility.UrlDecode(urlDetails.Url.AbsolutePath);
PathSegments = Path.Split('/').Skip(1).ToArray();
AbsolutePathSegments = AbsolutePath.Split('/').Skip(1).ToArray();
Method = method.ToLower();
ClientIP = clientIP;
@@ -136,7 +157,7 @@ namespace WireMock
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
Cookies = cookies;
RawQuery = WebUtility.UrlDecode(url.Query);
RawQuery = WebUtility.UrlDecode(urlDetails.Url.Query);
Query = ParseQuery(RawQuery);
}

View File

@@ -59,7 +59,7 @@ namespace WireMock.ResponseBuilders
/// <param name="bodyAsbase64">The body.</param>
/// <param name="encoding">The Encoding.</param>
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
[Obsolete]
[Obsolete("Should not be used, will be removed in future.")]
IResponseBuilder WithBodyFromBase64([NotNull] string bodyAsbase64, [CanBeNull] Encoding encoding = null);
/// <summary>

View File

@@ -173,7 +173,7 @@ namespace WireMock.ResponseBuilders
}
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(byte[], string, Encoding)"/>
public IResponseBuilder WithBody(byte[] body, string destination, Encoding encoding = null)
public IResponseBuilder WithBody(byte[] body, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
{
Check.NotNull(body, nameof(body));

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using WireMock.Admin.Mappings;
using WireMock.Http;
using WireMock.Util;
namespace WireMock
{
internal static class ResponseMessageBuilder
{
private static string ContentTypeJson = "application/json";
private static readonly IDictionary<string, WireMockList<string>> ContentTypeJsonHeaders = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string> { ContentTypeJson } } };
internal static ResponseMessage Create(string message, int statusCode = 200, Guid? guid = null)
{
var response = new ResponseMessage
{
StatusCode = statusCode,
Headers = ContentTypeJsonHeaders,
BodyAsJson = message != null ? new StatusModel { Status = message, Guid = guid } : null
};
return response;
}
}
}

View File

@@ -17,7 +17,9 @@ namespace WireMock.Serialization
DateTime = logEntry.RequestMessage.DateTime,
ClientIP = logEntry.RequestMessage.ClientIP,
Path = logEntry.RequestMessage.Path,
AbsoluteUrl = logEntry.RequestMessage.Url,
AbsolutePath = logEntry.RequestMessage.AbsolutePath,
Url = logEntry.RequestMessage.Url,
AbsoluteUrl = logEntry.RequestMessage.AbsoluteUrl,
Query = logEntry.RequestMessage.Query,
Method = logEntry.RequestMessage.Method,
Body = logEntry.RequestMessage.Body,

View File

@@ -71,7 +71,7 @@ namespace WireMock.Serialization
Params = paramsMatchers != null && paramsMatchers.Any() ? paramsMatchers.Select(pm => new ParamModel
{
Name = pm.Key,
Values = pm.Values?.ToList()
Matchers = MatcherMapper.Map(pm.Matchers)
//Funcs = Map(pm.Funcs)
}).ToList() : null,
@@ -146,15 +146,5 @@ namespace WireMock.Serialization
return newDictionary;
}
//private static string[] Map<T>([CanBeNull] IEnumerable<Func<T, bool>> funcs)
//{
// return funcs?.Select(Map).Where(x => x != null).ToArray();
//}
//private static string Map<T>([CanBeNull] Func<T, bool> func)
//{
// return func?.ToString();
//}
}
}

View File

@@ -21,28 +21,28 @@ namespace WireMock.Serialization
string matcherName = parts[0];
string matcherType = parts.Length > 1 ? parts[1] : null;
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
string[] stringPatterns = matcher.Patterns != null ? matcher.Patterns.Cast<string>().ToArray() : new [] { matcher.Pattern as string };
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
switch (matcherName)
{
case "ExactMatcher":
return new ExactMatcher(matchBehaviour, patterns);
return new ExactMatcher(matchBehaviour, stringPatterns);
case "RegexMatcher":
return new RegexMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
return new RegexMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
case "JsonMatcher":
return new JsonMatcher(matchBehaviour, matcher.Pattern);
case "JsonPathMatcher":
return new JsonPathMatcher(matchBehaviour, patterns);
return new JsonPathMatcher(matchBehaviour, stringPatterns);
case "XPathMatcher":
return new XPathMatcher(matchBehaviour, matcher.Pattern);
return new XPathMatcher(matchBehaviour, (string) matcher.Pattern);
case "WildcardMatcher":
return new WildcardMatcher(matchBehaviour, patterns, matcher.IgnoreCase == true);
return new WildcardMatcher(matchBehaviour, stringPatterns, matcher.IgnoreCase == true);
case "SimMetricsMatcher":
SimMetricType type = SimMetricType.Levenstein;
@@ -51,7 +51,7 @@ namespace WireMock.Serialization
throw new NotSupportedException($"Matcher '{matcherName}' with Type '{matcherType}' is not supported.");
}
return new SimMetricsMatcher(matchBehaviour, matcher.Pattern, type);
return new SimMetricsMatcher(matchBehaviour, (string) matcher.Pattern, type);
default:
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
@@ -70,9 +70,13 @@ namespace WireMock.Serialization
return null;
}
string[] patterns = matcher is IStringMatcher stringMatcher ?
stringMatcher.GetPatterns() :
matcher is IValueMatcher valueMatcher ? new[] { valueMatcher.GetValue() } : new string[0];
// If the matcher is a IStringMatcher, get the patterns.
// If the matcher is a IValueMatcher, get the value (can be string or object).
// Else empty array
object[] patterns = matcher is IStringMatcher stringMatcher ?
stringMatcher.GetPatterns().Cast<object>().ToArray() :
matcher is IValueMatcher valueMatcher ? new[] { valueMatcher.Value } :
new object[0];
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
bool? rejectOnMatch = matcher.MatchBehaviour == MatchBehaviour.RejectOnMatch ? true : (bool?)null;

View File

@@ -238,7 +238,11 @@ namespace WireMock.Server
}
});
if (requestMessage.Body != null)
if (requestMessage.BodyAsJson != null)
{
request.WithBody(new JsonMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.BodyAsJson));
}
else if (requestMessage.Body != null)
{
request.WithBody(new ExactMatcher(MatchBehaviour.AcceptOnMatch, requestMessage.Body));
}
@@ -279,7 +283,7 @@ namespace WireMock.Server
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
}
return new ResponseMessage { Body = "Settings updated" };
return ResponseMessageBuilder.Create("Settings updated");
}
#endregion Settings
@@ -292,7 +296,7 @@ namespace WireMock.Server
if (mapping == null)
{
_logger.Warn("HttpStatusCode set to 404 : Mapping not found");
return new ResponseMessage { StatusCode = 404, Body = "Mapping not found" };
return ResponseMessageBuilder.Create("Mapping not found", 404);
}
var model = MappingConverter.ToMappingModel(mapping);
@@ -307,7 +311,7 @@ namespace WireMock.Server
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
DeserializeAndAddOrUpdateMapping(mappingModel, guid);
return new ResponseMessage { Body = "Mapping added or updated" };
return ResponseMessageBuilder.Create("Mapping added or updated", 200, guid);
}
private ResponseMessage MappingDelete(RequestMessage requestMessage)
@@ -316,10 +320,10 @@ namespace WireMock.Server
if (DeleteMapping(guid))
{
return new ResponseMessage { Body = "Mapping removed" };
return ResponseMessageBuilder.Create("Mapping removed", 200, guid);
}
return new ResponseMessage { Body = "Mapping not found" };
return ResponseMessageBuilder.Create("Mapping not found", 404);
}
#endregion Mapping/{guid}
@@ -331,7 +335,7 @@ namespace WireMock.Server
SaveMappingToFile(mapping);
}
return new ResponseMessage { Body = "Mappings saved to disk" };
return ResponseMessageBuilder.Create("Mappings saved to disk");
}
private void SaveMappingToFile(Mapping mapping)
@@ -370,26 +374,27 @@ namespace WireMock.Server
private ResponseMessage MappingsPost(RequestMessage requestMessage)
{
Guid? guid;
try
{
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
DeserializeAndAddOrUpdateMapping(mappingModel);
guid = DeserializeAndAddOrUpdateMapping(mappingModel);
}
catch (ArgumentException a)
{
_logger.Error("HttpStatusCode set to 400 {0}", a);
return new ResponseMessage { StatusCode = 400, Body = a.Message };
return ResponseMessageBuilder.Create(a.Message, 400);
}
catch (Exception e)
{
_logger.Error("HttpStatusCode set to 500 {0}", e);
return new ResponseMessage { StatusCode = 500, Body = e.ToString() };
return ResponseMessageBuilder.Create(e.ToString(), 500);
}
return new ResponseMessage { StatusCode = 201, Body = "Mapping added" };
return ResponseMessageBuilder.Create("Mapping added", 201, guid);
}
private void DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
private Guid DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
{
Check.NotNull(mappingModel, nameof(mappingModel));
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
@@ -398,7 +403,7 @@ namespace WireMock.Server
var requestBuilder = InitRequestBuilder(mappingModel.Request);
var responseBuilder = InitResponseBuilder(mappingModel.Response);
IRespondWithAProvider respondProvider = Given(requestBuilder);
var respondProvider = Given(requestBuilder);
if (guid != null)
{
@@ -432,6 +437,8 @@ namespace WireMock.Server
}
respondProvider.RespondWith(responseBuilder);
return respondProvider.Guid;
}
private ResponseMessage MappingsDelete(RequestMessage requestMessage)
@@ -440,7 +447,7 @@ namespace WireMock.Server
ResetScenarios();
return new ResponseMessage { Body = "Mappings deleted" };
return ResponseMessageBuilder.Create("Mappings deleted");
}
#endregion Mappings
@@ -453,7 +460,7 @@ namespace WireMock.Server
if (entry == null)
{
_logger.Warn("HttpStatusCode set to 404 : Request not found");
return new ResponseMessage { StatusCode = 404, Body = "Request not found" };
return ResponseMessageBuilder.Create("Request not found", 404);
}
var model = LogEntryMapper.Map(entry);
@@ -466,9 +473,11 @@ namespace WireMock.Server
Guid guid = Guid.Parse(requestMessage.Path.Substring(AdminRequests.Length + 1));
if (DeleteLogEntry(guid))
return new ResponseMessage { Body = "Request removed" };
{
return ResponseMessageBuilder.Create("Request removed");
}
return new ResponseMessage { Body = "Request not found" };
return ResponseMessageBuilder.Create("Request not found", 404);
}
#endregion Request/{guid}
@@ -486,7 +495,7 @@ namespace WireMock.Server
{
ResetLogEntries();
return new ResponseMessage { Body = "Requests deleted" };
return ResponseMessageBuilder.Create("Requests deleted");
}
#endregion Requests
@@ -529,7 +538,7 @@ namespace WireMock.Server
{
ResetScenarios();
return new ResponseMessage { Body = "Scenarios reset" };
return ResponseMessageBuilder.Create("Scenarios reset");
}
#endregion
@@ -608,9 +617,9 @@ namespace WireMock.Server
if (requestModel.Params != null)
{
foreach (var paramModel in requestModel.Params)
foreach (var paramModel in requestModel.Params.Where(c => c.Matchers != null))
{
requestBuilder = paramModel.Values == null ? requestBuilder.WithParam(paramModel.Name) : requestBuilder.WithParam(paramModel.Name, paramModel.Values.ToArray());
requestBuilder = requestBuilder.WithParam(paramModel.Name, paramModel.Matchers.Select(MatcherMapper.Map).Cast<IStringMatcher>().ToArray());
}
}

View File

@@ -56,7 +56,30 @@ namespace WireMock.Server
/// Gets the scenarios.
/// </summary>
[PublicAPI]
public ConcurrentDictionary<string, object> Scenarios => new ConcurrentDictionary<string, object>(_options.Scenarios); // Checked
public ConcurrentDictionary<string, object> Scenarios => new ConcurrentDictionary<string, object>(_options.Scenarios);
#region IDisposable Members
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
if (_httpServer != null && _httpServer.IsStarted)
{
_httpServer.StopAsync();
}
}
#endregion
#region Start/Stop
/// <summary>
@@ -250,8 +273,7 @@ namespace WireMock.Server
public void Stop()
{
var result = _httpServer?.StopAsync();
if (result != null)
result.Wait(); //wait for stop to actually happen
result?.Wait(); // wait for stop to actually happen
}
#endregion
@@ -264,18 +286,7 @@ namespace WireMock.Server
Given(Request.Create().WithPath("/*").UsingAnyMethod())
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
.AtPriority(1000)
.RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }));
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (_httpServer != null && _httpServer.IsStarted)
{
_httpServer.StopAsync();
}
.RespondWith(new DynamicResponseProvider(request => ResponseMessageBuilder.Create("No matching mapping found", 404)));
}
/// <summary>

View File

@@ -8,6 +8,11 @@ namespace WireMock.Server
/// </summary>
public interface IRespondWithAProvider
{
/// <summary>
/// Gets the unique identifier for this mapping.
/// </summary>
Guid Guid { get; }
/// <summary>
/// Define a unique identifier for this mapping.
/// </summary>

View File

@@ -10,7 +10,6 @@ namespace WireMock.Server
internal class RespondWithAProvider : IRespondWithAProvider
{
private int _priority;
private Guid? _guid;
private string _title;
private string _path;
private object _executionConditionState;
@@ -19,6 +18,8 @@ namespace WireMock.Server
private readonly RegistrationCallback _registrationCallback;
private readonly IRequestMatcher _requestMatcher;
public Guid Guid { get; private set; } = Guid.NewGuid();
/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
@@ -36,8 +37,7 @@ namespace WireMock.Server
/// <param name="provider">The provider.</param>
public void RespondWith(IResponseProvider provider)
{
var mappingGuid = _guid ?? Guid.NewGuid();
_registrationCallback(new Mapping(mappingGuid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
_registrationCallback(new Mapping(Guid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
}
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
@@ -49,7 +49,7 @@ namespace WireMock.Server
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
public IRespondWithAProvider WithGuid(Guid guid)
{
_guid = guid;
Guid = guid;
return this;
}

View File

@@ -9,9 +9,8 @@ namespace WireMock.Util
/// <summary>
/// An EnhancedFileSystemWatcher, which can be used to suppress duplicate events that fire on a single change to the file.
/// </summary>
/// <seealso cref="System.IO.FileSystemWatcher" />
/// <seealso cref="System.IDisposable" />
public class EnhancedFileSystemWatcher : FileSystemWatcher, IDisposable
/// <seealso cref="FileSystemWatcher" />
public class EnhancedFileSystemWatcher : FileSystemWatcher
{
#region Private Members
// Default Watch Interval in Milliseconds
@@ -251,15 +250,5 @@ namespace WireMock.Util
}
#endregion
#endregion
#region IDisposable Members
/// <summary>
/// Releases all resources used by the <see cref="T:System.ComponentModel.Component" />.
/// </summary>
public new void Dispose()
{
base.Dispose();
}
#endregion
}
}

View File

@@ -0,0 +1,38 @@
using System;
using JetBrains.Annotations;
using WireMock.Models;
#if !NETSTANDARD
using Microsoft.Owin;
#else
using Microsoft.AspNetCore.Http;
#endif
namespace WireMock.Util
{
internal static class UrlUtils
{
public static UrlDetails Parse([NotNull] Uri uri, PathString pathBase)
{
if (!pathBase.HasValue)
{
return new UrlDetails(uri, uri);
}
var builder = new UriBuilder(uri);
builder.Path = RemoveFirst(builder.Path, pathBase.Value);
return new UrlDetails(uri, builder.Uri);
}
private static string RemoveFirst(string text, string search)
{
int pos = text.IndexOf(search);
if (pos < 0)
{
return text;
}
return text.Substring(0, pos) + text.Substring(pos + search.Length);
}
}
}

View File

@@ -38,10 +38,7 @@ namespace WireMock.Util
/// </summary>
public override string ToString()
{
if (this != null && this.Any())
return this.First().ToString();
return base.ToString();
return this.Any() ? this.First().ToString() : base.ToString();
}
}
}

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.4.1</Version>
<Version>1.0.4.5</Version>
<Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -21,6 +21,7 @@
<DebugType>full</DebugType>
<IncludeSource>True</IncludeSource>
<IncludeSymbols>True</IncludeSymbols>
<ProjectGuid>{D3804228-91F4-4502-9595-39584E5A01AD}</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">

View File

@@ -33,10 +33,12 @@ namespace WireMock.Net.Tests
Priority = 500,
Title = "test"
};
string result = await api.PostMappingAsync(model);
var result = await api.PostMappingAsync(model);
// Assert
Check.That(result).IsNotNull();
Check.That(result.Status).IsNotNull();
Check.That(result.Guid).IsNotNull();
var mapping = server.Mappings.Single(m => m.Priority == 500);
Check.That(mapping).IsNotNull();

View File

@@ -88,7 +88,7 @@ namespace WireMock.Net.Tests
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
string json = File.ReadAllText(folder);
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "ResponseBodyFiles", "responsebody.json");
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "responsebody.json");
dynamic jsonObj = JsonConvert.DeserializeObject(json);
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using NFluent;
using WireMock.Http;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsBytes = Encoding.UTF8.GetBytes("hi")
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -55,7 +56,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsJson = new { x = 42 }
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -73,7 +74,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsJson = new { x = 42 }
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -92,7 +93,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -110,7 +111,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
@@ -128,7 +129,7 @@ namespace WireMock.Net.Tests.Http
{
BodyAsString = "<xml>hello</xml>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, headers);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");

View File

@@ -27,7 +27,7 @@ namespace WireMock.Net.Tests.Matchers
var matcher = new JsonMatcher("{}");
// Act
string value = matcher.GetValue();
object value = matcher.Value;
// Assert
Check.That(value).Equals("{}");
@@ -62,7 +62,39 @@ namespace WireMock.Net.Tests.Matchers
}
[Fact]
public void JsonMatcher_IsMatch_JObject()
public void JsonMatcher_IsMatch_JObject1()
{
// Assign
var matcher = new JsonMatcher(new { Id = 1, Name = "test" });
// Act
var jobject = new JObject
{
{ "Id", new JValue(1) },
{ "Name", new JValue("Test") }
};
double match = matcher.IsMatch(jobject);
// Assert
Assert.Equal(1.0, match);
}
[Fact]
public void JsonMatcher_IsMatch_JObject2()
{
// Assign
var matcher = new JsonMatcher(new { Id = 1, Name = "test" });
// Act
var jobject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
double match = matcher.IsMatch(jobject);
// Assert
Assert.Equal(1.0, match);
}
[Fact]
public void JsonMatcher_IsMatch_JObjectAsString()
{
// Assign
var matcher = new JsonMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
@@ -80,7 +112,7 @@ namespace WireMock.Net.Tests.Matchers
}
[Fact]
public void JsonMatcher_IsMatch_JObject_RejectOnMatch()
public void JsonMatcher_IsMatch_JObjectAsString_RejectOnMatch()
{
// Assign
var matcher = new JsonMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -18,7 +19,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyMethod().WithCookie("session", "a*");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, null, null, new Dictionary<string, string> { { "session", "abc" } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, null, new Dictionary<string, string> { { "session", "abc" } });
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -3,6 +3,7 @@ using Moq;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -48,7 +49,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -102,7 +103,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var stringMatcherMock = new Mock<IStringMatcher>();
stringMatcherMock.Setup(m => m.IsMatch(It.IsAny<string>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
@@ -128,7 +129,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var objectMatcherMock = new Mock<IObjectMatcher>();
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
@@ -154,7 +155,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var objectMatcherMock = new Mock<IObjectMatcher>();
objectMatcherMock.Setup(m => m.IsMatch(It.IsAny<object>())).Returns(0.5d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", body);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", body);
var matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Moq;
using NFluent;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCompositeMatcher_GetMatchingScore_EmptyArray()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(Enumerable.Empty<IRequestMatcher>());
// Act
@@ -41,7 +42,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var requestMatcher2Mock = new Mock<IRequestMatcher>();
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object });
// Act
@@ -65,7 +66,7 @@ namespace WireMock.Net.Tests.RequestMatchers
var requestMatcher2Mock = new Mock<IRequestMatcher>();
requestMatcher2Mock.Setup(rm => rm.GetMatchingScore(It.IsAny<RequestMessage>(), It.IsAny<RequestMatchResult>())).Returns(0.8d);
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new Helper(new[] { requestMatcher1Mock.Object, requestMatcher2Mock.Object }, CompositeMatcherType.Or);
// Act

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCookieMatcher_GetMatchingScore_AcceptOnMatch_CookieDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "c", "x");
// Act
@@ -28,7 +29,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageCookieMatcher_GetMatchingScore_RejectOnMatch_CookieDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "c", "x");
// Act
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "c", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123");
// Act
@@ -59,7 +60,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123");
// Act
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, "h", "x");
// Act
@@ -91,7 +92,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "h", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(MatchBehaviour.RejectOnMatch, "h", "x");
// Act
@@ -107,7 +108,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "cook", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher("cook", new ExactMatcher("x"));
// Act
@@ -123,7 +124,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var cookies = new Dictionary<string, string> { { "cook", "x" } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, null, cookies);
var matcher = new RequestMessageCookieMatcher(x => x.ContainsKey("cook"));
// Act

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageHeaderMatcher_GetMatchingScore_AcceptOnMatch_HeaderDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
// Act
@@ -28,7 +29,7 @@ namespace WireMock.Net.Tests.RequestMatchers
public void RequestMessageHeaderMatcher_GetMatchingScore_RejectOnMatch_HeaderDoesNotExists()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1");
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
// Act
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "no-match", "123", true);
// Act
@@ -59,7 +60,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "no-match", "123", true);
// Act
@@ -75,7 +76,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, "h", "x", true);
// Act
@@ -91,7 +92,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(MatchBehaviour.RejectOnMatch, "h", "x", true);
// Act
@@ -107,7 +108,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher("h", new ExactMatcher("x"));
// Act
@@ -123,7 +124,7 @@ namespace WireMock.Net.Tests.RequestMatchers
{
// Assign
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var requestMessage = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.1", null, headers);
var requestMessage = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.1", null, headers);
var matcher = new RequestMessageHeaderMatcher(x => x.ContainsKey("h"));
// Act

View File

@@ -2,6 +2,7 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers
@@ -9,10 +10,10 @@ namespace WireMock.Net.Tests.RequestMatchers
public class RequestMessageParamMatcherTests
{
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_AllMatch()
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchExactOnStringValues()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -24,10 +25,25 @@ namespace WireMock.Net.Tests.RequestMatchers
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_PartialMatch()
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchExactOnExactMatchers()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new IStringMatcher[] { new ExactMatcher("test1"), new ExactMatcher("test2") });
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
Check.That(score).IsEqualTo(1.0d);
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuesPresentInUrl_MatchOnKeyWithValues_PartialMatch()
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test0,test2"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -39,10 +55,10 @@ namespace WireMock.Net.Tests.RequestMatchers
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent()
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithValues_Fails()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new[] { "test1", "test2" });
// Act
@@ -54,10 +70,10 @@ namespace WireMock.Net.Tests.RequestMatchers
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent_WithNull()
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKey()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
// Act
@@ -69,10 +85,10 @@ namespace WireMock.Net.Tests.RequestMatchers
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresent_WithEmptyArray()
public void RequestMessageParamMatcher_GetMatchingScore_OnlyKeyPresentInUrl_MatchOnKeyWithEmptyArray()
{
// Assign
var requestMessage = new RequestMessage(new Uri("http://localhost?key"), "GET", "127.0.0.1");
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key", new string[] { });
// Act
@@ -82,5 +98,20 @@ namespace WireMock.Net.Tests.RequestMatchers
// Assert
Check.That(score).IsEqualTo(1.0d);
}
[Fact]
public void RequestMessageParamMatcher_GetMatchingScore_KeyWithValuePresentInUrl_MatchOnKey()
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=frank@contoso.com"), "GET", "127.0.0.1");
var matcher = new RequestMessageParamMatcher(MatchBehaviour.AcceptOnMatch, "key");
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
Check.That(score).IsEqualTo(1.0d);
}
}
}

View File

@@ -1,5 +1,6 @@
using System;
using NFluent;
using WireMock.Models;
using WireMock.Util;
using Xunit;
@@ -13,7 +14,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_NoKeys()
{
// given
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
// then
Check.That(request.GetParameter("not_there")).IsNull();
@@ -23,7 +24,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_SingleKey_SingleValue()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?foo=bar"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?foo=bar"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("foo")).ContainsExactly("bar");
@@ -33,7 +34,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_MultipleKeys_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?key=1&key=2"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?key=1&key=2"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("key")).Contains("1");
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_ParseQuery_SingleKey_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost?key=1,2&foo=bar&key=3"), "POST", ClientIp);
// Assert
Check.That(request.GetParameter("key")).Contains("1");
@@ -56,7 +57,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_Constructor1_PathSegments()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp);
// Assert
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
@@ -66,7 +67,7 @@ namespace WireMock.Net.Tests
public void RequestMessage_Constructor2_PathSegments()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
var request = new RequestMessage(new UrlDetails("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
// Assert
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");

View File

@@ -5,6 +5,7 @@ using NFluent;
using Xunit;
using WireMock.RequestBuilders;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
namespace WireMock.Net.Tests
@@ -20,7 +21,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/bar").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -56,7 +57,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "ABC" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -74,7 +75,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "TaTa" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -92,7 +93,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "Hello world!"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -110,7 +111,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "xxx"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -124,7 +125,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithParam("bar", "1", "2");
// when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -138,7 +139,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().UsingAnyMethod().WithParam(p => p.ContainsKey("bar"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?bar=1&bar=2"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -152,7 +153,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithParam("bar", "1");
// when
var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/test=7"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -4,6 +4,7 @@ using Newtonsoft.Json;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using WireMock.Util;
using Xunit;
@@ -25,7 +26,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "b"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -43,7 +44,7 @@ namespace WireMock.Net.Tests
{
BodyAsJson = 123
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -61,7 +62,7 @@ namespace WireMock.Net.Tests
{
BodyAsBytes = new byte[0]
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -79,7 +80,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "cat"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -97,7 +98,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "Hello world!"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -120,7 +121,7 @@ namespace WireMock.Net.Tests
<todo-item id='a3'>xyz</todo-item>
</todo-list>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -143,7 +144,7 @@ namespace WireMock.Net.Tests
<todo-item id='a3'>xyz</todo-item>
</todo-list>"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -161,7 +162,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -179,7 +180,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "{ \"things\": { \"name\": \"Wiremock\" } }"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -201,7 +202,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -223,7 +224,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -245,7 +246,7 @@ namespace WireMock.Net.Tests
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// then
var requestMatchResult = new RequestMatchResult();
@@ -266,7 +267,7 @@ namespace WireMock.Net.Tests
};
// Act
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// Assert
var requestMatchResult = new RequestMatchResult();
@@ -286,7 +287,7 @@ namespace WireMock.Net.Tests
};
// Act
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, bodyData);
// Assert
var requestMatchResult = new RequestMatchResult();

View File

@@ -2,6 +2,7 @@ using System;
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP("127.0.0.2", "1.1.1.1");
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();
@@ -30,7 +31,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP("127.0.0.2");
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "192.1.1.1");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "192.1.1.1");
// then
var requestMatchResult = new RequestMatchResult();
@@ -44,7 +45,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP(new WildcardMatcher("127.0.0.2"));
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();
@@ -58,7 +59,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithClientIP(c => c.Contains("."));
// when
var request = new RequestMessage(new Uri("http://localhost"), "GET", "127.0.0.2");
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", "127.0.0.2");
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -5,6 +5,7 @@ using WireMock.Matchers;
using Xunit;
using WireMock.RequestBuilders;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Util;
namespace WireMock.Net.Tests
@@ -24,7 +25,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, body, new Dictionary<string, string[]> { { "X-toto", new[] { "tata" } } });
// then
var requestMatchResult = new RequestMatchResult();
@@ -38,7 +39,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -50,8 +51,8 @@ namespace WireMock.Net.Tests
{
var requestBuilder = Request.Create().WithPath("/x1", "/x2");
var request1 = new RequestMessage(new Uri("http://localhost/x1"), "blabla", ClientIp);
var request2 = new RequestMessage(new Uri("http://localhost/x2"), "blabla", ClientIp);
var request1 = new RequestMessage(new UrlDetails("http://localhost/x1"), "blabla", ClientIp);
var request2 = new RequestMessage(new UrlDetails("http://localhost/x2"), "blabla", ClientIp);
var requestMatchResult = new RequestMatchResult();
Check.That(requestBuilder.GetMatchingScore(request1, requestMatchResult)).IsEqualTo(1.0);
@@ -65,7 +66,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath(url => url.EndsWith("/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -79,7 +80,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath(new RegexMatcher("^/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo/bar"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -93,7 +94,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/bar"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -111,7 +112,7 @@ namespace WireMock.Net.Tests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "Delete", ClientIp, body);
// then
var requestMatchResult = new RequestMatchResult();
@@ -125,7 +126,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingGet();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "GET", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -139,7 +140,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingHead();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -153,7 +154,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPost();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -167,7 +168,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -181,7 +182,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPatch();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "PATCH", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PATCH", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -195,7 +196,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithPath("/foo").UsingPut();
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "HEAD", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -2,6 +2,7 @@
using NFluent;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.RequestBuilders;
using Xunit;
@@ -18,7 +19,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl("*/foo");
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -32,7 +33,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl(new WildcardMatcher("*/foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();
@@ -46,7 +47,7 @@ namespace WireMock.Net.Tests
var spec = Request.Create().WithUrl(url => url.Contains("foo"));
// when
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "blabla", ClientIp);
// then
var requestMatchResult = new RequestMatchResult();

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
@@ -15,7 +16,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
// Assign
var responseMessage = new ResponseMessage { StatusCode = 500 };
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create(() => responseMessage);

View File

@@ -2,6 +2,7 @@
using System.Text;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
@@ -20,7 +21,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.String, Encoding.ASCII);
@@ -41,7 +42,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody(new byte[] { 48, 49 }, BodyDestinationFormat.SameAsSource, Encoding.ASCII);
@@ -62,7 +63,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create().WithBody("test", null, Encoding.ASCII);
@@ -82,7 +83,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
object x = new { value = "test" };
var response = Response.Create().WithBodyAsJson(x, Encoding.ASCII);
@@ -100,7 +101,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_SameAsSource_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("r", BodyDestinationFormat.SameAsSource, Encoding.ASCII);
@@ -118,7 +119,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_Bytes_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("r", BodyDestinationFormat.Bytes, Encoding.ASCII);
@@ -136,7 +137,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithBody_String_Json_Encoding()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var response = Response.Create().WithBody("{ \"value\": 42 }", BodyDestinationFormat.Json, Encoding.ASCII);

View File

@@ -2,15 +2,17 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Newtonsoft.Json;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.ResponseBuilderTests
{
public class ResponseWithBodyHandlebarsTests
public class ResponseWithHandlebarsTests
{
private const string ClientIp = "::1";
@@ -24,7 +26,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
BodyAsJson = JsonConvert.DeserializeObject(jsonString),
Encoding = Encoding.UTF8
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, bodyData);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData);
var response = Response.Create()
.WithBodyAsJson(new { x = "test {{request.url}}" })
@@ -45,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "whatever"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test {{request.url}} {{request.path}} {{request.method}}")
@@ -58,6 +60,42 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
Check.That(responseMessage.Body).Equals("test http://localhost/foo /foo post");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_UrlPath()
{
// given
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
var request = new RequestMessage(urlDetails, "POST", ClientIp);
var response = Response.Create()
.WithBody("{{request.url}} {{request.absoluteurl}} {{request.path}} {{request.absolutepath}}")
.WithTransformer();
// act
var responseMessage = await response.ProvideResponseAsync(request);
// then
Check.That(responseMessage.Body).Equals("http://localhost/a/b http://localhost/wiremock/a/b /a/b /wiremock/a/b");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_PathSegments()
{
// given
var urlDetails = UrlUtils.Parse(new Uri("http://localhost/wiremock/a/b"), new PathString("/wiremock"));
var request = new RequestMessage(urlDetails, "POST", ClientIp);
var response = Response.Create()
.WithBody("{{request.pathsegments.[0]}} {{request.absolutepathsegments.[0]}}")
.WithTransformer();
// act
var responseMessage = await response.ProvideResponseAsync(request);
// then
Check.That(responseMessage.Body).Equals("a wiremock");
}
[Fact]
public async Task Response_ProvideResponse_Handlebars_Query()
{
@@ -66,7 +104,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost/foo?a=1&a=2&b=5"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test keya={{request.query.a}} idx={{request.query.a.[0]}} idx={{request.query.a.[1]}} keyb={{request.query.b}}")
@@ -87,7 +125,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}").WithBody("test").WithTransformer();
@@ -108,7 +146,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, body, new Dictionary<string, string[]> { { "Content-Type", new[] { "text/plain" } } });
var response = Response.Create().WithHeader("x", "{{request.headers.Content-Type}}", "{{request.url}}").WithBody("test").WithTransformer();
@@ -130,7 +168,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
{
BodyAsString = "abc"
};
var request = new RequestMessage(new Uri("http://localhost:1234"), "POST", ClientIp, body);
var request = new RequestMessage(new UrlDetails("http://localhost:1234"), "POST", ClientIp, body);
var response = Response.Create()
.WithBody("test {{request.origin}} {{request.port}} {{request.protocol}} {{request.host}}")

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using WireMock.Util;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_SingleValue()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, string> { { "h", "x" } };
var response = Response.Create().WithHeaders(headers);
@@ -31,7 +32,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_MultipleValues()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, string[]> { { "h", new[] { "x" } } };
var response = Response.Create().WithHeaders(headers);
@@ -46,7 +47,7 @@ namespace WireMock.Net.Tests.ResponseBuilderTests
public async Task Response_ProvideResponse_WithHeaders_WiremockList()
{
// Assign
var request = new RequestMessage(new Uri("http://localhost"), "GET", ClientIp);
var request = new RequestMessage(new UrlDetails("http://localhost"), "GET", ClientIp);
var headers = new Dictionary<string, WireMockList<string>> { { "h", new WireMockList<string>("x") } };
var response = Response.Create().WithHeaders(headers);

View File

@@ -1,5 +1,6 @@
using System;
using NFluent;
using WireMock.Models;
using WireMock.ResponseBuilders;
using Xunit;
@@ -16,7 +17,7 @@ namespace WireMock.Net.Tests
public async void Response_Create_WithHeader(string headerName, string headerValue)
{
// Assign
var requestMock = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
var requestMock = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp);
IResponseBuilder builder = Response.Create().WithHeader(headerName, headerValue);
// Act

View File

@@ -0,0 +1,53 @@
using System;
using Microsoft.Owin;
using NFluent;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util
{
public class UrlUtilsTests
{
[Fact]
public void UriUtils_CreateUri_WithValidPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString("/a"));
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
[Fact]
public void UriUtils_CreateUri_WithEmptyPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString());
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
[Fact]
public void UriUtils_CreateUri_WithDifferentPathString()
{
// Assign
Uri uri = new Uri("https://localhost:1234/a/b?x=0");
// Act
var result = UrlUtils.Parse(uri, new PathString("/test"));
// Assert
Check.That(result.Url.ToString()).Equals("https://localhost:1234/a/b?x=0");
Check.That(result.AbsoluteUrl.ToString()).Equals("https://localhost:1234/a/b?x=0");
}
}
}

View File

@@ -7,6 +7,7 @@
<AssemblyName>WireMock.Net.Tests</AssemblyName>
<PackageId>WireMock.Net.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<ProjectGuid>{31DC2EF8-C3FE-467D-84BE-FB5D956E612E}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
@@ -14,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="3.1.0" />
<PackageReference Include="Moq" Version="4.8.3" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
@@ -23,7 +24,7 @@
<PackageReference Include="ReportGenerator" Version="3.1.2" />
<PackageReference Include="SimMetrics.Net" Version="1.0.4" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
@@ -31,8 +32,8 @@
</ItemGroup>
<ItemGroup>
<None Update="ResponseBodyFiles\responsebody.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<None Update="responsebody.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>