mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6c36bc23b | ||
|
|
6b393ebc1d | ||
|
|
60bdc06d29 | ||
|
|
0f1a4f32ef | ||
|
|
e3a693ede7 | ||
|
|
b153024de3 | ||
|
|
e8e28c21a1 | ||
|
|
fd1f4968b4 |
12
CHANGELOG.md
12
CHANGELOG.md
@@ -1,3 +1,11 @@
|
||||
# 1.4.32 (17 January 2022)
|
||||
- [#713](https://github.com/WireMock-Net/WireMock.Net/pull/713) - Added support of custom matchers in static mappings contributed by [levanoz](https://github.com/levanoz)
|
||||
|
||||
# 1.4.31 (06 January 2022)
|
||||
- [#706](https://github.com/WireMock-Net/WireMock.Net/pull/706) - Provide open api schema to dynamic examples generator so you can generate accurate data [feature] contributed by [brunotarghetta](https://github.com/brunotarghetta)
|
||||
- [#707](https://github.com/WireMock-Net/WireMock.Net/pull/707) - Use NuGet "Stef.Validation" [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#710](https://github.com/WireMock-Net/WireMock.Net/pull/710) - Add ReplaceNodeOption flag [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
# 1.4.30 (25 December 2021)
|
||||
- [#703](https://github.com/WireMock-Net/WireMock.Net/pull/703) - SaveUnmatchedRequests [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#704](https://github.com/WireMock-Net/WireMock.Net/pull/704) - Add .ConfigureAwait(false); to the await Task calls [bug] contributed by [StefH](https://github.com/StefH)
|
||||
@@ -158,7 +166,6 @@
|
||||
- [#549](https://github.com/WireMock-Net/WireMock.Net/issues/549) - WithProxy(...) does not save the mappings to file [bug]
|
||||
|
||||
# 1.3.8 (03 December 2020)
|
||||
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
|
||||
- [#542](https://github.com/WireMock-Net/WireMock.Net/pull/542) - Create dotnet-wiremock tool [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#543](https://github.com/WireMock-Net/WireMock.Net/pull/543) - Add support for .NET 5 [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#544](https://github.com/WireMock-Net/WireMock.Net/pull/544) - Use Java 11 in Azure Pipelines (needed for SonarCloud) [feature] contributed by [StefH](https://github.com/StefH)
|
||||
@@ -166,6 +173,9 @@
|
||||
- [#547](https://github.com/WireMock-Net/WireMock.Net/pull/547) - Fix Proxying with SSL and NetCoreApp3.1 [bug] contributed by [StefH](https://github.com/StefH)
|
||||
- [#524](https://github.com/WireMock-Net/WireMock.Net/issues/524) - Proxying with SSL Not Working in .NET Core 3.1 [bug]
|
||||
|
||||
# 1.3.7 (17 November 2020)
|
||||
- [#539](https://github.com/WireMock-Net/WireMock.Net/pull/539) - Support for partial JSON matching contributed by [gleb-osokin](https://github.com/gleb-osokin)
|
||||
|
||||
# 1.3.6 (10 November 2020)
|
||||
- [#529](https://github.com/WireMock-Net/WireMock.Net/pull/529) - Add assertions for ClientIP, Url and ProxyUrl [feature] contributed by [akamud](https://github.com/akamud)
|
||||
- [#535](https://github.com/WireMock-Net/WireMock.Net/pull/535) - WithCallback should use also use enum HttpStatusCode [bug] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.4.30</VersionPrefix>
|
||||
<VersionPrefix>1.4.32</VersionPrefix>
|
||||
<PackageReleaseNotes>See CHANGELOG.md</PackageReleaseNotes>
|
||||
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
|
||||
<PackageProjectUrl>https://github.com/WireMock-Net/WireMock.Net</PackageProjectUrl>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
rem https://github.com/StefH/GitHubReleaseNotes
|
||||
|
||||
SET version=1.4.30
|
||||
SET version=1.4.32
|
||||
|
||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
||||
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
# 1.4.30 (25 December 2021)
|
||||
- #703 SaveUnmatchedRequests [feature]
|
||||
- #704 Add .ConfigureAwait(false); to the await Task calls [bug]
|
||||
- #534 Mock server not answer if integrated in Xamarin UITest project [bug]
|
||||
- #567 Can't start WireMock.Net server in Xamarin.UITest project (.NET Framework 4.7.2) on MacOS [bug]
|
||||
- #685 GuidWildcardMatcher to match on GUIDs [feature]
|
||||
# 1.4.32 (17 January 2022)
|
||||
- #713 Added support of custom matchers in static mappings
|
||||
|
||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||
@@ -28,7 +28,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\WireMock.Net\WireMock.Net.csproj" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers" Version="2.*" />
|
||||
<PackageReference Include="log4net" Version="2.0.12" />
|
||||
<PackageReference Include="log4net" Version="2.0.13" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.*" />
|
||||
<PackageReference Include="log4net" Version="2.0.10" />
|
||||
<PackageReference Include="log4net" Version="2.0.13" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.*" />
|
||||
<PackageReference Include="log4net" Version="2.0.10" />
|
||||
<PackageReference Include="log4net" Version="2.0.13" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<PackageReference Include="Handlebars.Net.Helpers.XPath" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Xeger" Version="2.*" />
|
||||
<PackageReference Include="Handlebars.Net.Helpers.Random" Version="2.*" />
|
||||
<PackageReference Include="log4net" Version="2.0.12" />
|
||||
<PackageReference Include="log4net" Version="2.0.13" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
using Newtonsoft.Json;
|
||||
using HandlebarsDotNet;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.ConsoleApplication
|
||||
{
|
||||
@@ -359,7 +357,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.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}}, add={{Math.Add request.query.start.[0] 42}} bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }")
|
||||
.WithTransformer(TransformerType.Handlebars)
|
||||
.WithTransformer(TransformerType.Handlebars, true, ReplaceNodeOptions.None)
|
||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||
);
|
||||
|
||||
|
||||
@@ -48,8 +48,8 @@
|
||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.1.1-preview-01\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.13\lib\net45\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Owin.Host.HttpListener, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<package id="Handlebars.Net" version="2.0.4" targetFramework="net452" />
|
||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net452" />
|
||||
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net452" />
|
||||
<package id="log4net" version="2.0.12" targetFramework="net452" />
|
||||
<package id="log4net" version="2.0.13" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="3.1.0" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net452" />
|
||||
|
||||
@@ -47,8 +47,8 @@
|
||||
<Reference Include="HandlebarsDotNet.Helpers.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=00d131fae0c250bc, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Handlebars.Net.Helpers.Core.2.1.1-preview-01\lib\net452\HandlebarsDotNet.Helpers.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.13\lib\net45\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<package id="Handlebars.Net" version="2.0.4" targetFramework="net461" />
|
||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net461" />
|
||||
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net461" />
|
||||
<package id="log4net" version="2.0.12" targetFramework="net461" />
|
||||
<package id="log4net" version="2.0.13" targetFramework="net461" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.2.0" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
|
||||
<package id="SimMetrics.Net" version="1.0.5" targetFramework="net461" />
|
||||
|
||||
@@ -57,8 +57,8 @@
|
||||
<Reference Include="JmesPath.Net, Version=1.0.125.0, Culture=neutral, PublicKeyToken=b29d616b7f4faff0, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\JmesPath.Net.1.0.125\lib\net45\JmesPath.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.13\lib\net45\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNetCore, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Microsoft.AspNetCore.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.dll</HintPath>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<package id="Handlebars.Net.Helpers" version="2.1.1-preview-01" targetFramework="net472" />
|
||||
<package id="Handlebars.Net.Helpers.Core" version="2.1.1-preview-01" targetFramework="net472" />
|
||||
<package id="JmesPath.Net" version="1.0.125" targetFramework="net472" />
|
||||
<package id="log4net" version="2.0.12" targetFramework="net461" />
|
||||
<package id="log4net" version="2.0.13" targetFramework="net472" />
|
||||
<package id="Microsoft.AspNetCore" version="2.2.0" targetFramework="net472" />
|
||||
<package id="Microsoft.AspNetCore.Authentication.Abstractions" version="2.2.0" targetFramework="net472" />
|
||||
<package id="Microsoft.AspNetCore.Authentication.Core" version="2.2.0" targetFramework="net472" />
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using RandomDataGenerator.FieldOptions;
|
||||
using RandomDataGenerator.Randomizers;
|
||||
using WireMock.Net.OpenApiParser.Settings;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
{
|
||||
public class DynamicDataGeneration : WireMockOpenApiParserDynamicExampleValues
|
||||
{
|
||||
public override string String
|
||||
{
|
||||
get
|
||||
{
|
||||
//Since you have your Schema, you can get if max-lenght is set. You can generate accurate examples with this settings
|
||||
var maxLength = this.Schema.MaxLength ?? 9;
|
||||
|
||||
return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex
|
||||
{
|
||||
Pattern = $"[0-9A-Z]{{{maxLength}}}"
|
||||
}).Generate() ?? "example-string";
|
||||
}
|
||||
set { }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "customer",
|
||||
"description": "It contains basic customer actions.",
|
||||
"version": "v1"
|
||||
},
|
||||
"host": "localhost",
|
||||
"basePath": "/v1/customer/",
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"paths": {
|
||||
"/": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "Correlation-Id",
|
||||
"required": true,
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"maxLength": 3
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"x-amf-mediaType": "application/json",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ResponseCustmer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"ResponseCustmer": {
|
||||
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"required": [
|
||||
"first-name",
|
||||
"last-name",
|
||||
"status",
|
||||
"interest"
|
||||
],
|
||||
"properties": {
|
||||
"first-name": {
|
||||
"type": "string"
|
||||
},
|
||||
"last-name": {
|
||||
"type": "string"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"maxLength": 2
|
||||
},
|
||||
"interest": {
|
||||
"type": "string",
|
||||
"maxLength": 45
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,59 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Microsoft.OpenApi.Readers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private const string Folder = "OpenApiFiles";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "https://localhost:9091/");
|
||||
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "https://localhost:9092/");
|
||||
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "https://localhost:9093/");
|
||||
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "https://localhost:9094/");
|
||||
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "https://localhost:9095/");
|
||||
|
||||
Console.WriteLine("Press any key to stop the servers");
|
||||
Console.ReadKey();
|
||||
|
||||
serverOpenAPIExamples.Stop();
|
||||
serverPetstore_V2_json.Stop();
|
||||
serverPetstore_V2_yaml.Stop();
|
||||
serverPetstore_V300_yaml.Stop();
|
||||
serverPetstore_V302_json.Stop();
|
||||
|
||||
//IWireMockOpenApiParser parser = new WireMockOpenApiParser();
|
||||
|
||||
//var petStoreModels = parser.FromStream(File.OpenRead("petstore-openapi3.json"), out OpenApiDiagnostic diagnostic1);
|
||||
//string petStoreJson = JsonConvert.SerializeObject(petStoreModels, Settings);
|
||||
// File.WriteAllText("../../../wiremock-petstore-openapi3.json", petStoreJson);
|
||||
|
||||
//Run.RunServer(petStoreModels);
|
||||
|
||||
//var mappingModels2 = parser.FromStream(File.OpenRead("infura.yaml"), out OpenApiDiagnostic diagnostic2);
|
||||
//Console.WriteLine(JsonConvert.SerializeObject(diagnostic2, Settings));
|
||||
|
||||
//string json2 = JsonConvert.SerializeObject(mappingModels2, Settings);
|
||||
//Console.WriteLine(json2);
|
||||
{
|
||||
//RunOthersOpenApiParserExample();
|
||||
|
||||
RunMockServerWithDynamicExampleGeneration();
|
||||
}
|
||||
|
||||
private static void RunMockServerWithDynamicExampleGeneration() {
|
||||
//Run your mocking framework specifieing youur Example Values generator class.
|
||||
var serverCustomer_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Customer_V2.0.json"), "http://localhost:8090/", true, new DynamicDataGeneration(), Types.ExampleValueType.Value, Types.ExampleValueType.Value);
|
||||
Console.WriteLine("Press any key to stop the servers");
|
||||
|
||||
Console.ReadKey();
|
||||
serverCustomer_V2_json.Stop();
|
||||
}
|
||||
|
||||
private static void RunOthersOpenApiParserExample()
|
||||
{
|
||||
var serverOpenAPIExamples = Run.RunServer(Path.Combine(Folder, "openAPIExamples.yaml"), "https://localhost:9091/");
|
||||
var serverPetstore_V2_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.json"), "https://localhost:9092/");
|
||||
var serverPetstore_V2_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V2.0.yaml"), "https://localhost:9093/");
|
||||
var serverPetstore_V300_yaml = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.0.yaml"), "https://localhost:9094/");
|
||||
var serverPetstore_V302_json = Run.RunServer(Path.Combine(Folder, "Swagger_Petstore_V3.0.2.json"), "https://localhost:9095/");
|
||||
|
||||
Console.WriteLine("Press any key to stop the servers");
|
||||
Console.ReadKey();
|
||||
|
||||
serverOpenAPIExamples.Stop();
|
||||
serverPetstore_V2_json.Stop();
|
||||
serverPetstore_V2_yaml.Stop();
|
||||
serverPetstore_V300_yaml.Stop();
|
||||
serverPetstore_V302_json.Stop();
|
||||
|
||||
//IWireMockOpenApiParser parser = new WireMockOpenApiParser();
|
||||
|
||||
//var petStoreModels = parser.FromStream(File.OpenRead("petstore-openapi3.json"), out OpenApiDiagnostic diagnostic1);
|
||||
//string petStoreJson = JsonConvert.SerializeObject(petStoreModels, Settings);
|
||||
// File.WriteAllText("../../../wiremock-petstore-openapi3.json", petStoreJson);
|
||||
|
||||
//Run.RunServer(petStoreModels);
|
||||
|
||||
//var mappingModels2 = parser.FromStream(File.OpenRead("infura.yaml"), out OpenApiDiagnostic diagnostic2);
|
||||
//Console.WriteLine(JsonConvert.SerializeObject(diagnostic2, Settings));
|
||||
|
||||
//string json2 = JsonConvert.SerializeObject(mappingModels2, Settings);
|
||||
//Console.WriteLine(json2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,28 +13,30 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
{
|
||||
public static class Run
|
||||
{
|
||||
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true)
|
||||
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true, IWireMockOpenApiParserExampleValues examplesValuesGenerator = null, ExampleValueType pathPatternToUse = ExampleValueType.Wildcard, ExampleValueType headerPatternToUse = ExampleValueType.Wildcard)
|
||||
{
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
ReadStaticMappings = true,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
SaveUnmatchedRequests = true
|
||||
});
|
||||
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
server.SetBasicAuthentication("a", "b");
|
||||
//server.SetBasicAuthentication("a", "b");
|
||||
|
||||
var settings = new WireMockOpenApiParserSettings
|
||||
{
|
||||
DynamicExamples = dynamicExamples,
|
||||
PathPatternToUse = ExampleValueType.Wildcard,
|
||||
HeaderPatternToUse = ExampleValueType.Wildcard
|
||||
ExampleValues = examplesValuesGenerator,
|
||||
PathPatternToUse = pathPatternToUse,
|
||||
HeaderPatternToUse = headerPatternToUse,
|
||||
};
|
||||
|
||||
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||
|
||||
@@ -36,6 +36,9 @@
|
||||
<None Update="petstore.yml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\Swagger_Customer_V2.0.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -32,8 +32,8 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.13\lib\net45\log4net.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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.12" targetFramework="net452" />
|
||||
<package id="log4net" version="2.0.13" 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" />
|
||||
|
||||
@@ -1,79 +1,109 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
using log4net.Repository;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using log4net;
|
||||
using log4net.Config;
|
||||
using log4net.Repository;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
||||
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||
|
||||
private static int sleepTime = 30000;
|
||||
private static WireMockServer _server;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
|
||||
|
||||
|
||||
namespace WireMock.Net.StandAlone.NETCoreApp
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
|
||||
// private static readonly ILog Log = LogManager.GetLogger(typeof(Program));
|
||||
|
||||
private static int sleepTime = 30000;
|
||||
private static WireMockServer _server;
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
|
||||
|
||||
if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
_server = WireMockServer.Start(settings);
|
||||
|
||||
settings.Logger.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
/* https://stackoverflow.com/questions/31942037/how-to-enable-cors-in-asp-net-core */
|
||||
/* Enable Cors */
|
||||
var policyName = "MyPolicy";
|
||||
settings.AdditionalServiceRegistration = services =>
|
||||
{
|
||||
services.AddCors(corsOptions =>
|
||||
corsOptions.AddPolicy(policyName,
|
||||
corsPolicyBuilder =>
|
||||
{
|
||||
corsPolicyBuilder
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyOrigin();
|
||||
}));
|
||||
|
||||
settings.Logger.Debug("Enable Cors");
|
||||
};
|
||||
|
||||
/* Use Cors */
|
||||
settings.PreWireMockMiddlewareInit = app =>
|
||||
{
|
||||
var appBuilder = (IApplicationBuilder)app;
|
||||
appBuilder.UseCors(policyName);
|
||||
|
||||
settings.Logger.Debug("Use Cors");
|
||||
};
|
||||
|
||||
_server = WireMockServer.Start(settings);
|
||||
|
||||
_server.Given(Request.Create().WithPath("/api/sap")
|
||||
.UsingPost()
|
||||
.WithBody((IBodyData xmlData) => {
|
||||
.WithBody((IBodyData xmlData) =>
|
||||
{
|
||||
//xmlData is always null
|
||||
return true;
|
||||
}))
|
||||
.RespondWith(Response.Create().WithStatusCode(System.Net.HttpStatusCode.OK));
|
||||
|
||||
_server
|
||||
.Given(Request.Create()
|
||||
.UsingAnyMethod())
|
||||
.RespondWith(Response.Create()
|
||||
.WithTransformer()
|
||||
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
|
||||
|
||||
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
Stop("CancelKeyPress");
|
||||
};
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||
{
|
||||
Stop("AssemblyLoadContext.Default.Unloading");
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
|
||||
Thread.Sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
|
||||
_server.Stop();
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
_server
|
||||
.Given(Request.Create()
|
||||
.UsingAnyMethod())
|
||||
.RespondWith(Response.Create()
|
||||
.WithTransformer()
|
||||
.WithBody("{{Random Type=\"Integer\" Min=100 Max=999999}} {{DateTime.Now}} {{DateTime.Now \"yyyy-MMM\"}} {{String.Format (DateTime.Now) \"MMM-dd\"}}"));
|
||||
|
||||
Console.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
Stop("CancelKeyPress");
|
||||
};
|
||||
|
||||
System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += ctx =>
|
||||
{
|
||||
Stop("AssemblyLoadContext.Default.Unloading");
|
||||
};
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server running : {_server.IsStarted}");
|
||||
Thread.Sleep(sleepTime);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopping because '{why}'");
|
||||
_server.Stop();
|
||||
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="log4net" Version="2.0.10" />
|
||||
<PackageReference Include="log4net" Version="2.0.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -39,8 +39,8 @@
|
||||
<StartupObject>WireMock.Net.StandAlone.Net452.Program</StartupObject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
|
||||
<Reference Include="log4net, Version=2.0.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\log4net.2.0.13\lib\net45\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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.12" targetFramework="net452" />
|
||||
<package id="log4net" version="2.0.13" targetFramework="net452" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net452" />
|
||||
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.0" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net452" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
@@ -64,10 +64,15 @@ namespace WireMock.Admin.Mappings
|
||||
public string TransformerType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use the Handlerbars transformer for the content from the referenced BodyAsFile.
|
||||
/// Use the Handlebars transformer for the content from the referenced BodyAsFile.
|
||||
/// </summary>
|
||||
public bool? UseTransformerForBodyAsFile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ReplaceNodeOptions to use when transforming a JSON node.
|
||||
/// </summary>
|
||||
public string TransformerReplaceNodeOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the headers.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
@@ -42,5 +43,10 @@ namespace WireMock.Admin.Mappings
|
||||
/// Gets the type of the transformer.
|
||||
/// </summary>
|
||||
public string TransformerType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ReplaceNodeOptions to use when transforming a JSON node.
|
||||
/// </summary>
|
||||
public string TransformerReplaceNodeOptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace WireMock.Models
|
||||
{
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// IWebhook
|
||||
/// </summary>
|
||||
public interface IWebhook
|
||||
/// </summary>
|
||||
public interface IWebhook
|
||||
{
|
||||
/// <summary>
|
||||
/// Request
|
||||
/// </summary>
|
||||
IWebhookRequest Request { get; set; }
|
||||
}
|
||||
/// </summary>
|
||||
IWebhookRequest Request { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,42 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// IWebhookRequest
|
||||
/// </summary>
|
||||
public interface IWebhookRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The Webhook Url.
|
||||
/// </summary>
|
||||
string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The method to use.
|
||||
/// </summary>
|
||||
string Method { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Headers to send.
|
||||
/// </summary>
|
||||
IDictionary<string, WireMockList<string>> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body to send.
|
||||
/// </summary>
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// IWebhookRequest
|
||||
/// </summary>
|
||||
public interface IWebhookRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// The Webhook Url.
|
||||
/// </summary>
|
||||
string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The method to use.
|
||||
/// </summary>
|
||||
string Method { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Headers to send.
|
||||
/// </summary>
|
||||
IDictionary<string, WireMockList<string>> Headers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The body to send.
|
||||
/// </summary>
|
||||
IBodyData BodyData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use Transformer.
|
||||
/// </summary>
|
||||
bool? UseTransformer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The transformer type.
|
||||
/// </summary>
|
||||
TransformerType TransformerType { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Use Transformer.
|
||||
/// </summary>
|
||||
bool? UseTransformer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The transformer type.
|
||||
/// </summary>
|
||||
TransformerType TransformerType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ReplaceNodeOptions to use when transforming a JSON node.
|
||||
/// </summary>
|
||||
ReplaceNodeOptions TransformerReplaceNodeOptions { get; set; }
|
||||
}
|
||||
}
|
||||
36
src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs
Normal file
36
src/WireMock.Net.Abstractions/Types/ReplaceNodeOptions.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Flags to use when replace a JSON node using the Transformer.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum ReplaceNodeOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Default
|
||||
/// </summary>
|
||||
None = 0
|
||||
|
||||
///// <summary>
|
||||
///// Replace boolean string value to a real boolean value. (This is used by default to maintain backward compatibility.)
|
||||
///// </summary>
|
||||
//Bool = 0b00000001,
|
||||
|
||||
///// <summary>
|
||||
///// Replace integer string value to a real integer value.
|
||||
///// </summary>
|
||||
//Integer = 0b00000010,
|
||||
|
||||
///// <summary>
|
||||
///// Replace long string value to a real long value.
|
||||
///// </summary>
|
||||
//Long = 0b00000100,
|
||||
|
||||
///// <summary>
|
||||
///// Replace all string values to a real values.
|
||||
///// </summary>
|
||||
//All = Bool | Integer | Long
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using Newtonsoft.Json.Linq;
|
||||
using WireMock.Exceptions;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -53,7 +53,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
public CSharpCodeMatcher(MatchBehaviour matchBehaviour, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Settings
|
||||
{
|
||||
/// <summary>
|
||||
@@ -48,5 +49,10 @@ namespace WireMock.Net.OpenApiParser.Settings
|
||||
/// An example value for a String.
|
||||
/// </summary>
|
||||
string String { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// OpenApi Schema to generate dynamic examples more accurate
|
||||
/// </summary>
|
||||
OpenApiSchema Schema { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using RandomDataGenerator.FieldOptions;
|
||||
using RandomDataGenerator.Randomizers;
|
||||
|
||||
@@ -10,22 +11,24 @@ namespace WireMock.Net.OpenApiParser.Settings
|
||||
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public bool Boolean { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; } set { } }
|
||||
public virtual bool Boolean { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; } set { } }
|
||||
/// <inheritdoc />
|
||||
public int Integer { get { return RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42; } set { } }
|
||||
public virtual int Integer { get { return RandomizerFactory.GetRandomizer(new FieldOptionsInteger()).Generate() ?? 42; } set { } }
|
||||
/// <inheritdoc />
|
||||
public float Float { get { return RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f; } set { } }
|
||||
public virtual float Float { get { return RandomizerFactory.GetRandomizer(new FieldOptionsFloat()).Generate() ?? 4.2f; } set { } }
|
||||
/// <inheritdoc />
|
||||
public double Double { get { return RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d; } set { } }
|
||||
public virtual double Double { get { return RandomizerFactory.GetRandomizer(new FieldOptionsDouble()).Generate() ?? 4.2d; } set { } }
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } set { } }
|
||||
public virtual Func<DateTime> Date { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow.Date; } set { } }
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } set { } }
|
||||
public virtual Func<DateTime> DateTime { get { return () => RandomizerFactory.GetRandomizer(new FieldOptionsDateTime()).Generate() ?? System.DateTime.UtcNow; } set { } }
|
||||
/// <inheritdoc />
|
||||
public byte[] Bytes { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate(); } set { } }
|
||||
public virtual byte[] Bytes { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBytes()).Generate(); } set { } }
|
||||
/// <inheritdoc />
|
||||
public object Object { get; set; } = "example-object";
|
||||
public virtual object Object { get; set; } = "example-object";
|
||||
/// <inheritdoc />
|
||||
public string String { get { return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; } set { } }
|
||||
public virtual string String { get { return RandomizerFactory.GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^[0-9]{2}[A-Z]{5}[0-9]{2}" }).Generate() ?? "example-string"; } set { } }
|
||||
/// <inheritdoc />
|
||||
public virtual OpenApiSchema Schema { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Settings
|
||||
{
|
||||
/// <summary>
|
||||
@@ -8,22 +9,24 @@ namespace WireMock.Net.OpenApiParser.Settings
|
||||
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public bool Boolean { get; set; } = true;
|
||||
public virtual bool Boolean { get; set; } = true;
|
||||
/// <inheritdoc />
|
||||
public int Integer { get; set; } = 42;
|
||||
public virtual int Integer { get; set; } = 42;
|
||||
/// <inheritdoc />
|
||||
public float Float { get; set; } = 4.2f;
|
||||
public virtual float Float { get; set; } = 4.2f;
|
||||
/// <inheritdoc />
|
||||
public double Double { get; set; } = 4.2d;
|
||||
public virtual double Double { get; set; } = 4.2d;
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
|
||||
public virtual Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
|
||||
public virtual Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
|
||||
/// <inheritdoc />
|
||||
public byte[] Bytes { get; set; } = { 48, 49, 50 };
|
||||
public virtual byte[] Bytes { get; set; } = { 48, 49, 50 };
|
||||
/// <inheritdoc />
|
||||
public object Object { get; set; } = "example-object";
|
||||
public virtual object Object { get; set; } = "example-object";
|
||||
/// <inheritdoc />
|
||||
public string String { get; set; } = "example-string";
|
||||
public virtual string String { get; set; } = "example-string";
|
||||
/// <inheritdoc />
|
||||
public virtual OpenApiSchema Schema { get; set; } = new OpenApiSchema();
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,8 @@ namespace WireMock.Net.OpenApiParser.Utils
|
||||
var schemaExample = schema?.Example;
|
||||
var schemaEnum = GetRandomEnumValue(schema?.Enum);
|
||||
|
||||
_settings.ExampleValues.Schema = schema;
|
||||
|
||||
switch (schema?.GetSchemaType())
|
||||
{
|
||||
case SchemaType.Boolean:
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||
<PackageReference Include="Stef.Validation" Version="0.0.4" />
|
||||
<PackageReference Include="Stef.Validation" Version="0.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@ using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Server;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Net.StandAlone
|
||||
{
|
||||
@@ -22,7 +22,7 @@ namespace WireMock.Net.StandAlone
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
var server = WireMockServer.Start(settings);
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace WireMock.Net.StandAlone
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start([NotNull] string[] args, [CanBeNull] IWireMockLogger logger = null)
|
||||
{
|
||||
Check.NotNull(args, nameof(args));
|
||||
Guard.NotNull(args, nameof(args));
|
||||
|
||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace WireMock.Net.StandAlone
|
||||
[PublicAPI]
|
||||
public static bool TryStart([NotNull] string[] args, out WireMockServer server, [CanBeNull] IWireMockLogger logger = null)
|
||||
{
|
||||
Check.NotNull(args, nameof(args));
|
||||
Guard.NotNull(args, nameof(args));
|
||||
|
||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Handlers
|
||||
{
|
||||
@@ -34,7 +34,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/>
|
||||
public virtual bool FolderExists(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
@@ -42,7 +42,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.CreateFolder"/>
|
||||
public virtual void CreateFolder(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/>
|
||||
public virtual IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
return includeSubdirectories ? Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) : Directory.EnumerateFiles(path);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/>
|
||||
public virtual string ReadMappingFile(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
@@ -72,8 +72,8 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteMappingFile(string, string)"/>
|
||||
public virtual void WriteMappingFile(string path, string text)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Check.NotNull(text, nameof(text));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNull(text, nameof(text));
|
||||
|
||||
File.WriteAllText(path, text);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsFile"/>
|
||||
public virtual byte[] ReadResponseBodyAsFile(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
path = PathUtils.CleanPath(path);
|
||||
// If the file exists at the given path relative to the MappingsFolder, then return that.
|
||||
// Else the path will just be as-is.
|
||||
@@ -91,7 +91,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsString"/>
|
||||
public virtual string ReadResponseBodyAsString(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Guard.NotNullOrEmpty(path, nameof(path));
|
||||
path = PathUtils.CleanPath(path);
|
||||
// In case the path is a filename, the path will be adjusted to the MappingFolder.
|
||||
// Else the path will just be as-is.
|
||||
@@ -101,7 +101,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.FileExists"/>
|
||||
public virtual bool FileExists(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
return File.Exists(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
@@ -109,8 +109,8 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteFile(string, byte[])"/>
|
||||
public virtual void WriteFile(string filename, byte[] bytes)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Check.NotNull(bytes, nameof(bytes));
|
||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||
Guard.NotNull(bytes, nameof(bytes));
|
||||
|
||||
File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes);
|
||||
}
|
||||
@@ -118,7 +118,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
||||
public virtual void DeleteFile(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
File.Delete(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
@@ -126,7 +126,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadFile"/>
|
||||
public virtual byte[] ReadFile(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
return File.ReadAllBytes(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
@@ -134,7 +134,7 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadFileAsString"/>
|
||||
public virtual string ReadFileAsString(string filename)
|
||||
{
|
||||
return File.ReadAllText(AdjustPathForMappingFolder(Check.NotNullOrEmpty(filename, nameof(filename))));
|
||||
return File.ReadAllText(AdjustPathForMappingFolder(Guard.NotNullOrEmpty(filename, nameof(filename))));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.GetUnmatchedRequestsFolder"/>
|
||||
@@ -146,8 +146,8 @@ namespace WireMock.Handlers
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteUnmatchedRequest"/>
|
||||
public virtual void WriteUnmatchedRequest(string filename, string text)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Check.NotNull(text, nameof(text));
|
||||
Guard.NotNullOrEmpty(filename, nameof(filename));
|
||||
Guard.NotNull(text, nameof(text));
|
||||
|
||||
var folder = GetUnmatchedRequestsFolder();
|
||||
if (!FolderExists(folder))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
@@ -15,7 +15,7 @@ namespace WireMock.Http
|
||||
/// <returns>ByteArrayContent</returns>
|
||||
internal static ByteArrayContent Create([NotNull] byte[] content, [CanBeNull] MediaTypeHeaderValue contentType)
|
||||
{
|
||||
Check.NotNull(content, nameof(content));
|
||||
Guard.NotNull(content, nameof(content));
|
||||
|
||||
var byteContent = new ByteArrayContent(content);
|
||||
if (contentType != null)
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Net.Http.Headers;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
@@ -14,8 +14,8 @@ namespace WireMock.Http
|
||||
{
|
||||
internal static HttpRequestMessage Create([NotNull] RequestMessage requestMessage, [NotNull] string url)
|
||||
{
|
||||
Check.NotNull(requestMessage, nameof(requestMessage));
|
||||
Check.NotNullOrEmpty(url, nameof(url));
|
||||
Guard.NotNull(requestMessage, nameof(requestMessage));
|
||||
Guard.NotNullOrEmpty(url, nameof(url));
|
||||
|
||||
var httpRequestMessage = new HttpRequestMessage(new HttpMethod(requestMessage.Method), url);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
@@ -15,7 +15,7 @@ namespace WireMock.Http
|
||||
/// <returns>StringContent</returns>
|
||||
internal static StringContent Create([NotNull] string content, [CanBeNull] MediaTypeHeaderValue contentType)
|
||||
{
|
||||
Check.NotNull(content, nameof(content));
|
||||
Guard.NotNull(content, nameof(content));
|
||||
|
||||
var stringContent = new StringContent(content);
|
||||
stringContent.Headers.ContentType = contentType;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -11,7 +11,7 @@ using WireMock.Transformers.Handlebars;
|
||||
using WireMock.Transformers.Scriban;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
@@ -28,10 +28,10 @@ namespace WireMock.Http
|
||||
|
||||
public Task<HttpResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] IWebhookRequest request, [NotNull] RequestMessage originalRequestMessage, [NotNull] ResponseMessage originalResponseMessage)
|
||||
{
|
||||
Check.NotNull(client, nameof(client));
|
||||
Check.NotNull(request, nameof(request));
|
||||
Check.NotNull(originalRequestMessage, nameof(originalRequestMessage));
|
||||
Check.NotNull(originalResponseMessage, nameof(originalResponseMessage));
|
||||
Guard.NotNull(client, nameof(client));
|
||||
Guard.NotNull(request, nameof(request));
|
||||
Guard.NotNull(originalRequestMessage, nameof(originalRequestMessage));
|
||||
Guard.NotNull(originalResponseMessage, nameof(originalResponseMessage));
|
||||
|
||||
IBodyData bodyData;
|
||||
IDictionary<string, WireMockList<string>> headers;
|
||||
@@ -55,7 +55,7 @@ namespace WireMock.Http
|
||||
throw new NotImplementedException($"TransformerType '{request.TransformerType}' is not supported.");
|
||||
}
|
||||
|
||||
(bodyData, headers) = responseMessageTransformer.Transform(originalRequestMessage, originalResponseMessage, request.BodyData, request.Headers);
|
||||
(bodyData, headers) = responseMessageTransformer.Transform(originalRequestMessage, originalResponseMessage, request.BodyData, request.Headers, request.TransformerReplaceNodeOptions);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using AnyOfTypes;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -37,7 +37,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="values">The values.</param>
|
||||
public ExactMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf<string, StringPattern>[] values)
|
||||
{
|
||||
Check.NotNull(values, nameof(values));
|
||||
Guard.NotNull(values, nameof(values));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using JetBrains.Annotations;
|
||||
using System.Linq;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="value">The value.</param>
|
||||
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] object value)
|
||||
{
|
||||
Check.NotNull(value, nameof(value));
|
||||
Guard.NotNull(value, nameof(value));
|
||||
|
||||
ValueAsObject = value;
|
||||
MatchBehaviour = matchBehaviour;
|
||||
@@ -63,7 +63,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="value">The value.</param>
|
||||
public ExactObjectMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] value, bool throwException = false)
|
||||
{
|
||||
Check.NotNull(value, nameof(value));
|
||||
Guard.NotNull(value, nameof(value));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -5,7 +5,7 @@ using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -48,7 +48,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
public JsonPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -5,7 +5,7 @@ using Newtonsoft.Json;
|
||||
using System.Linq;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -55,7 +55,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
public JmesPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -5,7 +5,7 @@ using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public JsonMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
{
|
||||
Check.NotNull(value, nameof(value));
|
||||
Guard.NotNull(value, nameof(value));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
IgnoreCase = ignoreCase;
|
||||
|
||||
@@ -6,7 +6,7 @@ using Newtonsoft.Json.Linq;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -57,7 +57,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public LinqMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -6,7 +6,7 @@ using JetBrains.Annotations;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.RegularExpressions;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -61,7 +61,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="useRegexExtended">Use RegexExtended (default = true).</param>
|
||||
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] AnyOf<string, StringPattern>[] patterns, bool ignoreCase = false, bool throwException = false, bool useRegexExtended = true)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_patterns = patterns;
|
||||
IgnoreCase = ignoreCase;
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
using System.Linq;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -70,7 +70,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="func">The function.</param>
|
||||
public RequestMessageBodyMatcher([NotNull] Func<string, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
Func = func;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="func">The function.</param>
|
||||
public RequestMessageBodyMatcher([NotNull] Func<byte[], bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
DataFunc = func;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="func">The function.</param>
|
||||
public RequestMessageBodyMatcher([NotNull] Func<object, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
JsonFunc = func;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="func">The function.</param>
|
||||
public RequestMessageBodyMatcher([NotNull] Func<IBodyData, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
BodyDataFunc = func;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageBodyMatcher([NotNull] params IMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
Matchers = matchers;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageClientIPMatcher([NotNull] params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
Matchers = matchers;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The clientIP functions.</param>
|
||||
public RequestMessageClientIPMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -27,7 +27,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="type">The CompositeMatcherType type (Defaults to 'And')</param>
|
||||
protected RequestMessageCompositeMatcher([NotNull] IEnumerable<IRequestMatcher> requestMatchers, CompositeMatcherType type = CompositeMatcherType.And)
|
||||
{
|
||||
Check.NotNull(requestMatchers, nameof(requestMatchers));
|
||||
Guard.NotNull(requestMatchers, nameof(requestMatchers));
|
||||
|
||||
_type = type;
|
||||
RequestMatchers = requestMatchers;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -39,8 +39,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
_ignoreCase = ignoreCase;
|
||||
@@ -58,7 +58,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, bool ignoreCase, [NotNull] params string[] patterns) :
|
||||
this(matchBehaviour, name, ignoreCase, patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast<IStringMatcher>().ToArray())
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,8 +70,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
public RequestMessageCookieMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, bool ignoreCase, [NotNull] params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
Name = name;
|
||||
@@ -85,7 +85,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The funcs.</param>
|
||||
public RequestMessageCookieMatcher([NotNull] params Func<IDictionary<string, string>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -40,8 +40,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, [NotNull] string pattern, bool ignoreCase)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
_ignoreCase = ignoreCase;
|
||||
@@ -59,7 +59,7 @@ namespace WireMock.Matchers.Request
|
||||
public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, bool ignoreCase, [NotNull] params string[] patterns) :
|
||||
this(matchBehaviour, name, ignoreCase, patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast<IStringMatcher>().ToArray())
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -71,8 +71,8 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
public RequestMessageHeaderMatcher(MatchBehaviour matchBehaviour, [NotNull] string name, bool ignoreCase, [NotNull] params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
Name = name;
|
||||
@@ -86,7 +86,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The funcs.</param>
|
||||
public RequestMessageHeaderMatcher([NotNull] params Func<IDictionary<string, string[]>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="methods">The methods.</param>
|
||||
public RequestMessageMethodMatcher(MatchBehaviour matchBehaviour, [NotNull] params string[] methods)
|
||||
{
|
||||
Check.NotNull(methods, nameof(methods));
|
||||
Guard.NotNull(methods, nameof(methods));
|
||||
_matchBehaviour = matchBehaviour;
|
||||
|
||||
Methods = methods;
|
||||
|
||||
@@ -3,7 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -64,7 +64,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageParamMatcher(MatchBehaviour matchBehaviour, [NotNull] string key, bool ignoreCase, [CanBeNull] IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
Guard.NotNull(key, nameof(key));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
Key = key;
|
||||
@@ -78,7 +78,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The funcs.</param>
|
||||
public RequestMessageParamMatcher([NotNull] params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessagePathMatcher([NotNull] params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
|
||||
Matchers = matchers;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The path functions.</param>
|
||||
public RequestMessagePathMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers.Request
|
||||
{
|
||||
@@ -36,7 +36,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
public RequestMessageUrlMatcher([NotNull] params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
Matchers = matchers;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="funcs">The url functions.</param>
|
||||
public RequestMessageUrlMatcher([NotNull] params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNull(funcs, nameof(funcs));
|
||||
Guard.NotNull(funcs, nameof(funcs));
|
||||
Funcs = funcs;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using SimMetrics.Net.API;
|
||||
using SimMetrics.Net.Metric;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
@@ -71,7 +71,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public SimMetricsMatcher(MatchBehaviour matchBehaviour, [NotNull] AnyOf<string, StringPattern>[] patterns, SimMetricType simMetricType = SimMetricType.Levenstein, bool throwException = false)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -5,7 +5,7 @@ using AnyOfTypes;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
#if !NETSTANDARD1_3
|
||||
using Wmhelp.XPath2;
|
||||
#endif
|
||||
@@ -42,7 +42,7 @@ namespace WireMock.Matchers
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
public XPathMatcher(MatchBehaviour matchBehaviour, bool throwException = false, [NotNull] params AnyOf<string, StringPattern>[] patterns)
|
||||
{
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
MatchBehaviour = matchBehaviour;
|
||||
ThrowException = throwException;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
@@ -41,8 +41,8 @@ namespace WireMock.Models
|
||||
/// <param name="url">The URL (relative).</param>
|
||||
public UrlDetails(Uri absoluteUrl, Uri url)
|
||||
{
|
||||
Check.NotNull(absoluteUrl, nameof(absoluteUrl));
|
||||
Check.NotNull(url, nameof(url));
|
||||
Guard.NotNull(absoluteUrl, nameof(absoluteUrl));
|
||||
Guard.NotNull(url, nameof(url));
|
||||
|
||||
AbsoluteUrl = absoluteUrl;
|
||||
Url = url;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
@@ -26,5 +26,8 @@ namespace WireMock.Models
|
||||
|
||||
/// <inheritdoc cref="IWebhookRequest.TransformerType"/>
|
||||
public TransformerType TransformerType { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWebhookRequest.TransformerReplaceNodeOptions"/>
|
||||
public ReplaceNodeOptions TransformerReplaceNodeOptions { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#if USE_ASPNETCORE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -8,10 +9,10 @@ using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Stef.Validation;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -35,8 +36,8 @@ namespace WireMock.Owin
|
||||
|
||||
public AspNetCoreSelfHost([NotNull] IWireMockMiddlewareOptions wireMockMiddlewareOptions, [NotNull] HostUrlOptions urlOptions)
|
||||
{
|
||||
Check.NotNull(wireMockMiddlewareOptions, nameof(wireMockMiddlewareOptions));
|
||||
Check.NotNull(urlOptions, nameof(urlOptions));
|
||||
Guard.NotNull(wireMockMiddlewareOptions, nameof(wireMockMiddlewareOptions));
|
||||
Guard.NotNull(urlOptions, nameof(urlOptions));
|
||||
|
||||
_logger = wireMockMiddlewareOptions.Logger ?? new WireMockConsoleLogger();
|
||||
|
||||
@@ -54,7 +55,7 @@ namespace WireMock.Owin
|
||||
// a filesystem handler).
|
||||
if (string.IsNullOrEmpty(AppContext.BaseDirectory))
|
||||
{
|
||||
builder.UseContentRoot(System.IO.Directory.GetCurrentDirectory());
|
||||
builder.UseContentRoot(Directory.GetCurrentDirectory());
|
||||
}
|
||||
|
||||
_host = builder
|
||||
|
||||
@@ -12,7 +12,7 @@ using IContext = Microsoft.AspNetCore.Http.HttpContext;
|
||||
using Next = Microsoft.AspNetCore.Http.RequestDelegate;
|
||||
#endif
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -24,8 +24,8 @@ namespace WireMock.Owin
|
||||
#if !USE_ASPNETCORE
|
||||
public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapper) : base(next)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
Guard.NotNull(options, nameof(options));
|
||||
Guard.NotNull(responseMapper, nameof(responseMapper));
|
||||
|
||||
_options = options;
|
||||
_responseMapper = responseMapper;
|
||||
@@ -33,8 +33,8 @@ namespace WireMock.Owin
|
||||
#else
|
||||
public GlobalExceptionMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinResponseMapper responseMapper)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
Guard.NotNull(options, nameof(options));
|
||||
Guard.NotNull(responseMapper, nameof(responseMapper));
|
||||
|
||||
Next = next;
|
||||
_options = options;
|
||||
|
||||
@@ -12,7 +12,7 @@ using RandomDataGenerator.Randomizers;
|
||||
using WireMock.Http;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
#if !USE_ASPNETCORE
|
||||
using IResponse = Microsoft.Owin.IOwinResponse;
|
||||
#else
|
||||
@@ -47,7 +47,7 @@ namespace WireMock.Owin.Mappers
|
||||
/// <param name="options">The IWireMockMiddlewareOptions.</param>
|
||||
public OwinResponseMapper(IWireMockMiddlewareOptions options)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Guard.NotNull(options, nameof(options));
|
||||
|
||||
_options = options;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -12,7 +12,7 @@ namespace WireMock.Owin
|
||||
|
||||
public MappingMatcher(IWireMockMiddlewareOptions options)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Guard.NotNull(options, nameof(options));
|
||||
|
||||
_options = options;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
@@ -22,8 +22,8 @@ namespace WireMock.Owin
|
||||
|
||||
public OwinSelfHost([NotNull] IWireMockMiddlewareOptions options, [NotNull] HostUrlOptions urlOptions)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(urlOptions, nameof(urlOptions));
|
||||
Guard.NotNull(options, nameof(options));
|
||||
Guard.NotNull(urlOptions, nameof(urlOptions));
|
||||
|
||||
_options = options;
|
||||
_logger = options.Logger ?? new WireMockConsoleLogger();
|
||||
@@ -46,10 +46,7 @@ namespace WireMock.Owin
|
||||
[PublicAPI]
|
||||
public Task StartAsync()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
StartServers();
|
||||
}, _cts.Token);
|
||||
return Task.Run(StartServers, _cts.Token);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Logging;
|
||||
using System.Linq;
|
||||
using Stef.Validation;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Http;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Settings;
|
||||
#if !USE_ASPNETCORE
|
||||
@@ -35,18 +35,18 @@ namespace WireMock.Owin
|
||||
#if !USE_ASPNETCORE
|
||||
public WireMockMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinRequestMapper requestMapper, IOwinResponseMapper responseMapper, IMappingMatcher mappingMatcher) : base(next)
|
||||
{
|
||||
_options = Check.NotNull(options, nameof(options));
|
||||
_requestMapper = Check.NotNull(requestMapper, nameof(requestMapper));
|
||||
_responseMapper = Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
_mappingMatcher = Check.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
_options = Guard.NotNull(options, nameof(options));
|
||||
_requestMapper = Guard.NotNull(requestMapper, nameof(requestMapper));
|
||||
_responseMapper = Guard.NotNull(responseMapper, nameof(responseMapper));
|
||||
_mappingMatcher = Guard.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
}
|
||||
#else
|
||||
public WireMockMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinRequestMapper requestMapper, IOwinResponseMapper responseMapper, IMappingMatcher mappingMatcher)
|
||||
{
|
||||
_options = Check.NotNull(options, nameof(options));
|
||||
_requestMapper = Check.NotNull(requestMapper, nameof(requestMapper));
|
||||
_responseMapper = Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
_mappingMatcher = Check.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
_options = Guard.NotNull(options, nameof(options));
|
||||
_requestMapper = Guard.NotNull(requestMapper, nameof(requestMapper));
|
||||
_responseMapper = Guard.NotNull(responseMapper, nameof(responseMapper));
|
||||
_mappingMatcher = Guard.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ using WireMock.ResponseBuilders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Proxy
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace WireMock.Proxy
|
||||
|
||||
public ProxyHelper([NotNull] IWireMockServerSettings settings)
|
||||
{
|
||||
_settings = Check.NotNull(settings, nameof(settings));
|
||||
_settings = Guard.NotNull(settings, nameof(settings));
|
||||
}
|
||||
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> SendAsync(
|
||||
@@ -30,9 +30,9 @@ namespace WireMock.Proxy
|
||||
[NotNull] RequestMessage requestMessage,
|
||||
[NotNull] string url)
|
||||
{
|
||||
Check.NotNull(client, nameof(client));
|
||||
Check.NotNull(requestMessage, nameof(requestMessage));
|
||||
Check.NotNull(url, nameof(url));
|
||||
Guard.NotNull(client, nameof(client));
|
||||
Guard.NotNull(requestMessage, nameof(requestMessage));
|
||||
Guard.NotNull(url, nameof(url));
|
||||
|
||||
var originalUri = new Uri(requestMessage.Url);
|
||||
var requiredUri = new Uri(url);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RegularExpressions
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace WireMock.RegularExpressions
|
||||
/// <param name="pattern">Pattern to replace token for.</param>
|
||||
private static string ReplaceGuidPattern(string pattern)
|
||||
{
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
Guard.NotNull(pattern, nameof(pattern));
|
||||
|
||||
foreach (var tokenPattern in GuidTokenPatterns)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using WireMock.Http;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -106,7 +106,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(MatchBehaviour, string[])"/>
|
||||
public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods)
|
||||
{
|
||||
Check.NotNullOrEmpty(methods, nameof(methods));
|
||||
Guard.NotNullOrEmpty(methods, nameof(methods));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods));
|
||||
return this;
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(IMatcher[])"/>
|
||||
public IRequestBuilder WithBody(IMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(matchers, nameof(matchers));
|
||||
Guard.NotNull(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageBodyMatcher(matchers));
|
||||
return this;
|
||||
@@ -49,7 +49,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{string, bool})"/>
|
||||
public IRequestBuilder WithBody(Func<string, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
|
||||
return this;
|
||||
@@ -58,7 +58,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{byte[], bool})"/>
|
||||
public IRequestBuilder WithBody(Func<byte[], bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
|
||||
return this;
|
||||
@@ -67,7 +67,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{object, bool})"/>
|
||||
public IRequestBuilder WithBody(Func<object, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
|
||||
return this;
|
||||
@@ -76,7 +76,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IBodyRequestBuilder.WithBody(Func{IBodyData, bool})"/>
|
||||
public IRequestBuilder WithBody(Func<IBodyData, bool> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
|
||||
return this;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -17,8 +17,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(string, string, bool, MatchBehaviour)"/>
|
||||
public IRequestBuilder WithCookie(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(matchBehaviour, name, pattern, ignoreCase));
|
||||
return this;
|
||||
@@ -33,8 +33,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(string, string[], bool, MatchBehaviour)"/>
|
||||
public IRequestBuilder WithCookie(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(matchBehaviour, name, ignoreCase, patterns));
|
||||
return this;
|
||||
@@ -43,8 +43,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(string, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithCookie(string name, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, name, false, matchers));
|
||||
return this;
|
||||
@@ -53,8 +53,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(string, bool, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithCookie(string name, bool ignoreCase, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(MatchBehaviour.AcceptOnMatch, name, ignoreCase, matchers));
|
||||
return this;
|
||||
@@ -63,8 +63,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(string, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithCookie(string name, bool ignoreCase, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(matchBehaviour, name, ignoreCase, matchers));
|
||||
return this;
|
||||
@@ -73,7 +73,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="ICookiesRequestBuilder.WithCookie(Func{IDictionary{string, string}, bool}[])"/>
|
||||
public IRequestBuilder WithCookie(params Func<IDictionary<string, string>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageCookieMatcher(funcs));
|
||||
return this;
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -19,8 +19,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, string, bool, MatchBehaviour)"/>
|
||||
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, pattern, ignoreCase));
|
||||
return this;
|
||||
@@ -35,8 +35,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, string[], bool, MatchBehaviour)"/>
|
||||
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, ignoreCase, patterns));
|
||||
return this;
|
||||
@@ -45,8 +45,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithHeader(string name, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, name, false, matchers));
|
||||
return this;
|
||||
@@ -55,8 +55,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, bool, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithHeader(string name, bool ignoreCase, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(MatchBehaviour.AcceptOnMatch, name, ignoreCase, matchers));
|
||||
return this;
|
||||
@@ -65,8 +65,8 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(string, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithHeader(string name, bool ignoreCase, MatchBehaviour matchBehaviour, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(matchBehaviour, name, ignoreCase, matchers));
|
||||
return this;
|
||||
@@ -75,7 +75,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IHeadersRequestBuilder.WithHeader(Func{IDictionary{string, string[]}, bool}[])"/>
|
||||
public IRequestBuilder WithHeader(params Func<IDictionary<string, string[]>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageHeaderMatcher(funcs));
|
||||
return this;
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Collections.Generic;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -20,7 +20,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, bool, MatchBehaviour)"/>
|
||||
public IRequestBuilder WithParam(string key, bool ignoreCase, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
Guard.NotNull(key, nameof(key));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, ignoreCase));
|
||||
return this;
|
||||
@@ -59,7 +59,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, bool, string[])"/>
|
||||
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, bool ignoreCase = false, params string[] values)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
Guard.NotNull(key, nameof(key));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, ignoreCase, values));
|
||||
return this;
|
||||
@@ -74,7 +74,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(string, MatchBehaviour, bool, IStringMatcher[])"/>
|
||||
public IRequestBuilder WithParam(string key, MatchBehaviour matchBehaviour, bool ignoreCase, params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNull(key, nameof(key));
|
||||
Guard.NotNull(key, nameof(key));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageParamMatcher(matchBehaviour, key, ignoreCase, matchers));
|
||||
return this;
|
||||
@@ -83,7 +83,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IParamsRequestBuilder.WithParam(Func{IDictionary{string, WireMockList{string}}, bool}[])"/>
|
||||
public IRequestBuilder WithParam(params Func<IDictionary<string, WireMockList<string>>, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageParamMatcher(funcs));
|
||||
return this;
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.RequestBuilders
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(IStringMatcher[])"/>
|
||||
public IRequestBuilder WithClientIP(params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(matchers));
|
||||
return this;
|
||||
@@ -83,7 +83,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(string[])"/>
|
||||
public IRequestBuilder WithClientIP(MatchBehaviour matchBehaviour, params string[] clientIPs)
|
||||
{
|
||||
Check.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
||||
Guard.NotNullOrEmpty(clientIPs, nameof(clientIPs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(matchBehaviour, clientIPs));
|
||||
return this;
|
||||
@@ -92,7 +92,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IClientIPRequestBuilder.WithClientIP(Func{string, bool}[])"/>
|
||||
public IRequestBuilder WithClientIP(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageClientIPMatcher(funcs));
|
||||
return this;
|
||||
@@ -101,7 +101,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(IStringMatcher[])"/>
|
||||
public IRequestBuilder WithPath(params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(matchers));
|
||||
return this;
|
||||
@@ -116,7 +116,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(MatchBehaviour, string[])"/>
|
||||
public IRequestBuilder WithPath(MatchBehaviour matchBehaviour, params string[] paths)
|
||||
{
|
||||
Check.NotNullOrEmpty(paths, nameof(paths));
|
||||
Guard.NotNullOrEmpty(paths, nameof(paths));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(matchBehaviour, paths));
|
||||
return this;
|
||||
@@ -125,7 +125,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithPath(Func{string, bool}[])"/>
|
||||
public IRequestBuilder WithPath(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessagePathMatcher(funcs));
|
||||
return this;
|
||||
@@ -134,7 +134,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(IStringMatcher[])"/>
|
||||
public IRequestBuilder WithUrl(params IStringMatcher[] matchers)
|
||||
{
|
||||
Check.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
Guard.NotNullOrEmpty(matchers, nameof(matchers));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(matchers));
|
||||
return this;
|
||||
@@ -149,7 +149,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(MatchBehaviour, string[])"/>
|
||||
public IRequestBuilder WithUrl(MatchBehaviour matchBehaviour, params string[] urls)
|
||||
{
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
Guard.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(matchBehaviour, urls));
|
||||
return this;
|
||||
@@ -158,7 +158,7 @@ namespace WireMock.RequestBuilders
|
||||
/// <inheritdoc cref="IUrlAndPathRequestBuilder.WithUrl(Func{string, bool}[])"/>
|
||||
public IRequestBuilder WithUrl(params Func<string, bool>[] funcs)
|
||||
{
|
||||
Check.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
Guard.NotNullOrEmpty(funcs, nameof(funcs));
|
||||
|
||||
_requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
|
||||
return this;
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Net;
|
||||
using WireMock.Models;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
@@ -103,9 +103,9 @@ namespace WireMock
|
||||
/// <param name="cookies">The cookies.</param>
|
||||
public RequestMessage([NotNull] UrlDetails urlDetails, [NotNull] string method, [NotNull] string clientIP, [CanBeNull] IBodyData bodyData = null, [CanBeNull] IDictionary<string, string[]> headers = null, [CanBeNull] IDictionary<string, string> cookies = null)
|
||||
{
|
||||
Check.NotNull(urlDetails, nameof(urlDetails));
|
||||
Check.NotNull(method, nameof(method));
|
||||
Check.NotNull(clientIP, nameof(clientIP));
|
||||
Guard.NotNull(urlDetails, nameof(urlDetails));
|
||||
Guard.NotNull(method, nameof(method));
|
||||
Guard.NotNull(clientIP, nameof(clientIP));
|
||||
|
||||
AbsoluteUrl = urlDetails.AbsoluteUrl.ToString();
|
||||
Url = urlDetails.Url.ToString();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using WireMock.Types;
|
||||
using WireMock.Types;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -13,7 +13,15 @@ namespace WireMock.ResponseBuilders
|
||||
/// <returns>
|
||||
/// The <see cref="IResponseBuilder"/>.
|
||||
/// </returns>
|
||||
IResponseBuilder WithTransformer(bool transformContentFromBodyAsFile = false);
|
||||
IResponseBuilder WithTransformer(bool transformContentFromBodyAsFile);
|
||||
|
||||
/// <summary>
|
||||
/// Use the Handlebars.Net ResponseMessage transformer.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The <see cref="IResponseBuilder"/>.
|
||||
/// </returns>
|
||||
IResponseBuilder WithTransformer(ReplaceNodeOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Use a specific ResponseMessage transformer.
|
||||
@@ -21,6 +29,6 @@ namespace WireMock.ResponseBuilders
|
||||
/// <returns>
|
||||
/// The <see cref="IResponseBuilder"/>.
|
||||
/// </returns>
|
||||
IResponseBuilder WithTransformer(TransformerType transformerType, bool transformContentFromBodyAsFile = false);
|
||||
IResponseBuilder WithTransformer(TransformerType transformerType = TransformerType.Handlebars, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.None);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, ResponseMessage})"/>
|
||||
public IResponseBuilder WithCallback(Func<RequestMessage, ResponseMessage> callbackHandler)
|
||||
{
|
||||
Check.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
|
||||
return WithCallbackInternal(true, callbackHandler);
|
||||
}
|
||||
@@ -32,14 +32,14 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="ICallbackResponseBuilder.WithCallback(Func{RequestMessage, Task{ResponseMessage}})"/>
|
||||
public IResponseBuilder WithCallback(Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
|
||||
{
|
||||
Check.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
|
||||
return WithCallbackInternal(true, callbackHandler);
|
||||
}
|
||||
|
||||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, ResponseMessage> callbackHandler)
|
||||
{
|
||||
Check.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
|
||||
WithCallbackUsed = withCallbackUsed;
|
||||
Callback = callbackHandler;
|
||||
@@ -49,7 +49,7 @@ namespace WireMock.ResponseBuilders
|
||||
|
||||
private IResponseBuilder WithCallbackInternal(bool withCallbackUsed, Func<RequestMessage, Task<ResponseMessage>> callbackHandler)
|
||||
{
|
||||
Check.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
Guard.NotNull(callbackHandler, nameof(callbackHandler));
|
||||
|
||||
WithCallbackUsed = withCallbackUsed;
|
||||
CallbackAsync = callbackHandler;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Net.Http;
|
||||
using WireMock.Http;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(string, string)"/>
|
||||
public IResponseBuilder WithProxy(string proxyUrl, string clientX509Certificate2ThumbprintOrSubjectName = null)
|
||||
{
|
||||
Check.NotNullOrEmpty(proxyUrl, nameof(proxyUrl));
|
||||
Guard.NotNullOrEmpty(proxyUrl, nameof(proxyUrl));
|
||||
|
||||
var settings = new ProxyAndRecordSettings
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IProxyResponseBuilder.WithProxy(IProxyAndRecordSettings)"/>
|
||||
public IResponseBuilder WithProxy(IProxyAndRecordSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
ProxyAndRecordSettings = settings;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Stef.Validation;
|
||||
using WireMock.Proxy;
|
||||
using WireMock.ResponseProviders;
|
||||
using WireMock.Settings;
|
||||
@@ -16,7 +17,6 @@ using WireMock.Transformers.Handlebars;
|
||||
using WireMock.Transformers.Scriban;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -68,10 +68,15 @@ namespace WireMock.ResponseBuilders
|
||||
public TransformerType TransformerType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether to use the Handlerbars transformer for the content from the referenced BodyAsFile.
|
||||
/// Gets a value indicating whether to use the Handlebars transformer for the content from the referenced BodyAsFile.
|
||||
/// </summary>
|
||||
public bool UseTransformerForBodyAsFile { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ReplaceNodeOptions to use when transforming a JSON node.
|
||||
/// </summary>
|
||||
public ReplaceNodeOptions TransformerReplaceNodeOptions { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the response message.
|
||||
/// </summary>
|
||||
@@ -97,7 +102,7 @@ namespace WireMock.ResponseBuilders
|
||||
[PublicAPI]
|
||||
public static IResponseBuilder Create([NotNull] Func<ResponseMessage> func)
|
||||
{
|
||||
Check.NotNull(func, nameof(func));
|
||||
Guard.NotNull(func, nameof(func));
|
||||
|
||||
return new Response(func());
|
||||
}
|
||||
@@ -159,7 +164,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IHeadersResponseBuilder.WithHeader(string, string[])"/>
|
||||
public IResponseBuilder WithHeader(string name, params string[] values)
|
||||
{
|
||||
Check.NotNull(name, nameof(name));
|
||||
Guard.NotNull(name, nameof(name));
|
||||
|
||||
ResponseMessage.AddHeader(name, values);
|
||||
return this;
|
||||
@@ -168,7 +173,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IHeadersResponseBuilder.WithHeaders(IDictionary{string, string})"/>
|
||||
public IResponseBuilder WithHeaders(IDictionary<string, string> headers)
|
||||
{
|
||||
Check.NotNull(headers, nameof(headers));
|
||||
Guard.NotNull(headers, nameof(headers));
|
||||
|
||||
ResponseMessage.Headers = headers.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
return this;
|
||||
@@ -177,7 +182,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IHeadersResponseBuilder.WithHeaders(IDictionary{string, string[]})"/>
|
||||
public IResponseBuilder WithHeaders(IDictionary<string, string[]> headers)
|
||||
{
|
||||
Check.NotNull(headers, nameof(headers));
|
||||
Guard.NotNull(headers, nameof(headers));
|
||||
|
||||
ResponseMessage.Headers = headers.ToDictionary(header => header.Key, header => new WireMockList<string>(header.Value));
|
||||
return this;
|
||||
@@ -193,7 +198,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(Func{RequestMessage, string}, string, Encoding)"/>
|
||||
public IResponseBuilder WithBody(Func<RequestMessage, string> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||
{
|
||||
Check.NotNull(bodyFactory, nameof(bodyFactory));
|
||||
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
||||
|
||||
return WithCallbackInternal(true, req => new ResponseMessage
|
||||
{
|
||||
@@ -209,7 +214,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(Func{RequestMessage, Task{string}}, string, Encoding)"/>
|
||||
public IResponseBuilder WithBody(Func<RequestMessage, Task<string>> bodyFactory, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||
{
|
||||
Check.NotNull(bodyFactory, nameof(bodyFactory));
|
||||
Guard.NotNull(bodyFactory, nameof(bodyFactory));
|
||||
|
||||
return WithCallbackInternal(true, async req => new ResponseMessage
|
||||
{
|
||||
@@ -225,7 +230,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(byte[], string, Encoding)"/>
|
||||
public IResponseBuilder WithBody(byte[] body, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||
{
|
||||
Check.NotNull(body, nameof(body));
|
||||
Guard.NotNull(body, nameof(body));
|
||||
|
||||
ResponseMessage.BodyDestination = destination;
|
||||
ResponseMessage.BodyData = new BodyData();
|
||||
@@ -251,7 +256,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyFromFile"/>
|
||||
public IResponseBuilder WithBodyFromFile(string filename, bool cache = true)
|
||||
{
|
||||
Check.NotNull(filename, nameof(filename));
|
||||
Guard.NotNull(filename, nameof(filename));
|
||||
|
||||
ResponseMessage.BodyData = new BodyData
|
||||
{
|
||||
@@ -274,7 +279,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBody(string, string, Encoding)"/>
|
||||
public IResponseBuilder WithBody(string body, string destination = BodyDestinationFormat.SameAsSource, Encoding encoding = null)
|
||||
{
|
||||
Check.NotNull(body, nameof(body));
|
||||
Guard.NotNull(body, nameof(body));
|
||||
|
||||
encoding = encoding ?? Encoding.UTF8;
|
||||
|
||||
@@ -309,7 +314,7 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IBodyResponseBuilder.WithBodyAsJson(object, Encoding, bool?)"/>
|
||||
public IResponseBuilder WithBodyAsJson(object body, Encoding encoding = null, bool? indented = null)
|
||||
{
|
||||
Check.NotNull(body, nameof(body));
|
||||
Guard.NotNull(body, nameof(body));
|
||||
|
||||
ResponseMessage.BodyDestination = null;
|
||||
ResponseMessage.BodyData = new BodyData
|
||||
@@ -330,27 +335,33 @@ namespace WireMock.ResponseBuilders
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ITransformResponseBuilder.WithTransformer(bool)"/>
|
||||
public IResponseBuilder WithTransformer(bool transformContentFromBodyAsFile = false)
|
||||
public IResponseBuilder WithTransformer(bool transformContentFromBodyAsFile)
|
||||
{
|
||||
UseTransformer = true;
|
||||
TransformerType = TransformerType.Handlebars;
|
||||
UseTransformerForBodyAsFile = transformContentFromBodyAsFile;
|
||||
return this;
|
||||
return WithTransformer(TransformerType.Handlebars, transformContentFromBodyAsFile);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ITransformResponseBuilder.WithTransformer(TransformerType, bool)"/>
|
||||
public IResponseBuilder WithTransformer(TransformerType transformerType, bool transformContentFromBodyAsFile = false)
|
||||
/// <inheritdoc cref="ITransformResponseBuilder.WithTransformer(ReplaceNodeOptions)"/>
|
||||
public IResponseBuilder WithTransformer(ReplaceNodeOptions options)
|
||||
{
|
||||
return WithTransformer(TransformerType.Handlebars, false, options);
|
||||
}
|
||||
|
||||
#pragma warning disable CS1574
|
||||
/// <inheritdoc cref="ITransformResponseBuilder.WithTransformer(TransformerType, bool, ReplaceNodeOptions)"/>
|
||||
#pragma warning restore CS1574
|
||||
public IResponseBuilder WithTransformer(TransformerType transformerType, bool transformContentFromBodyAsFile = false, ReplaceNodeOptions options = ReplaceNodeOptions.None)
|
||||
{
|
||||
UseTransformer = true;
|
||||
TransformerType = transformerType;
|
||||
UseTransformerForBodyAsFile = transformContentFromBodyAsFile;
|
||||
TransformerReplaceNodeOptions = options;
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IDelayResponseBuilder.WithDelay(TimeSpan)"/>
|
||||
public IResponseBuilder WithDelay(TimeSpan delay)
|
||||
{
|
||||
Check.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));
|
||||
Guard.Condition(delay, d => d > TimeSpan.Zero, nameof(delay));
|
||||
|
||||
Delay = delay;
|
||||
return this;
|
||||
@@ -365,8 +376,8 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IDelayResponseBuilder.WithRandomDelay(int, int)"/>
|
||||
public IResponseBuilder WithRandomDelay(int minimumMilliseconds = 0, int maximumMilliseconds = 60_000)
|
||||
{
|
||||
Check.Condition(minimumMilliseconds, min => min >= 0, nameof(minimumMilliseconds));
|
||||
Check.Condition(maximumMilliseconds, max => max > minimumMilliseconds, nameof(maximumMilliseconds));
|
||||
Guard.Condition(minimumMilliseconds, min => min >= 0, nameof(minimumMilliseconds));
|
||||
Guard.Condition(maximumMilliseconds, max => max > minimumMilliseconds, nameof(maximumMilliseconds));
|
||||
|
||||
MinimumDelayMilliseconds = minimumMilliseconds;
|
||||
MaximumDelayMilliseconds = maximumMilliseconds;
|
||||
@@ -377,8 +388,8 @@ namespace WireMock.ResponseBuilders
|
||||
/// <inheritdoc cref="IResponseProvider.ProvideResponseAsync(RequestMessage, IWireMockServerSettings)"/>
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings)
|
||||
{
|
||||
Check.NotNull(requestMessage, nameof(requestMessage));
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
Guard.NotNull(requestMessage, nameof(requestMessage));
|
||||
Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
if (Delay != null)
|
||||
{
|
||||
@@ -458,7 +469,7 @@ namespace WireMock.ResponseBuilders
|
||||
throw new NotImplementedException($"TransformerType '{TransformerType}' is not supported.");
|
||||
}
|
||||
|
||||
return (responseMessageTransformer.Transform(requestMessage, responseMessage, UseTransformerForBodyAsFile), null);
|
||||
return (responseMessageTransformer.Transform(requestMessage, responseMessage, UseTransformerForBodyAsFile, TransformerReplaceNodeOptions), null);
|
||||
}
|
||||
|
||||
if (!UseTransformer && ResponseMessage.BodyData?.BodyAsFileIsCached == true)
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Linq;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock
|
||||
{
|
||||
@@ -44,7 +44,7 @@ namespace WireMock
|
||||
/// <inheritdoc cref="IResponseMessage.AddHeader(string, string[])" />
|
||||
public void AddHeader(string name, params string[] values)
|
||||
{
|
||||
Check.NotNullOrEmpty(values, nameof(values));
|
||||
Guard.NotNullOrEmpty(values, nameof(values));
|
||||
|
||||
var newHeaderValues = Headers.TryGetValue(name, out WireMockList<string> existingValues)
|
||||
? values.Union(existingValues).ToArray()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Stef.Validation;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -16,7 +16,7 @@ namespace WireMock.Serialization
|
||||
|
||||
public MappingConverter(MatcherMapper mapper)
|
||||
{
|
||||
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
|
||||
_mapper = Guard.NotNull(mapper, nameof(mapper));
|
||||
}
|
||||
|
||||
public MappingModel ToMappingModel(IMapping mapping)
|
||||
@@ -130,6 +130,7 @@ namespace WireMock.Serialization
|
||||
mappingModel.Response.UseTransformer = null;
|
||||
mappingModel.Response.TransformerType = null;
|
||||
mappingModel.Response.UseTransformerForBodyAsFile = null;
|
||||
mappingModel.Response.TransformerReplaceNodeOptions = null;
|
||||
mappingModel.Response.BodyEncoding = null;
|
||||
mappingModel.Response.ProxyUrl = response.ProxyAndRecordSettings.Url;
|
||||
mappingModel.Response.Fault = null;
|
||||
@@ -150,6 +151,7 @@ namespace WireMock.Serialization
|
||||
{
|
||||
mappingModel.Response.UseTransformer = response.UseTransformer;
|
||||
mappingModel.Response.TransformerType = response.TransformerType.ToString();
|
||||
mappingModel.Response.TransformerReplaceNodeOptions = response.TransformerReplaceNodeOptions.ToString();
|
||||
}
|
||||
|
||||
if (response.UseTransformerForBodyAsFile)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Serialization
|
||||
{
|
||||
@@ -13,7 +13,7 @@ namespace WireMock.Serialization
|
||||
|
||||
public MappingToFileSaver(IWireMockServerSettings settings, MappingConverter mappingConverter)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
_settings = settings;
|
||||
_mappingConverter = mappingConverter;
|
||||
|
||||
@@ -105,6 +105,11 @@ namespace WireMock.Serialization
|
||||
return new SimMetricsMatcher(matchBehaviour, stringPatterns, type, throwExceptionWhenMatcherFails);
|
||||
|
||||
default:
|
||||
if (_settings.CustomMatcherMappings != null && _settings.CustomMatcherMappings.ContainsKey(matcherName))
|
||||
{
|
||||
return _settings.CustomMatcherMappings[matcherName](matcher);
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"Matcher '{matcherName}' is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Admin.Mappings;
|
||||
@@ -31,6 +31,13 @@ namespace WireMock.Serialization
|
||||
transformerType = TransformerType.Handlebars;
|
||||
}
|
||||
webhook.Request.TransformerType = transformerType;
|
||||
|
||||
if (!Enum.TryParse<ReplaceNodeOptions>(model.Request.TransformerReplaceNodeOptions, out var option))
|
||||
{
|
||||
option = ReplaceNodeOptions.None;
|
||||
}
|
||||
|
||||
webhook.Request.TransformerReplaceNodeOptions = option;
|
||||
}
|
||||
|
||||
IEnumerable<string> contentTypeHeader = null;
|
||||
@@ -76,7 +83,8 @@ namespace WireMock.Serialization
|
||||
Method = webhook.Request.Method,
|
||||
Headers = webhook.Request.Headers?.ToDictionary(x => x.Key, x => x.Value.ToString()),
|
||||
UseTransformer = webhook.Request.UseTransformer,
|
||||
TransformerType = webhook.Request.UseTransformer == true ? webhook.Request.TransformerType.ToString() : null
|
||||
TransformerType = webhook.Request.UseTransformer == true ? webhook.Request.TransformerType.ToString() : null,
|
||||
TransformerReplaceNodeOptions = webhook.Request.TransformerReplaceNodeOptions.ToString()
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,6 +101,7 @@ namespace WireMock.Serialization
|
||||
break;
|
||||
|
||||
default:
|
||||
// Empty
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ using WireMock.ResponseProviders;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace WireMock.Server
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings)
|
||||
{
|
||||
Check.NotNull(timeSettings, nameof(timeSettings));
|
||||
Guard.NotNull(timeSettings, nameof(timeSettings));
|
||||
|
||||
TimeSettings = timeSettings;
|
||||
|
||||
@@ -164,7 +164,7 @@ namespace WireMock.Server
|
||||
/// <see cref="IRespondWithAProvider.WithWebhook(IWebhook[])"/>
|
||||
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
|
||||
{
|
||||
Check.HasNoNulls(webhooks, nameof(webhooks));
|
||||
Guard.HasNoNulls(webhooks, nameof(webhooks));
|
||||
|
||||
Webhooks = webhooks;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Stef.Validation;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Admin.Scenarios;
|
||||
using WireMock.Admin.Settings;
|
||||
@@ -24,7 +25,6 @@ using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -206,7 +206,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public bool ReadStaticMappingAndAddOrUpdate([NotNull] string path)
|
||||
{
|
||||
Check.NotNull(path, nameof(path));
|
||||
Guard.NotNull(path, nameof(path));
|
||||
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
@@ -414,9 +414,9 @@ namespace WireMock.Server
|
||||
|
||||
private Guid? ConvertMappingAndRegisterAsRespondProvider(MappingModel mappingModel, Guid? guid = null, string path = null)
|
||||
{
|
||||
Check.NotNull(mappingModel, nameof(mappingModel));
|
||||
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
||||
Check.NotNull(mappingModel.Response, nameof(mappingModel.Response));
|
||||
Guard.NotNull(mappingModel, nameof(mappingModel));
|
||||
Guard.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
||||
Guard.NotNull(mappingModel.Response, nameof(mappingModel.Response));
|
||||
|
||||
var requestBuilder = InitRequestBuilder(mappingModel.Request, true);
|
||||
if (requestBuilder == null)
|
||||
@@ -785,7 +785,15 @@ namespace WireMock.Server
|
||||
{
|
||||
transformerType = TransformerType.Handlebars;
|
||||
}
|
||||
responseBuilder = responseBuilder.WithTransformer(transformerType, responseModel.UseTransformerForBodyAsFile == true);
|
||||
|
||||
if (!Enum.TryParse<ReplaceNodeOptions>(responseModel.TransformerReplaceNodeOptions, out var option))
|
||||
{
|
||||
option = ReplaceNodeOptions.None;
|
||||
}
|
||||
responseBuilder = responseBuilder.WithTransformer(
|
||||
transformerType,
|
||||
responseModel.UseTransformerForBodyAsFile == true,
|
||||
option);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(responseModel.ProxyUrl))
|
||||
|
||||
@@ -9,7 +9,7 @@ using WireMock.Matchers;
|
||||
using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Util;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
using OrgMapping = WireMock.Org.Abstractions.Mapping;
|
||||
|
||||
namespace WireMock.Server
|
||||
@@ -23,7 +23,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public void ReadStaticWireMockOrgMappingAndAddOrUpdate([NotNull] string path)
|
||||
{
|
||||
Check.NotNull(path, nameof(path));
|
||||
Guard.NotNull(path, nameof(path));
|
||||
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseProviders;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start([NotNull] IWireMockServerSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
return new WireMockServer(settings);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static WireMockServer Start(params string[] urls)
|
||||
{
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
Guard.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new WireMockServer(new WireMockServerSettings
|
||||
{
|
||||
@@ -155,7 +155,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static WireMockServer StartWithAdminInterface(params string[] urls)
|
||||
{
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
Guard.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new WireMockServer(new WireMockServerSettings
|
||||
{
|
||||
@@ -172,7 +172,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public static WireMockServer StartWithAdminInterfaceAndReadStaticMappings(params string[] urls)
|
||||
{
|
||||
Check.NotNullOrEmpty(urls, nameof(urls));
|
||||
Guard.NotNullOrEmpty(urls, nameof(urls));
|
||||
|
||||
return new WireMockServer(new WireMockServerSettings
|
||||
{
|
||||
@@ -413,8 +413,8 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public void SetAzureADAuthentication([NotNull] string tenant, [NotNull] string audience)
|
||||
{
|
||||
Check.NotNull(tenant, nameof(tenant));
|
||||
Check.NotNull(audience, nameof(audience));
|
||||
Guard.NotNull(tenant, nameof(tenant));
|
||||
Guard.NotNull(audience, nameof(audience));
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
throw new NotSupportedException("AzureADAuthentication is not supported for NETStandard 1.3");
|
||||
@@ -427,8 +427,8 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public void SetBasicAuthentication([NotNull] string username, [NotNull] string password)
|
||||
{
|
||||
Check.NotNull(username, nameof(username));
|
||||
Check.NotNull(password, nameof(password));
|
||||
Guard.NotNull(username, nameof(username));
|
||||
Guard.NotNull(password, nameof(password));
|
||||
|
||||
_options.AuthenticationMatcher = new BasicAuthenticationMatcher(username, password);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using HandlebarsDotNet;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
@@ -229,5 +232,11 @@ namespace WireMock.Settings
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
bool? SaveUnmatchedRequests { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Custom matcher mappings for static mappings
|
||||
/// </summary>
|
||||
[PublicAPI, JsonIgnore]
|
||||
IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HandlebarsDotNet;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
#if USE_ASPNETCORE
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endif
|
||||
@@ -158,5 +161,9 @@ namespace WireMock.Settings
|
||||
/// <inheritdoc cref="IWireMockServerSettings.SaveUnmatchedRequests"/>
|
||||
[PublicAPI]
|
||||
public bool? SaveUnmatchedRequests { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.CustomMatcherMappings"/>
|
||||
[PublicAPI, JsonIgnore]
|
||||
public IDictionary<string, Func<MatcherModel, IMatcher>> CustomMatcherMappings { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Settings
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace WireMock.Settings
|
||||
[PublicAPI]
|
||||
public static bool TryParseArguments([NotNull] string[] args, out IWireMockServerSettings settings, [CanBeNull] IWireMockLogger logger = null)
|
||||
{
|
||||
Check.HasNoNulls(args, nameof(args));
|
||||
Guard.HasNoNulls(args, nameof(args));
|
||||
|
||||
var parser = new SimpleCommandLineParser();
|
||||
parser.Parse(args);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
using HandlebarsDotNet;
|
||||
using WireMock.Handlers;
|
||||
using HandlebarsDotNet;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
{
|
||||
internal class HandlebarsContext : IHandlebarsContext
|
||||
{
|
||||
public IHandlebars Handlebars { get; set; }
|
||||
|
||||
public IFileSystemHandler FileSystemHandler { get; set; }
|
||||
|
||||
public string ParseAndRender(string text, object model)
|
||||
{
|
||||
var template = Handlebars.Compile(text);
|
||||
return template(model);
|
||||
}
|
||||
}
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
{
|
||||
internal class HandlebarsContext : IHandlebarsContext
|
||||
{
|
||||
public IHandlebars Handlebars { get; set; }
|
||||
|
||||
public IFileSystemHandler FileSystemHandler { get; set; }
|
||||
|
||||
public string ParseAndRender(string text, object model)
|
||||
{
|
||||
var template = Handlebars.Compile(text);
|
||||
return template(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System;
|
||||
using HandlebarsDotNet;
|
||||
using JetBrains.Annotations;
|
||||
using Stef.Validation;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
@@ -12,7 +13,7 @@ namespace WireMock.Transformers.Handlebars
|
||||
|
||||
public HandlebarsContextFactory([NotNull] IFileSystemHandler fileSystemHandler, [CanBeNull] Action<IHandlebars, IFileSystemHandler> action)
|
||||
{
|
||||
_fileSystemHandler = fileSystemHandler ?? throw new ArgumentNullException(nameof(fileSystemHandler));
|
||||
_fileSystemHandler = Guard.NotNull(fileSystemHandler);
|
||||
_action = action;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Transformers
|
||||
{
|
||||
interface ITransformer
|
||||
{
|
||||
ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile);
|
||||
|
||||
(IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers);
|
||||
}
|
||||
namespace WireMock.Transformers
|
||||
{
|
||||
interface ITransformer
|
||||
{
|
||||
ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options);
|
||||
|
||||
(IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Scriban;
|
||||
using Stef.Validation;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Types;
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace WireMock.Transformers.Scriban
|
||||
|
||||
public ScribanContext(IFileSystemHandler fileSystemHandler, TransformerType transformerType)
|
||||
{
|
||||
FileSystemHandler = fileSystemHandler ?? throw new ArgumentNullException(nameof(fileSystemHandler));
|
||||
FileSystemHandler = Guard.NotNull(fileSystemHandler);
|
||||
_transformerType = transformerType;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Types;
|
||||
using WireMock.Validation;
|
||||
using Stef.Validation;
|
||||
|
||||
namespace WireMock.Transformers.Scriban
|
||||
{
|
||||
@@ -11,11 +11,8 @@ namespace WireMock.Transformers.Scriban
|
||||
|
||||
public ScribanContextFactory(IFileSystemHandler fileSystemHandler, TransformerType transformerType)
|
||||
{
|
||||
Check.NotNull(fileSystemHandler, nameof(fileSystemHandler));
|
||||
Check.Condition(transformerType, t => t == TransformerType.Scriban || t == TransformerType.ScribanDotLiquid, nameof(transformerType));
|
||||
|
||||
_fileSystemHandler = fileSystemHandler;
|
||||
_transformerType = transformerType;
|
||||
_fileSystemHandler = Guard.NotNull(fileSystemHandler);
|
||||
_transformerType = Guard.Condition(transformerType, t => t == TransformerType.Scriban || t == TransformerType.ScribanDotLiquid);
|
||||
}
|
||||
|
||||
public ITransformerContext Create()
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace WireMock.Transformers
|
||||
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
|
||||
}
|
||||
|
||||
public (IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers)
|
||||
public (IBodyData BodyData, IDictionary<string, WireMockList<string>> Headers) Transform(RequestMessage originalRequestMessage, ResponseMessage originalResponseMessage, IBodyData bodyData, IDictionary<string, WireMockList<string>> headers, ReplaceNodeOptions options)
|
||||
{
|
||||
var transformerContext = _factory.Create();
|
||||
|
||||
@@ -31,13 +31,13 @@ namespace WireMock.Transformers
|
||||
IBodyData newBodyData = null;
|
||||
if (bodyData?.DetectedBodyType != null)
|
||||
{
|
||||
newBodyData = TransformBodyData(transformerContext, model, bodyData, false);
|
||||
newBodyData = TransformBodyData(transformerContext, options, model, bodyData, false);
|
||||
}
|
||||
|
||||
return (newBodyData, TransformHeaders(transformerContext, model, headers));
|
||||
}
|
||||
|
||||
public ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile)
|
||||
public ResponseMessage Transform(RequestMessage requestMessage, ResponseMessage original, bool useTransformerForBodyAsFile, ReplaceNodeOptions options)
|
||||
{
|
||||
var transformerContext = _factory.Create();
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace WireMock.Transformers
|
||||
|
||||
if (original.BodyData?.DetectedBodyType != null)
|
||||
{
|
||||
responseMessage.BodyData = TransformBodyData(transformerContext, model, original.BodyData, useTransformerForBodyAsFile);
|
||||
responseMessage.BodyData = TransformBodyData(transformerContext, options, model, original.BodyData, useTransformerForBodyAsFile);
|
||||
|
||||
if (original.BodyData.DetectedBodyType == BodyType.String)
|
||||
{
|
||||
@@ -77,12 +77,12 @@ namespace WireMock.Transformers
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
private static IBodyData TransformBodyData(ITransformerContext transformerContext, object model, IBodyData original, bool useTransformerForBodyAsFile)
|
||||
private static IBodyData TransformBodyData(ITransformerContext transformerContext, ReplaceNodeOptions options, object model, IBodyData original, bool useTransformerForBodyAsFile)
|
||||
{
|
||||
switch (original?.DetectedBodyType)
|
||||
{
|
||||
case BodyType.Json:
|
||||
return TransformBodyAsJson(transformerContext, model, original);
|
||||
return TransformBodyAsJson(transformerContext, options, model, original);
|
||||
|
||||
case BodyType.File:
|
||||
return TransformBodyAsFile(transformerContext, model, original, useTransformerForBodyAsFile);
|
||||
@@ -114,28 +114,28 @@ namespace WireMock.Transformers
|
||||
return newHeaders;
|
||||
}
|
||||
|
||||
private static IBodyData TransformBodyAsJson(ITransformerContext handlebarsContext, object model, IBodyData original)
|
||||
private static IBodyData TransformBodyAsJson(ITransformerContext handlebarsContext, ReplaceNodeOptions options, object model, IBodyData original)
|
||||
{
|
||||
JToken jToken;
|
||||
switch (original.BodyAsJson)
|
||||
{
|
||||
case JObject bodyAsJObject:
|
||||
jToken = bodyAsJObject.DeepClone();
|
||||
WalkNode(handlebarsContext, jToken, model);
|
||||
WalkNode(handlebarsContext, options, jToken, model);
|
||||
break;
|
||||
|
||||
case Array bodyAsArray:
|
||||
jToken = JArray.FromObject(bodyAsArray);
|
||||
WalkNode(handlebarsContext, jToken, model);
|
||||
WalkNode(handlebarsContext, options, jToken, model);
|
||||
break;
|
||||
|
||||
case string bodyAsString:
|
||||
jToken = ReplaceSingleNode(handlebarsContext, bodyAsString, model);
|
||||
jToken = ReplaceSingleNode(handlebarsContext, options, bodyAsString, model);
|
||||
break;
|
||||
|
||||
default:
|
||||
jToken = JObject.FromObject(original.BodyAsJson);
|
||||
WalkNode(handlebarsContext, jToken, model);
|
||||
WalkNode(handlebarsContext, options, jToken, model);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace WireMock.Transformers
|
||||
};
|
||||
}
|
||||
|
||||
private static JToken ReplaceSingleNode(ITransformerContext handlebarsContext, string stringValue, object model)
|
||||
private static JToken ReplaceSingleNode(ITransformerContext handlebarsContext, ReplaceNodeOptions options, string stringValue, object model)
|
||||
{
|
||||
string transformedString = handlebarsContext.ParseAndRender(stringValue, model);
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace WireMock.Transformers
|
||||
JObject dummy = JObject.Parse($"{{ \"{property}\": null }}");
|
||||
JToken node = dummy[property];
|
||||
|
||||
ReplaceNodeValue(node, transformedString);
|
||||
ReplaceNodeValue(options, node, transformedString);
|
||||
|
||||
return dummy[property];
|
||||
}
|
||||
@@ -166,44 +166,47 @@ namespace WireMock.Transformers
|
||||
return stringValue;
|
||||
}
|
||||
|
||||
private static void WalkNode(ITransformerContext handlebarsContext, JToken node, object model)
|
||||
private static void WalkNode(ITransformerContext handlebarsContext, ReplaceNodeOptions options, JToken node, object model)
|
||||
{
|
||||
if (node.Type == JTokenType.Object)
|
||||
switch (node.Type)
|
||||
{
|
||||
// In case of Object, loop all children. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||
foreach (JProperty child in node.Children<JProperty>().ToArray())
|
||||
{
|
||||
WalkNode(handlebarsContext, child.Value, model);
|
||||
}
|
||||
}
|
||||
else if (node.Type == JTokenType.Array)
|
||||
{
|
||||
// In case of Array, loop all items. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||
foreach (JToken child in node.Children().ToArray())
|
||||
{
|
||||
WalkNode(handlebarsContext, child, model);
|
||||
}
|
||||
}
|
||||
else if (node.Type == JTokenType.String)
|
||||
{
|
||||
// In case of string, try to transform the value.
|
||||
string stringValue = node.Value<string>();
|
||||
if (string.IsNullOrEmpty(stringValue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
case JTokenType.Object:
|
||||
// In case of Object, loop all children. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||
foreach (var child in node.Children<JProperty>().ToArray())
|
||||
{
|
||||
WalkNode(handlebarsContext, options, child.Value, model);
|
||||
}
|
||||
break;
|
||||
|
||||
string transformedString = handlebarsContext.ParseAndRender(stringValue, model);
|
||||
if (!string.Equals(stringValue, transformedString))
|
||||
{
|
||||
ReplaceNodeValue(node, transformedString);
|
||||
}
|
||||
case JTokenType.Array:
|
||||
// In case of Array, loop all items. Do a ToArray() to avoid `Collection was modified` exceptions.
|
||||
foreach (var child in node.Children().ToArray())
|
||||
{
|
||||
WalkNode(handlebarsContext, options, child, model);
|
||||
}
|
||||
break;
|
||||
|
||||
case JTokenType.String:
|
||||
// In case of string, try to transform the value.
|
||||
string stringValue = node.Value<string>();
|
||||
if (string.IsNullOrEmpty(stringValue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string transformed = handlebarsContext.ParseAndRender(stringValue, model);
|
||||
if (!string.Equals(stringValue, transformed))
|
||||
{
|
||||
ReplaceNodeValue(options, node, transformed);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReplaceNodeValue(JToken node, string stringValue)
|
||||
private static void ReplaceNodeValue(ReplaceNodeOptions options, JToken node, string transformedString)
|
||||
{
|
||||
if (bool.TryParse(stringValue, out bool valueAsBoolean))
|
||||
StringUtils.TryParseQuotedString(transformedString, out var result, out _);
|
||||
if (bool.TryParse(result, out var valueAsBoolean) || bool.TryParse(transformedString, out valueAsBoolean))
|
||||
{
|
||||
node.Replace(valueAsBoolean);
|
||||
return;
|
||||
@@ -213,12 +216,12 @@ namespace WireMock.Transformers
|
||||
try
|
||||
{
|
||||
// Try to convert this string into a JsonObject
|
||||
value = JToken.Parse(stringValue);
|
||||
value = JToken.Parse(transformedString);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
// Ignore JsonException and just keep string value and convert to JToken
|
||||
value = stringValue;
|
||||
value = transformedString;
|
||||
}
|
||||
|
||||
node.Replace(value);
|
||||
@@ -248,18 +251,15 @@ namespace WireMock.Transformers
|
||||
BodyAsFile = transformedBodyAsFilename
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
string text = handlebarsContext.FileSystemHandler.ReadResponseBodyAsString(transformedBodyAsFilename);
|
||||
|
||||
return new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.String,
|
||||
DetectedBodyTypeFromContentType = original.DetectedBodyTypeFromContentType,
|
||||
BodyAsString = handlebarsContext.ParseAndRender(text, model),
|
||||
BodyAsFile = transformedBodyAsFilename
|
||||
};
|
||||
}
|
||||
string text = handlebarsContext.FileSystemHandler.ReadResponseBodyAsString(transformedBodyAsFilename);
|
||||
return new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.String,
|
||||
DetectedBodyTypeFromContentType = original.DetectedBodyTypeFromContentType,
|
||||
BodyAsString = handlebarsContext.ParseAndRender(text, model),
|
||||
BodyAsFile = transformedBodyAsFilename
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user