mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-08 03:19:34 +01:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf283ec13 | ||
|
|
2c0f00d77f | ||
|
|
1bcdfe31ab | ||
|
|
0abe12f5c8 | ||
|
|
7bd63a0baf | ||
|
|
a29363105c | ||
|
|
4f294baff2 | ||
|
|
2d2a2dd6fc | ||
|
|
ac72973cc4 | ||
|
|
e87f970057 | ||
|
|
df4a1f628a | ||
|
|
bdb79aec95 | ||
|
|
3369501506 | ||
|
|
8662638622 | ||
|
|
a3c853b4ad | ||
|
|
a4a9f2c862 |
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,3 +1,42 @@
|
||||
# 1.0.3.16 (15 April 2018)
|
||||
|
||||
- [#125](https://github.com/WireMock-Net/WireMock.Net/pull/125) - Change listen from loopback to any ip address for dotnetcore2.0 apps contributed by ([SubjectiveReality](https://github.com/SubjectiveReality))
|
||||
- [#124](https://github.com/WireMock-Net/WireMock.Net/issues/124) - Issue: Unable to get host to listen on ips other than 127.0.0.1 using StandAloneApp
|
||||
- [#121](https://github.com/WireMock-Net/WireMock.Net/pull/121) - Fix for issue #118 contributed by ([raghavendrabankapur](https://github.com/raghavendrabankapur)) +fix
|
||||
- [#118](https://github.com/WireMock-Net/WireMock.Net/issues/118) - Not reading the response from a file when mappings are placed in json file
|
||||
|
||||
Commits: 7bd63a0baf...1bcdfe31ab
|
||||
|
||||
|
||||
# 1.0.3.15 (05 April 2018)
|
||||
|
||||
- [#117](https://github.com/WireMock-Net/WireMock.Net/pull/117) - Respect start timeout setting and expose exception from server startup contributed by Evan Liang ([evanlwj](https://github.com/evanlwj))
|
||||
|
||||
Commits: 2d2a2dd6fc...4f294baff2
|
||||
|
||||
|
||||
# 1.0.3.14 (01 April 2018)
|
||||
|
||||
- [#114](https://github.com/WireMock-Net/WireMock.Net/issues/114) - Feature: Add PathSegments in Transform +feature
|
||||
- [#113](https://github.com/WireMock-Net/WireMock.Net/issues/113) - Feature: Add BodyAsJsonIndented for response message +feature
|
||||
|
||||
Commits: bdb79aec95...e87f970057
|
||||
|
||||
|
||||
# 1.0.3.12 (24 March 2018)
|
||||
|
||||
- [#100](https://github.com/WireMock-Net/WireMock.Net/issues/100) - Issue: JsonPathMatcher - not working for rootless jsons?
|
||||
|
||||
Commits: ...
|
||||
|
||||
|
||||
# 1.0.3.11 (20 March 2018)
|
||||
|
||||
- [#110](https://github.com/WireMock-Net/WireMock.Net/issues/110) - Fix: remove `Func[]` from MappingModel
|
||||
|
||||
Commits: a4a9f2c862...a4a9f2c862
|
||||
|
||||
|
||||
# 1.0.3.10 (17 March 2018)
|
||||
|
||||
- [#109](https://github.com/WireMock-Net/WireMock.Net/issues/109) - Issue: When proxying, MimeType is wrong for StringContent
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
https://github.com/GitTools/GitReleaseNotes
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.10
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.3.16
|
||||
|
||||
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags
|
||||
|
||||
@@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
GitReleaseNotes.txt = GitReleaseNotes.txt
|
||||
README.md = README.md
|
||||
ReSharper_WireMock.DotSettings = ReSharper_WireMock.DotSettings
|
||||
WireMock.Net Solution.sln.DotSettings = WireMock.Net Solution.sln.DotSettings
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{F0C22C47-DF71-463C-9B04-B4E0F3B8708A}"
|
||||
@@ -49,6 +50,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.Proxy.
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone.Net461", "examples\WireMock.Net.StandAlone.Net461\WireMock.Net.StandAlone.Net461.csproj", "{3C279524-DB73-4DE3-BEF1-F2B2958C9F65}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Service", "examples\Wiremock.Net.Service\WireMock.Net.Service.csproj", "{7F0B2446-0363-4720-AF46-F47F83B557DC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -107,6 +110,10 @@ Global
|
||||
{3C279524-DB73-4DE3-BEF1-F2B2958C9F65}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3C279524-DB73-4DE3-BEF1-F2B2958C9F65}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3C279524-DB73-4DE3-BEF1-F2B2958C9F65}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7F0B2446-0363-4720-AF46-F47F83B557DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7F0B2446-0363-4720-AF46-F47F83B557DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F0B2446-0363-4720-AF46-F47F83B557DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F0B2446-0363-4720-AF46-F47F83B557DC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -125,6 +132,7 @@ Global
|
||||
{26433A8F-BF01-4962-97EB-81BFFBB61096} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{23A9AA3C-40FC-42AA-8A5E-05899795A1C6} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{3C279524-DB73-4DE3-BEF1-F2B2958C9F65} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
{7F0B2446-0363-4720-AF46-F47F83B557DC} = {F0C22C47-DF71-463C-9B04-B4E0F3B8708A}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BF428BCC-C837-433B-87D2-15C7014B73E9}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSL/@EntryIndexedValue">SSL</s:String></wpf:ResourceDictionary>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MD/@EntryIndexedValue">MD5</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSL/@EntryIndexedValue">SSL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TE/@EntryIndexedValue">TE</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TSV/@EntryIndexedValue">TSV</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WWW/@EntryIndexedValue">WWW</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XMS/@EntryIndexedValue">XMS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XUA/@EntryIndexedValue">XUA</s:String>
|
||||
</wpf:ResourceDictionary>
|
||||
@@ -160,18 +160,17 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.RespondWith(Response.Create().WithStatusCode(200).WithBody("partial = 200"));
|
||||
|
||||
// http://localhost:8080/any/any?start=1000&stop=1&stop=2
|
||||
//server
|
||||
// .Given(Request.Create().WithPath("/*").UsingGet())
|
||||
// .WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
// .AtPriority(server.Mappings.Count() + 1)
|
||||
// .RespondWith(Response.Create()
|
||||
// .WithStatusCode(200)
|
||||
// .WithHeader("Content-Type", "application/json")
|
||||
// .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||
// .WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||
// .WithTransformer()
|
||||
// .WithDelay(TimeSpan.FromMilliseconds(100))
|
||||
// );
|
||||
server
|
||||
.Given(Request.Create().WithPath("/trans").UsingGet())
|
||||
.WithGuid("90356dba-b36c-469a-a17e-669cd84f1f05")
|
||||
.RespondWith(Response.Create()
|
||||
.WithStatusCode(200)
|
||||
.WithHeader("Content-Type", "application/json")
|
||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
||||
.WithBody(@"{""msg"": ""Hello world CATCH-ALL on /*, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||
.WithTransformer()
|
||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||
);
|
||||
|
||||
server
|
||||
.Given(Request.Create()
|
||||
|
||||
14
examples/WireMock.Net.Service/App.config
Normal file
14
examples/WireMock.Net.Service/App.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
28
examples/WireMock.Net.Service/InstallUtil.InstallLog
Normal file
28
examples/WireMock.Net.Service/InstallUtil.InstallLog
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
The uninstall is beginning.
|
||||
See the contents of the log file for the C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.exe assembly's progress.
|
||||
The file is located at C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.InstallLog.
|
||||
|
||||
The uninstall has completed.
|
||||
|
||||
|
||||
The uninstall is beginning.
|
||||
See the contents of the log file for the C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.exe assembly's progress.
|
||||
The file is located at C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.InstallLog.
|
||||
|
||||
The uninstall has completed.
|
||||
|
||||
|
||||
The uninstall is beginning.
|
||||
See the contents of the log file for the C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.exe assembly's progress.
|
||||
The file is located at C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\Wiremock.Net.Service.InstallLog.
|
||||
|
||||
The uninstall has completed.
|
||||
|
||||
|
||||
The uninstall is beginning.
|
||||
See the contents of the log file for the C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\WireMock.Net.Service.exe assembly's progress.
|
||||
The file is located at C:\Users\azureuser\Documents\Github\WireMock.Net\examples\Wiremock.Net.Service\bin\debug\WireMock.Net.Service.InstallLog.
|
||||
|
||||
The uninstall has completed.
|
||||
59
examples/WireMock.Net.Service/Installer.Designer.cs
generated
Normal file
59
examples/WireMock.Net.Service/Installer.Designer.cs
generated
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace Wiremock.Net.Service
|
||||
{
|
||||
partial class Installer
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Component Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
|
||||
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
|
||||
//
|
||||
// serviceProcessInstaller1
|
||||
//
|
||||
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
|
||||
this.serviceProcessInstaller1.Password = null;
|
||||
this.serviceProcessInstaller1.Username = null;
|
||||
//
|
||||
// serviceInstaller1
|
||||
//
|
||||
this.serviceInstaller1.Description = "WireMock.Net Service";
|
||||
this.serviceInstaller1.DisplayName = "WireMock.Net.Service";
|
||||
this.serviceInstaller1.ServiceName = "WireMock.Net.Service";
|
||||
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
|
||||
//
|
||||
// ProjectInstaller
|
||||
//
|
||||
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
|
||||
this.serviceProcessInstaller1,
|
||||
this.serviceInstaller1});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
|
||||
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
|
||||
}
|
||||
}
|
||||
19
examples/WireMock.Net.Service/Installer.cs
Normal file
19
examples/WireMock.Net.Service/Installer.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wiremock.Net.Service
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public partial class Installer : System.Configuration.Install.Installer
|
||||
{
|
||||
public Installer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
74
examples/WireMock.Net.Service/Program.cs
Normal file
74
examples/WireMock.Net.Service/Program.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.ServiceProcess;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Net.StandAlone;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace Wiremock.Net.Service
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
#region Nested classes to support running as service
|
||||
public const string ServiceName = "Wiremock.Net.Service";
|
||||
|
||||
public class Service : ServiceBase
|
||||
{
|
||||
public Service()
|
||||
{
|
||||
ServiceName = Program.ServiceName;
|
||||
}
|
||||
|
||||
protected override void OnStart(string[] args)
|
||||
{
|
||||
Start();
|
||||
}
|
||||
|
||||
protected override void OnStop()
|
||||
{
|
||||
Program.Stop();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static FluentMockServer _server;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// running as service
|
||||
if (!Environment.UserInteractive)
|
||||
{
|
||||
using (var service = new Service())
|
||||
{
|
||||
ServiceBase.Run(service);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// running as console app
|
||||
Start();
|
||||
|
||||
Console.WriteLine("Press any key to stop...");
|
||||
Console.ReadKey(true);
|
||||
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Start()
|
||||
{
|
||||
_server = StandAloneApp.Start(new FluentMockServerSettings
|
||||
{
|
||||
Urls = new[] { "http://*:9091/" },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = true,
|
||||
Logger = new WireMockConsoleLogger()
|
||||
});
|
||||
}
|
||||
|
||||
private static void Stop()
|
||||
{
|
||||
_server.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
examples/WireMock.Net.Service/Properties/AssemblyInfo.cs
Normal file
35
examples/WireMock.Net.Service/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Wiremock.Net.Service")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Wiremock.Net.Service")]
|
||||
[assembly: AssemblyCopyright("Copyright © Stef Heyenrath 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("7f0b2446-0363-4720-af46-f47f83b557dc")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
11
examples/WireMock.Net.Service/Service-Install.bat
Normal file
11
examples/WireMock.Net.Service/Service-Install.bat
Normal file
@@ -0,0 +1,11 @@
|
||||
@echo off
|
||||
call uninstall.bat
|
||||
|
||||
SET mypath=%~dp0
|
||||
SET targetpath=C:\Services\WireMock.Net.Service\
|
||||
|
||||
mkdir "%targetpath%"
|
||||
xcopy "%mypath%*" "%targetpath%*"
|
||||
|
||||
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "%targetpath%WireMock.Net.Service.exe"
|
||||
net start "WireMock.Net.Service"
|
||||
3
examples/WireMock.Net.Service/Service-Start.bat
Normal file
3
examples/WireMock.Net.Service/Service-Start.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
|
||||
net start "WireMock.Net.Service"
|
||||
3
examples/WireMock.Net.Service/Service-Stop.bat
Normal file
3
examples/WireMock.Net.Service/Service-Stop.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
@echo off
|
||||
|
||||
net stop "WireMock.Net.Service"
|
||||
9
examples/WireMock.Net.Service/Service-Uninstall.bat
Normal file
9
examples/WireMock.Net.Service/Service-Uninstall.bat
Normal file
@@ -0,0 +1,9 @@
|
||||
@echo off
|
||||
SET mypath=%~dp0
|
||||
SET targetpath=C:\Services\WireMock.Net.Service\
|
||||
|
||||
net stop "WireMock.Net.Service"
|
||||
C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe /u "%mypath%WireMock.Net.Service.exe"
|
||||
sc delete "WireMock.Net.Service"
|
||||
|
||||
rmdir /S /Q "%targetpath%"
|
||||
127
examples/WireMock.Net.Service/WireMock.Net.Service.csproj
Normal file
127
examples/WireMock.Net.Service/WireMock.Net.Service.csproj
Normal file
@@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{7F0B2446-0363-4720-AF46-F47F83B557DC}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>WireMock.Net.Service</RootNamespace>
|
||||
<AssemblyName>WireMock.Net.Service</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Handlebars, Version=1.8.1.0, Culture=neutral, PublicKeyToken=22225d0bf33cd661, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Handlebars.Net.1.9.0\lib\net40\Handlebars.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Hosting, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MimeKitLite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bede1c8a46c66814, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\MimeKitLite.2.0.1\lib\net45\MimeKitLite.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="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="RestEase, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\RestEase.1.4.4\lib\net45\RestEase.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SimMetrics.Net, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\SimMetrics.Net.1.0.4\lib\net45\SimMetrics.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Security" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.Owin, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="XPath2, Version=1.0.5.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\XPath2.1.0.5.1\lib\net40\XPath2.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Installer.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Installer.Designer.cs">
|
||||
<DependentUpon>Installer.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="Service-Start.bat">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Service-Stop.bat">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Service-Uninstall.bat">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Service-Install.bat">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj">
|
||||
<Project>{b6269aac-170a-43d5-8b9a-579ded3d9a95}</Project>
|
||||
<Name>WireMock.Net.StandAlone</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj">
|
||||
<Project>{d3804228-91f4-4502-9595-39584e5a01ad}</Project>
|
||||
<Name>WireMock.Net</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
18
examples/WireMock.Net.Service/packages.config
Normal file
18
examples/WireMock.Net.Service/packages.config
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Handlebars.Net" version="1.9.0" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Owin" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.OwinSelfHost" version="5.2.3" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin" version="2.0.2" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="2.0.2" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Hosting" version="2.0.2" targetFramework="net452" />
|
||||
<package id="MimeKitLite" version="2.0.1" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
|
||||
<package id="Owin" version="1.0" targetFramework="net452" />
|
||||
<package id="RestEase" version="1.4.4" targetFramework="net452" />
|
||||
<package id="SimMetrics.Net" version="1.0.4" targetFramework="net452" />
|
||||
<package id="System.Net.Http" version="4.3.3" targetFramework="net452" />
|
||||
<package id="XPath2" version="1.0.5.1" targetFramework="net452" />
|
||||
</packages>
|
||||
@@ -21,7 +21,11 @@ namespace WireMock.Net.StandAlone
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
|
||||
return FluentMockServer.Start(settings);
|
||||
var server = FluentMockServer.Start(settings);
|
||||
|
||||
settings.Logger.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -80,8 +84,6 @@ namespace WireMock.Net.StandAlone
|
||||
|
||||
FluentMockServer server = Start(settings);
|
||||
|
||||
settings.Logger.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
|
||||
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
|
||||
<Version>1.0.3.10</Version>
|
||||
<Version>1.0.3.16</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -8,25 +8,16 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matcher.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matcher.
|
||||
/// </value>
|
||||
public MatcherModel Matcher { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the function.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The function.
|
||||
/// </value>
|
||||
public string Func { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the function.
|
||||
///// </summary>
|
||||
//public string Func { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the data function.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The data function.
|
||||
/// </value>
|
||||
public string DataFunc { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the data function.
|
||||
///// </summary>
|
||||
//public string DataFunc { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,11 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,16 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The name.
|
||||
/// </value>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public IList<MatcherModel> Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,16 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The name.
|
||||
/// </value>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public IList<MatcherModel> Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,16 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The name.
|
||||
/// </value>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the values.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The values.
|
||||
/// </value>
|
||||
public IList<string> Values { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,11 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,16 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the ClientIP. (Can be a string or a ClientIPModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The ClientIP.
|
||||
/// </value>
|
||||
public object ClientIP { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Path. (Can be a string or a PathModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Path.
|
||||
/// </value>
|
||||
public object Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Url. (Can be a string or a UrlModel)
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The URL.
|
||||
/// </value>
|
||||
public object Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -39,33 +30,21 @@ namespace WireMock.Admin.Mappings
|
||||
/// <summary>
|
||||
/// Gets or sets the Headers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Headers.
|
||||
/// </value>
|
||||
public IList<HeaderModel> Headers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Cookies.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Cookies.
|
||||
/// </value>
|
||||
public IList<CookieModel> Cookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Params.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The Headers.
|
||||
/// </value>
|
||||
public IList<ParamModel> Params { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The body.
|
||||
/// </value>
|
||||
public BodyModel Body { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,11 @@ namespace WireMock.Admin.Mappings
|
||||
/// </summary>
|
||||
public object BodyAsJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
||||
/// </summary>
|
||||
public bool? BodyAsJsonIndented { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body (as bytearray).
|
||||
/// </summary>
|
||||
|
||||
@@ -8,17 +8,11 @@
|
||||
/// <summary>
|
||||
/// Gets or sets the matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The matchers.
|
||||
/// </value>
|
||||
public MatcherModel[] Matchers { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the functions.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The functions.
|
||||
/// </value>
|
||||
public string[] Funcs { get; set; }
|
||||
///// <summary>
|
||||
///// Gets or sets the functions.
|
||||
///// </summary>
|
||||
//public string[] Funcs { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,11 @@ using WireMock.Validation;
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
/// <summary>
|
||||
/// JSONPathMatcher
|
||||
/// JsonPathMatcher
|
||||
/// </summary>
|
||||
/// <seealso cref="IMatcher" />
|
||||
public class JsonPathMatcher : IStringMatcher, IObjectMatcher
|
||||
{
|
||||
// private readonly object _jsonPattern;
|
||||
private readonly string[] _patterns;
|
||||
|
||||
/// <summary>
|
||||
@@ -26,13 +25,6 @@ namespace WireMock.Matchers
|
||||
_patterns = patterns;
|
||||
}
|
||||
|
||||
//public JsonPathMatcher([NotNull] object jsonPattern)
|
||||
//{
|
||||
// Check.NotNull(jsonPattern, nameof(jsonPattern));
|
||||
|
||||
// _jsonPattern = jsonPattern;
|
||||
//}
|
||||
|
||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||
public double IsMatch(string input)
|
||||
{
|
||||
@@ -43,9 +35,8 @@ namespace WireMock.Matchers
|
||||
|
||||
try
|
||||
{
|
||||
JObject o = JObject.Parse(input);
|
||||
|
||||
return MatchScores.ToScore(_patterns.Select(p => o.SelectToken(p) != null));
|
||||
var jtoken = JToken.Parse(input);
|
||||
return IsMatch(jtoken);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -63,9 +54,9 @@ namespace WireMock.Matchers
|
||||
|
||||
try
|
||||
{
|
||||
var o = input as JObject ?? JObject.FromObject(input);
|
||||
|
||||
return MatchScores.ToScore(_patterns.Select(p => o.SelectToken(p) != null));
|
||||
// Check if JToken or object
|
||||
JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
|
||||
return IsMatch(jtoken);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -84,5 +75,13 @@ namespace WireMock.Matchers
|
||||
{
|
||||
return "JsonPathMatcher";
|
||||
}
|
||||
|
||||
private double IsMatch(JToken jtoken)
|
||||
{
|
||||
// Wrap in array if needed
|
||||
JToken jarray = jtoken is JArray ? jtoken : new JArray(jtoken);
|
||||
|
||||
return MatchScores.ToScore(_patterns.Select(pattern => jarray.SelectToken(pattern) != null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using WireMock.Http;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -18,6 +19,8 @@ namespace WireMock.Owin
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly string[] _urls;
|
||||
private readonly IWireMockLogger _logger;
|
||||
private Exception _runningException;
|
||||
|
||||
private IWebHost _host;
|
||||
|
||||
@@ -27,11 +30,15 @@ namespace WireMock.Owin
|
||||
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
public Exception RunningException => _runningException;
|
||||
|
||||
public AspNetCoreSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
_logger = options.Logger ?? new WireMockConsoleLogger();
|
||||
|
||||
foreach (string uriPrefix in uriPrefixes)
|
||||
{
|
||||
Urls.Add(uriPrefix);
|
||||
@@ -69,13 +76,13 @@ namespace WireMock.Owin
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("http://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(System.Net.IPAddress.Loopback, port);
|
||||
options.Listen(System.Net.IPAddress.Any, port);
|
||||
}
|
||||
|
||||
foreach (string url in _urls.Where(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PortUtil.TryExtractProtocolAndPort(url, out string host, out int port);
|
||||
options.Listen(System.Net.IPAddress.Loopback, port, listenOptions =>
|
||||
options.Listen(System.Net.IPAddress.Any, port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
});
|
||||
@@ -89,20 +96,34 @@ namespace WireMock.Owin
|
||||
|
||||
IsStarted = true;
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
Console.WriteLine("WireMock.Net server using netstandard1.3");
|
||||
return Task.Run(() =>
|
||||
{
|
||||
_host.Run(_cts.Token);
|
||||
StartServers();
|
||||
}, _cts.Token);
|
||||
#else
|
||||
System.Console.WriteLine("WireMock.Net server using netstandard2.0");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
private void StartServers()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsStarted = true;
|
||||
#if NETSTANDARD1_3
|
||||
_logger.Info("WireMock.Net server using netstandard1.3");
|
||||
_host.Run(_cts.Token);
|
||||
#else
|
||||
_logger.Info("WireMock.Net server using netstandard2.0");
|
||||
_host.Run();
|
||||
}, _cts.Token);
|
||||
#endif
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_runningException = e;
|
||||
_logger.Error(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsStarted = false;
|
||||
}
|
||||
}
|
||||
|
||||
public Task StopAsync()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -16,19 +17,18 @@ namespace WireMock.Owin
|
||||
/// <summary>
|
||||
/// Gets the urls.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
List<string> Urls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ports.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The ports.
|
||||
/// </value>
|
||||
List<int> Ports { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The exception occurred when the host is running
|
||||
/// </summary>
|
||||
Exception RunningException { get; }
|
||||
|
||||
Task StartAsync();
|
||||
|
||||
Task StopAsync();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
// using System.IO;
|
||||
using System.Linq;
|
||||
// using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Util;
|
||||
#if !NETSTANDARD
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Http;
|
||||
using WireMock.Util;
|
||||
#if !NETSTANDARD
|
||||
using Microsoft.Owin;
|
||||
@@ -21,17 +22,27 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly Encoding _utf8NoBom = new UTF8Encoding(false);
|
||||
|
||||
// https://stackoverflow.com/questions/239725/cannot-set-some-http-headers-when-using-system-net-webrequest
|
||||
// https://msdn.microsoft.com/en-us/library/78h415ay(v=vs.110).aspx
|
||||
#if !NETSTANDARD
|
||||
private static readonly IDictionary<string, Action<IOwinResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<IOwinResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#else
|
||||
private static readonly IDictionary<string, Action<HttpResponse, WireMockList<string>>> RestrictedResponseHeaders = new Dictionary<string, Action<HttpResponse, WireMockList<string>>>(StringComparer.OrdinalIgnoreCase) {
|
||||
#endif
|
||||
{ "Content-Length", null },
|
||||
{ "Content-Type", (r, v) => r.ContentType = v.FirstOrDefault() },
|
||||
{ "Keep-Alive", null },
|
||||
{ "Transfer-Encoding", null },
|
||||
{ "WWW-Authenticate", null }
|
||||
{ HttpKnownHeaderNames.Accept, null },
|
||||
{ HttpKnownHeaderNames.Connection, null },
|
||||
{ HttpKnownHeaderNames.ContentLength, null },
|
||||
{ HttpKnownHeaderNames.ContentType, (r, v) => r.ContentType = v.FirstOrDefault() },
|
||||
{ HttpKnownHeaderNames.Date, null },
|
||||
{ HttpKnownHeaderNames.Expect, null },
|
||||
{ HttpKnownHeaderNames.Host, null },
|
||||
{ HttpKnownHeaderNames.IfModifiedSince, null },
|
||||
{ HttpKnownHeaderNames.KeepAlive, null },
|
||||
{ HttpKnownHeaderNames.Range, null },
|
||||
{ HttpKnownHeaderNames.Referer, null },
|
||||
{ HttpKnownHeaderNames.TransferEncoding, null },
|
||||
{ HttpKnownHeaderNames.UserAgent, null },
|
||||
{ HttpKnownHeaderNames.ProxyConnection, null },
|
||||
{ HttpKnownHeaderNames.WWWAuthenticate, null }
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -87,7 +98,8 @@ namespace WireMock.Owin
|
||||
|
||||
if (responseMessage.BodyAsJson != null)
|
||||
{
|
||||
string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore });
|
||||
Formatting formatting = responseMessage.BodyAsJsonIndented == true ? Formatting.Indented : Formatting.None;
|
||||
string jsonBody = JsonConvert.SerializeObject(responseMessage.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore });
|
||||
using (var writer = new StreamWriter(response.Body, responseMessage.BodyEncoding ?? _utf8NoBom))
|
||||
{
|
||||
await writer.WriteAsync(jsonBody);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#if !NETSTANDARD
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using Owin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Owin;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using WireMock.Http;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -15,12 +16,16 @@ namespace WireMock.Owin
|
||||
{
|
||||
private readonly WireMockMiddlewareOptions _options;
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private readonly IWireMockLogger _logger;
|
||||
private Exception _runningException;
|
||||
|
||||
public OwinSelfHost([NotNull] WireMockMiddlewareOptions options, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNullOrEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
_logger = options.Logger ?? new WireMockConsoleLogger();
|
||||
|
||||
foreach (string uriPrefix in uriPrefixes)
|
||||
{
|
||||
Urls.Add(uriPrefix);
|
||||
@@ -38,6 +43,8 @@ namespace WireMock.Owin
|
||||
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
public Exception RunningException => _runningException;
|
||||
|
||||
[PublicAPI]
|
||||
public Task StartAsync()
|
||||
{
|
||||
@@ -58,37 +65,46 @@ namespace WireMock.Owin
|
||||
private void StartServers()
|
||||
{
|
||||
#if NET46
|
||||
Console.WriteLine("WireMock.Net server using .net 4.6.x or higher");
|
||||
_logger.Info("WireMock.Net server using .net 4.6.x or higher");
|
||||
#else
|
||||
Console.WriteLine("WireMock.Net server using .net 4.5.x or higher");
|
||||
_logger.Info("WireMock.Net server using .net 4.5.x or higher");
|
||||
#endif
|
||||
|
||||
Action<IAppBuilder> startup = app =>
|
||||
{
|
||||
app.Use<GlobalExceptionMiddleware>(_options);
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(app);
|
||||
app.Use<WireMockMiddleware>(_options);
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(app);
|
||||
};
|
||||
|
||||
var servers = new List<IDisposable>();
|
||||
foreach (var url in Urls)
|
||||
|
||||
try
|
||||
{
|
||||
servers.Add(WebApp.Start(url, startup));
|
||||
Action<IAppBuilder> startup = app =>
|
||||
{
|
||||
app.Use<GlobalExceptionMiddleware>(_options);
|
||||
_options.PreWireMockMiddlewareInit?.Invoke(app);
|
||||
app.Use<WireMockMiddleware>(_options);
|
||||
_options.PostWireMockMiddlewareInit?.Invoke(app);
|
||||
};
|
||||
|
||||
foreach (var url in Urls)
|
||||
{
|
||||
servers.Add(WebApp.Start(url, startup));
|
||||
}
|
||||
|
||||
IsStarted = true;
|
||||
|
||||
// WaitHandle is signaled when the token is cancelled,
|
||||
// which will be more efficent than Thread.Sleep in while loop
|
||||
_cts.Token.WaitHandle.WaitOne();
|
||||
}
|
||||
|
||||
IsStarted = true;
|
||||
|
||||
while (!_cts.IsCancellationRequested)
|
||||
catch (Exception e)
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
// Expose exception of starting host, otherwise it's hard to be troubleshooting if keeping quiet
|
||||
// For example, WebApp.Start will fail with System.MissingMemberException if Microsoft.Owin.Host.HttpListener.dll is being located
|
||||
// https://stackoverflow.com/questions/25090211/owin-httplistener-not-located/31369857
|
||||
_runningException = e;
|
||||
_logger.Error(e.ToString());
|
||||
}
|
||||
|
||||
IsStarted = false;
|
||||
|
||||
foreach (var server in servers)
|
||||
finally
|
||||
{
|
||||
server.Dispose();
|
||||
IsStarted = false;
|
||||
// Dispose all servers in finally block to make sure clean up allocated resource on error happening
|
||||
servers.ForEach(s => s.Dispose());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public string Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path segments.
|
||||
/// </summary>
|
||||
public string[] PathSegments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the method.
|
||||
/// </summary>
|
||||
@@ -120,6 +125,7 @@ namespace WireMock
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
PathSegments = Path.Split('/').Skip(1).ToArray();
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
|
||||
@@ -157,11 +163,14 @@ namespace WireMock
|
||||
Port = url.Port;
|
||||
Origin = $"{url.Scheme}://{url.Host}:{url.Port}";
|
||||
Path = WebUtility.UrlDecode(url.AbsolutePath);
|
||||
PathSegments = Path.Split('/').Skip(1).ToArray();
|
||||
Method = method.ToLower();
|
||||
ClientIP = clientIP;
|
||||
|
||||
BodyAsBytes = bodyAsBytes;
|
||||
Body = body;
|
||||
BodyEncoding = bodyEncoding;
|
||||
|
||||
Headers = headers?.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
Cookies = cookies;
|
||||
RawQuery = WebUtility.UrlDecode(url.Query);
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace WireMock.ResponseBuilders
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] string body, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a ... response based on a callback function.
|
||||
/// </summary>
|
||||
@@ -26,8 +25,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <param name="destination">The Body Destination format (SameAsSource, String or Bytes).</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage,string> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
IResponseBuilder WithBody([NotNull] Func<RequestMessage, string> bodyFactory, [CanBeNull] string destination = BodyDestinationFormat.SameAsSource, [CanBeNull] Encoding encoding = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a ... response based on a bytearray.
|
||||
@@ -43,8 +41,17 @@ namespace WireMock.ResponseBuilders
|
||||
/// </summary>
|
||||
/// <param name="body">The body.</param>
|
||||
/// <param name="encoding">The body encoding.</param>
|
||||
/// <param name="indented">Use JSON indented.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBodyAsJson([NotNull] object body, [CanBeNull] Encoding encoding = null);
|
||||
IResponseBuilder WithBodyAsJson([NotNull] object body, [CanBeNull] Encoding encoding = null, bool? indented = null);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a string response based on a object (which will be converted to a JSON string).
|
||||
/// </summary>
|
||||
/// <param name="body">The body.</param>
|
||||
/// <param name="indented">Define whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.</param>
|
||||
/// <returns>A <see cref="IResponseBuilder"/>.</returns>
|
||||
IResponseBuilder WithBodyAsJson([NotNull] object body, bool indented);
|
||||
|
||||
/// <summary>
|
||||
/// WithBody : Create a string response based on a Base64 string (which will be decoded to a normal string).
|
||||
|
||||
@@ -31,9 +31,6 @@ namespace WireMock.ResponseBuilders
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether [use transformer].
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if [use transformer]; otherwise, <c>false</c>.
|
||||
/// </value>
|
||||
public bool UseTransformer { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -258,18 +255,25 @@ namespace WireMock.ResponseBuilders
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyAsJson"/>
|
||||
public IResponseBuilder WithBodyAsJson(object body, Encoding encoding = null)
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyAsJson(object, Encoding, bool?)"/>
|
||||
public IResponseBuilder WithBodyAsJson(object body, Encoding encoding = null, bool? indented = null)
|
||||
{
|
||||
Check.NotNull(body, nameof(body));
|
||||
|
||||
ResponseMessage.BodyDestination = null;
|
||||
ResponseMessage.BodyAsJson = body;
|
||||
ResponseMessage.BodyEncoding = encoding;
|
||||
ResponseMessage.BodyAsJsonIndented = indented;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyAsJson(object, bool)"/>
|
||||
public IResponseBuilder WithBodyAsJson(object body, bool indented)
|
||||
{
|
||||
return WithBodyAsJson(body, null, indented);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyFromBase64"/>
|
||||
public IResponseBuilder WithBodyFromBase64(string bodyAsbase64, Encoding encoding = null)
|
||||
{
|
||||
|
||||
@@ -42,6 +42,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public object BodyAsJson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether child objects to be indented according to the Newtonsoft.Json.JsonTextWriter.Indentation and Newtonsoft.Json.JsonTextWriter.IndentChar settings.
|
||||
/// </summary>
|
||||
public bool? BodyAsJsonIndented { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the body as bytes.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -38,20 +36,20 @@ namespace WireMock.Serialization
|
||||
{
|
||||
ClientIP = clientIPMatchers != null && clientIPMatchers.Any() ? new ClientIPModel
|
||||
{
|
||||
Matchers = MatcherMapper.Map(clientIPMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)),
|
||||
Funcs = Map(clientIPMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
Matchers = MatcherMapper.Map(clientIPMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers))
|
||||
//Funcs = Map(clientIPMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
} : null,
|
||||
|
||||
Path = pathMatchers != null && pathMatchers.Any() ? new PathModel
|
||||
{
|
||||
Matchers = MatcherMapper.Map(pathMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)),
|
||||
Funcs = Map(pathMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
Matchers = MatcherMapper.Map(pathMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers))
|
||||
//Funcs = Map(pathMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
} : null,
|
||||
|
||||
Url = urlMatchers != null && urlMatchers.Any() ? new UrlModel
|
||||
{
|
||||
Matchers = MatcherMapper.Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)),
|
||||
Funcs = Map(urlMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
Matchers = MatcherMapper.Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers))
|
||||
//Funcs = Map(urlMatchers.Where(m => m.Funcs != null).SelectMany(m => m.Funcs))
|
||||
} : null,
|
||||
|
||||
Methods = methodMatcher?.Methods,
|
||||
@@ -59,29 +57,29 @@ namespace WireMock.Serialization
|
||||
Headers = headerMatchers != null && headerMatchers.Any() ? headerMatchers.Select(hm => new HeaderModel
|
||||
{
|
||||
Name = hm.Name,
|
||||
Matchers = MatcherMapper.Map(hm.Matchers),
|
||||
Funcs = Map(hm.Funcs)
|
||||
Matchers = MatcherMapper.Map(hm.Matchers)
|
||||
//Funcs = Map(hm.Funcs)
|
||||
}).ToList() : null,
|
||||
|
||||
Cookies = cookieMatchers != null && cookieMatchers.Any() ? cookieMatchers.Select(cm => new CookieModel
|
||||
{
|
||||
Name = cm.Name,
|
||||
Matchers = MatcherMapper.Map(cm.Matchers),
|
||||
Funcs = Map(cm.Funcs)
|
||||
Matchers = MatcherMapper.Map(cm.Matchers)
|
||||
//Funcs = Map(cm.Funcs)
|
||||
}).ToList() : null,
|
||||
|
||||
Params = paramsMatchers != null && paramsMatchers.Any() ? paramsMatchers.Select(pm => new ParamModel
|
||||
{
|
||||
Name = pm.Key,
|
||||
Values = pm.Values?.ToList(),
|
||||
Funcs = Map(pm.Funcs)
|
||||
Values = pm.Values?.ToList()
|
||||
//Funcs = Map(pm.Funcs)
|
||||
}).ToList() : null,
|
||||
|
||||
Body = methodMatcher?.Methods != null && methodMatcher.Methods.Any(m => m == "get") ? null : new BodyModel
|
||||
{
|
||||
Matcher = bodyMatcher != null ? MatcherMapper.Map(bodyMatcher.Matcher) : null,
|
||||
Func = bodyMatcher != null ? Map(bodyMatcher.Func) : null,
|
||||
DataFunc = bodyMatcher != null ? Map(bodyMatcher.DataFunc) : null
|
||||
Matcher = bodyMatcher != null ? MatcherMapper.Map(bodyMatcher.Matcher) : null
|
||||
//Func = bodyMatcher != null ? Map(bodyMatcher.Func) : null,
|
||||
//DataFunc = bodyMatcher != null ? Map(bodyMatcher.DataFunc) : null
|
||||
}
|
||||
},
|
||||
Response = new ResponseModel
|
||||
@@ -96,6 +94,7 @@ namespace WireMock.Serialization
|
||||
mappingModel.Response.Headers = null;
|
||||
mappingModel.Response.BodyDestination = null;
|
||||
mappingModel.Response.BodyAsJson = null;
|
||||
mappingModel.Response.BodyAsJsonIndented = null;
|
||||
mappingModel.Response.Body = null;
|
||||
mappingModel.Response.BodyAsBytes = null;
|
||||
mappingModel.Response.BodyAsFile = null;
|
||||
@@ -110,6 +109,7 @@ namespace WireMock.Serialization
|
||||
mappingModel.Response.StatusCode = response.ResponseMessage.StatusCode;
|
||||
mappingModel.Response.Headers = Map(response.ResponseMessage.Headers);
|
||||
mappingModel.Response.BodyAsJson = response.ResponseMessage.BodyAsJson;
|
||||
mappingModel.Response.BodyAsJsonIndented = response.ResponseMessage.BodyAsJsonIndented;
|
||||
mappingModel.Response.Body = response.ResponseMessage.Body;
|
||||
mappingModel.Response.BodyAsBytes = response.ResponseMessage.BodyAsBytes;
|
||||
mappingModel.Response.BodyAsFile = response.ResponseMessage.BodyAsFile;
|
||||
@@ -147,16 +147,14 @@ 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] 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();
|
||||
}
|
||||
//private static string Map<T>([CanBeNull] Func<T, bool> func)
|
||||
//{
|
||||
// return func?.ToString();
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -266,17 +266,19 @@ namespace WireMock.Server
|
||||
|
||||
private ResponseMessage SettingsUpdate(RequestMessage requestMessage)
|
||||
{
|
||||
var settings = requestMessage.Body != null ? JsonConvert.DeserializeObject<SettingsModel>(requestMessage.Body) : ((JObject)requestMessage.BodyAsJson).ToObject<SettingsModel>();
|
||||
|
||||
if (settings.AllowPartialMapping != null)
|
||||
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
|
||||
|
||||
var settings = DeserializeObject<SettingsModel>(requestMessage);
|
||||
_options.MaxRequestLogCount = settings.MaxRequestLogCount;
|
||||
|
||||
_options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
||||
|
||||
if (settings.AllowPartialMapping != null)
|
||||
{
|
||||
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
|
||||
}
|
||||
|
||||
if (settings.GlobalProcessingDelay != null)
|
||||
{
|
||||
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
|
||||
}
|
||||
|
||||
return new ResponseMessage { Body = "Settings updated" };
|
||||
}
|
||||
@@ -303,7 +305,7 @@ namespace WireMock.Server
|
||||
{
|
||||
Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));
|
||||
|
||||
MappingModel mappingModel = requestMessage.Body != null ? JsonConvert.DeserializeObject<MappingModel>(requestMessage.Body) : ((JObject)requestMessage.BodyAsJson).ToObject<MappingModel>();
|
||||
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
|
||||
DeserializeAndAddOrUpdateMapping(mappingModel, guid);
|
||||
|
||||
return new ResponseMessage { Body = "Mapping added or updated" };
|
||||
@@ -371,7 +373,7 @@ namespace WireMock.Server
|
||||
{
|
||||
try
|
||||
{
|
||||
MappingModel mappingModel = requestMessage.Body != null ? JsonConvert.DeserializeObject<MappingModel>(requestMessage.Body) : ((JObject)requestMessage.BodyAsJson).ToObject<MappingModel>();
|
||||
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
|
||||
DeserializeAndAddOrUpdateMapping(mappingModel);
|
||||
}
|
||||
catch (ArgumentException a)
|
||||
@@ -552,7 +554,7 @@ namespace WireMock.Server
|
||||
#region Requests/find
|
||||
private ResponseMessage RequestsFind(RequestMessage requestMessage)
|
||||
{
|
||||
var requestModel = requestMessage.Body != null ? JsonConvert.DeserializeObject<RequestModel>(requestMessage.Body) : ((JObject)requestMessage.BodyAsJson).ToObject<RequestModel>();
|
||||
var requestModel = DeserializeObject<RequestModel>(requestMessage);
|
||||
|
||||
var request = (Request)InitRequestBuilder(requestModel);
|
||||
|
||||
@@ -598,8 +600,7 @@ namespace WireMock.Server
|
||||
|
||||
if (requestModel.ClientIP != null)
|
||||
{
|
||||
string clientIP = requestModel.ClientIP as string;
|
||||
if (clientIP != null)
|
||||
if (requestModel.ClientIP is string clientIP)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithClientIP(clientIP);
|
||||
}
|
||||
@@ -615,8 +616,7 @@ namespace WireMock.Server
|
||||
|
||||
if (requestModel.Path != null)
|
||||
{
|
||||
string path = requestModel.Path as string;
|
||||
if (path != null)
|
||||
if (requestModel.Path is string path)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithPath(path);
|
||||
}
|
||||
@@ -632,8 +632,7 @@ namespace WireMock.Server
|
||||
|
||||
if (requestModel.Url != null)
|
||||
{
|
||||
string url = requestModel.Url as string;
|
||||
if (url != null)
|
||||
if (requestModel.Url is string url)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithUrl(url);
|
||||
}
|
||||
@@ -739,13 +738,18 @@ namespace WireMock.Server
|
||||
}
|
||||
else if (responseModel.BodyAsJson != null)
|
||||
{
|
||||
responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson, ToEncoding(responseModel.BodyEncoding));
|
||||
responseBuilder = responseBuilder.WithBodyAsJson(responseModel.BodyAsJson, ToEncoding(responseModel.BodyEncoding), responseModel.BodyAsJsonIndented == true);
|
||||
}
|
||||
else if (responseModel.BodyFromBase64 != null)
|
||||
{
|
||||
responseBuilder = responseBuilder.WithBodyFromBase64(responseModel.BodyFromBase64, ToEncoding(responseModel.BodyEncoding));
|
||||
}
|
||||
|
||||
else if (responseModel.BodyAsFile != null)
|
||||
{
|
||||
responseBuilder = responseBuilder.WithBodyFromFile(responseModel.BodyAsFile);
|
||||
}
|
||||
|
||||
if (responseModel.UseTransformer)
|
||||
{
|
||||
responseBuilder = responseBuilder.WithTransformer();
|
||||
@@ -768,5 +772,12 @@ namespace WireMock.Server
|
||||
{
|
||||
return encodingModel != null ? Encoding.GetEncoding(encodingModel.CodePage) : null;
|
||||
}
|
||||
|
||||
private T DeserializeObject<T>(RequestMessage requestMessage)
|
||||
{
|
||||
return requestMessage.Body != null ?
|
||||
JsonConvert.DeserializeObject<T>(requestMessage.Body) :
|
||||
((JObject)requestMessage.BodyAsJson).ToObject<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading;
|
||||
using WireMock.Http;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseProviders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using WireMock.Owin;
|
||||
using WireMock.ResponseProviders;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -32,7 +32,7 @@ namespace WireMock.Server
|
||||
/// Gets a value indicating whether this server is started.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public bool IsStarted { get; }
|
||||
public bool IsStarted => _httpServer != null && _httpServer.IsStarted;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ports.
|
||||
@@ -186,10 +186,23 @@ namespace WireMock.Server
|
||||
|
||||
_httpServer.StartAsync();
|
||||
|
||||
// Fix for 'Bug: Server not listening after Start() returns (on macOS)'
|
||||
Task.Delay(ServerStartDelay).Wait();
|
||||
|
||||
IsStarted = _httpServer.IsStarted;
|
||||
using (var ctsStartTimeout = new CancellationTokenSource(settings.StartTimeout))
|
||||
{
|
||||
while (!_httpServer.IsStarted)
|
||||
{
|
||||
// Throw out exception if service start fails
|
||||
if (_httpServer.RunningException != null)
|
||||
{
|
||||
throw new Exception($"Service start failed with error: {_httpServer.RunningException.Message}", _httpServer.RunningException);
|
||||
}
|
||||
// Respect start timeout setting by throwing TimeoutException
|
||||
if (ctsStartTimeout.IsCancellationRequested)
|
||||
{
|
||||
throw new TimeoutException($"Service start timed out after {TimeSpan.FromMilliseconds(settings.StartTimeout)}");
|
||||
}
|
||||
ctsStartTimeout.Token.WaitHandle.WaitOne(ServerStartDelay);
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.AllowPartialMapping == true)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,8 @@ namespace WireMock.Transformers
|
||||
var template = new { request = requestMessage };
|
||||
|
||||
// Body
|
||||
string body = bodyIsJson ? JsonConvert.SerializeObject(original.BodyAsJson) : original.Body;
|
||||
Formatting formatting = original.BodyAsJsonIndented == true ? Formatting.Indented : Formatting.None;
|
||||
string body = bodyIsJson ? JsonConvert.SerializeObject(original.BodyAsJson, formatting) : original.Body;
|
||||
if (body != null)
|
||||
{
|
||||
var templateBody = Handlebars.Compile(body);
|
||||
|
||||
@@ -11,8 +11,7 @@ namespace WireMock.Util
|
||||
return default(T);
|
||||
}
|
||||
|
||||
var token = value as JToken;
|
||||
return token == null ? default(T) : token.ToObject<T>();
|
||||
return !(value is JToken token) ? default(T) : token.ToObject<T>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.3.10</Version>
|
||||
<Version>1.0.3.16</Version>
|
||||
<Authors>Stef Heyenrath</Authors>
|
||||
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
|
||||
@@ -11,6 +11,7 @@ using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
@@ -76,6 +77,34 @@ namespace WireMock.Net.Tests
|
||||
Check.That(mappings.First().Title).IsNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_ReadStaticMapping_WithResponseBodyFromFile()
|
||||
{
|
||||
string guid = "00000002-ee28-4f29-ae63-1ac9b0802d87";
|
||||
|
||||
string folder = Path.Combine(GetCurrentFolder(), "__admin", "mappings", guid + ".json");
|
||||
string json = File.ReadAllText(folder);
|
||||
|
||||
string responseBodyFilePath = Path.Combine(GetCurrentFolder(), "ResponseBodyFiles", "responsebody.json");
|
||||
|
||||
dynamic jsonObj = JsonConvert.DeserializeObject(json);
|
||||
jsonObj["Response"]["BodyAsFile"] = responseBodyFilePath;
|
||||
|
||||
string output = JsonConvert.SerializeObject(jsonObj, Formatting.Indented);
|
||||
File.WriteAllText(folder, output);
|
||||
|
||||
_server = FluentMockServer.Start();
|
||||
_server.ReadStaticMappingAndAddOrUpdate(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(1);
|
||||
|
||||
Check.That(mappings.First().RequestMatcher).IsNotNull();
|
||||
Check.That(mappings.First().Provider).IsNotNull();
|
||||
Check.That(mappings.First().Guid).Equals(Guid.Parse(guid));
|
||||
Check.That(mappings.First().Title).IsNullOrEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FluentMockServer_ReadStaticMappings()
|
||||
{
|
||||
@@ -85,7 +114,7 @@ namespace WireMock.Net.Tests
|
||||
_server.ReadStaticMappings(folder);
|
||||
|
||||
var mappings = _server.Mappings.ToArray();
|
||||
Check.That(mappings).HasSize(2);
|
||||
Check.That(mappings).HasSize(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -232,6 +261,40 @@ namespace WireMock.Net.Tests
|
||||
Check.That(response).IsEqualTo("Hello world!");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_respond_to_request_BodyAsJson()
|
||||
{
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Request.Create().UsingAnyVerb())
|
||||
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }));
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0]);
|
||||
|
||||
// Assert
|
||||
Check.That(response).IsEqualTo("{\"message\":\"Hello\"}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_respond_to_request_BodyAsJson_Indented()
|
||||
{
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server
|
||||
.Given(Request.Create().UsingAnyVerb())
|
||||
.RespondWith(Response.Create().WithBodyAsJson(new { message = "Hello" }, true));
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + _server.Ports[0]);
|
||||
|
||||
// Assert
|
||||
Check.That(response).IsEqualTo("{\r\n \"message\": \"Hello\"\r\n}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_respond_to_request_bodyAsCallback()
|
||||
{
|
||||
@@ -482,6 +545,24 @@ namespace WireMock.Net.Tests
|
||||
Check.That(response).IsEqualTo("/fooBar");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FluentMockServer_Should_IgnoreRestrictedHeader()
|
||||
{
|
||||
// Assign
|
||||
_server = FluentMockServer.Start();
|
||||
_server
|
||||
.Given(Request.Create().WithPath("/head").UsingHead())
|
||||
.RespondWith(Response.Create().WithHeader("Content-Length", "1024"));
|
||||
|
||||
var request = new HttpRequestMessage(HttpMethod.Head, "http://localhost:" + _server.Ports[0] + "/head");
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().SendAsync(request);
|
||||
|
||||
// Assert
|
||||
Check.That(response.Content.Headers.GetValues("Content-Length")).ContainsExactly("0");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_server?.Stop();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using NFluent;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -31,5 +32,104 @@ namespace WireMock.Net.Tests.Matchers
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string s = null;
|
||||
var matcher = new JsonPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object o = null;
|
||||
var matcher = new JsonPathMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_String_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPathMatcher("xxx");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_Object_Exception_Mismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPathMatcher("xxx");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch("");
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_AnonymousObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPathMatcher("$..[?(@.Id == 1)]");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
string[] patterns = { "$..[?(@.Id == 1)]" };
|
||||
var matcher = new JsonPathMatcher(patterns);
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPathMatcher_IsMatch_JObject_Parsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPathMatcher("$..[?(@.Id == 1)]");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(JObject.Parse("{\"Id\":1,\"Name\":\"Test\"}"));
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RequestMatchers
|
||||
{
|
||||
public class RequestMessageBodyMatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsString_IStringMatcher()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsString = "b"
|
||||
};
|
||||
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 matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
|
||||
stringMatcherMock.Verify(m => m.IsMatch("b"), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IStringMatcher()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsBytes = new byte[] { 1 }
|
||||
};
|
||||
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 matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.GetPatterns(), Times.Never);
|
||||
stringMatcherMock.Verify(m => m.IsMatch(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IStringMatcher()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsJson = new { value = 42 }
|
||||
};
|
||||
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 matcher = new RequestMessageBodyMatcher(stringMatcherMock.Object);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.0d);
|
||||
|
||||
// Verify
|
||||
stringMatcherMock.Verify(m => m.IsMatch("b"), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsJson_IObjectMatcher()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsJson = 42
|
||||
};
|
||||
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 matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
|
||||
// Verify
|
||||
objectMatcherMock.Verify(m => m.IsMatch(42), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessageBodyMatcher_GetMatchingScore_BodyAsBytes_IObjectMatcher()
|
||||
{
|
||||
// Assign
|
||||
var body = new BodyData
|
||||
{
|
||||
BodyAsBytes = new byte[] { 1 }
|
||||
};
|
||||
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 matcher = new RequestMessageBodyMatcher(objectMatcherMock.Object);
|
||||
|
||||
// Act
|
||||
var result = new RequestMatchResult();
|
||||
double score = matcher.GetMatchingScore(requestMessage, result);
|
||||
|
||||
// Assert
|
||||
Check.That(score).IsEqualTo(0.5d);
|
||||
|
||||
// Verify
|
||||
objectMatcherMock.Verify(m => m.IsMatch(It.IsAny<byte[]>()), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
@@ -50,5 +51,25 @@ namespace WireMock.Net.Tests
|
||||
Check.That(request.GetParameter("key")).Contains("2");
|
||||
Check.That(request.GetParameter("key")).Contains("3");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor1_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp);
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestMessage_Constructor2_PathSegments()
|
||||
{
|
||||
// Assign
|
||||
var request = new RequestMessage(new Uri("http://localhost/a/b/c"), "POST", ClientIp, new BodyData());
|
||||
|
||||
// Assert
|
||||
Check.That(request.PathSegments).ContainsExactly("a", "b", "c");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ namespace WireMock.Net.Tests
|
||||
public void Request_WithBodyJsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string bodyAsString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
@@ -179,7 +179,7 @@ namespace WireMock.Net.Tests
|
||||
public void Request_WithBodyAsJson_Object_JsonPathMatcher_true()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.things[?(@.name == 'RequiredThing')]"));
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..things[?(@.name == 'RequiredThing')]"));
|
||||
|
||||
// when
|
||||
string jsonString = "{ \"things\": [ { \"name\": \"RequiredThing\" }, { \"name\": \"Wiremock\" } ] }";
|
||||
@@ -199,7 +199,7 @@ namespace WireMock.Net.Tests
|
||||
public void Request_WithBodyAsJson_Array_JsonPathMatcher_1()
|
||||
{
|
||||
// given
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$.books[?(@.price < 10)]"));
|
||||
var spec = Request.Create().UsingAnyVerb().WithBody(new JsonPathMatcher("$..books[?(@.price < 10)]"));
|
||||
|
||||
// when
|
||||
string jsonString = "{ \"books\": [ { \"category\": \"test1\", \"price\": 8.95 }, { \"category\": \"test2\", \"price\": 20 } ] }";
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"test": "test"
|
||||
}
|
||||
26
test/WireMock.Net.Tests/ResponseTests.cs
Normal file
26
test/WireMock.Net.Tests/ResponseTests.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.ResponseBuilders;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
public class ResponseTests
|
||||
{
|
||||
private const string ClientIp = "::1";
|
||||
|
||||
[Fact]
|
||||
public async void Response_Create_WithHeader_ContentLength()
|
||||
{
|
||||
// Assign
|
||||
var requestMock = new RequestMessage(new Uri("http://localhost/foo"), "PUT", ClientIp);
|
||||
IResponseBuilder builder = Response.Create().WithHeader("Content-Length", "1024");
|
||||
|
||||
// Act
|
||||
var response = await builder.ProvideResponseAsync(requestMock);
|
||||
|
||||
// Assert
|
||||
Check.That(response.Headers["Content-Length"].ToString()).Equals("1024");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,9 +31,15 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="ResponseBodyFiles\responsebody.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d86.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings\00000002-ee28-4f29-ae63-1ac9b0802d87.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="__admin\mappings\documentdb_root.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Guid": "00000002-ee28-4f29-ae63-1ac9b0802d87",
|
||||
"Priority": 0,
|
||||
"Request": {
|
||||
"Path": {
|
||||
"Matchers": [
|
||||
{
|
||||
"Name": "ExactMatcher",
|
||||
"Pattern": "/response/staticfile"
|
||||
}
|
||||
]
|
||||
},
|
||||
"Methods": [
|
||||
"get"
|
||||
]
|
||||
},
|
||||
"Response": {
|
||||
"StatusCode": 200,
|
||||
"BodyAsFile": "responsebody.json",
|
||||
"Headers": {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user