mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-11 21:07:44 +01:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eec9c486a5 | ||
|
|
b5ae087b95 | ||
|
|
1d1ff4a418 | ||
|
|
3e1c3598f7 | ||
|
|
12b868401d | ||
|
|
a7d283e12b | ||
|
|
5280970765 | ||
|
|
6943b90da6 | ||
|
|
4a434b5dba | ||
|
|
3dafd2e725 | ||
|
|
c6e4608039 | ||
|
|
57f89a06e1 | ||
|
|
4d80eb53fe | ||
|
|
13c002fede | ||
|
|
9db6e800ad | ||
|
|
897ee9ffe3 | ||
|
|
8865543bf1 | ||
|
|
48cfd2d20e | ||
|
|
71d2660aff | ||
|
|
7f2a42de96 | ||
|
|
c333b8b263 | ||
|
|
32ddd48321 | ||
|
|
260abf5275 | ||
|
|
d3b2422ec1 | ||
|
|
823917a4ab | ||
|
|
1e968106d1 | ||
|
|
49e10ed20f | ||
|
|
c3ec3a66b3 | ||
|
|
5644491942 | ||
|
|
6e5e629525 | ||
|
|
77ee123340 | ||
|
|
ae2a05e86b | ||
|
|
0e06cf6346 | ||
|
|
e9db520cc3 | ||
|
|
a0e661fae9 | ||
|
|
25666152bb | ||
|
|
6f5eeb5359 | ||
|
|
7ca2095576 | ||
|
|
74edad517b |
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,3 +1,42 @@
|
||||
# 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)
|
||||
- [#534](https://github.com/WireMock-Net/WireMock.Net/issues/534) - Mock server not answer if integrated in Xamarin UITest project [bug]
|
||||
- [#567](https://github.com/WireMock-Net/WireMock.Net/issues/567) - Can't start WireMock.Net server in Xamarin.UITest project (.NET Framework 4.7.2) on MacOS [bug]
|
||||
- [#685](https://github.com/WireMock-Net/WireMock.Net/issues/685) - GuidWildcardMatcher to match on GUIDs [feature]
|
||||
|
||||
# 1.4.29 (12 December 2021)
|
||||
- [#699](https://github.com/WireMock-Net/WireMock.Net/pull/699) - GUID Pattern support in RegexMatcher contributed by [brogdogg](https://github.com/brogdogg)
|
||||
- [#700](https://github.com/WireMock-Net/WireMock.Net/pull/700) - RegexExtended in settings [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
# 1.4.28 (01 December 2021)
|
||||
- [#686](https://github.com/WireMock-Net/WireMock.Net/pull/686) - [Snyk] Security upgrade Microsoft.Owin from 4.0.0 to 4.1.1 [dependencies] contributed by [snyk-bot](https://github.com/snyk-bot)
|
||||
- [#688](https://github.com/WireMock-Net/WireMock.Net/pull/688) - Bump System.Text.Encodings.Web from 4.5.0 to 4.5.1 in /examples/WireMock.Net.Console.Net472.Classic [dependencies] contributed by [dependabot[bot]](https://github.com/apps/dependabot)
|
||||
- [#689](https://github.com/WireMock-Net/WireMock.Net/pull/689) - Upgrade some NuGet's (Codecov, coverlet, Moq and NFluent) [dependencies] contributed by [StefH](https://github.com/StefH)
|
||||
- [#691](https://github.com/WireMock-Net/WireMock.Net/pull/691) - Update the OpenApiPathsMapper to handle Value/Wildcard [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#694](https://github.com/WireMock-Net/WireMock.Net/pull/694) - RamlToOpenAPI updated to 0.5.0 [feature] contributed by [mcheguini](https://github.com/mcheguini)
|
||||
- [#695](https://github.com/WireMock-Net/WireMock.Net/pull/695) - Allow configure IgnoreCase in settings [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#696](https://github.com/WireMock-Net/WireMock.Net/pull/696) - Filter required property in headers, query params, request body [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#666](https://github.com/WireMock-Net/WireMock.Net/issues/666) - Example is not working as expected [bug]
|
||||
- [#692](https://github.com/WireMock-Net/WireMock.Net/issues/692) - Case insensitive and ignoring optional path and header parameters in OpenApiPathsMapper [feature]
|
||||
|
||||
# 1.4.27 (17 November 2021)
|
||||
- [#678](https://github.com/WireMock-Net/WireMock.Net/pull/678) - Support RequestBody [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#680](https://github.com/WireMock-Net/WireMock.Net/pull/680) - Support examples in properties [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#681](https://github.com/WireMock-Net/WireMock.Net/pull/681) - Support enums in properties [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
|
||||
# 1.4.26 (04 November 2021)
|
||||
- [#670](https://github.com/WireMock-Net/WireMock.Net/pull/670) - Improve method MapSchemaToObject to support array and object [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#673](https://github.com/WireMock-Net/WireMock.Net/pull/673) - Support examples random data generation contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#675](https://github.com/WireMock-Net/WireMock.Net/pull/675) - Support basepath from servers contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#676](https://github.com/WireMock-Net/WireMock.Net/pull/676) - Fix random generate data in url no spaces [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
|
||||
# 1.4.25 (27 October 2021)
|
||||
- [#661](https://github.com/WireMock-Net/WireMock.Net/pull/661) - Add TimeSettings (Start, End and TTL) [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#664](https://github.com/WireMock-Net/WireMock.Net/pull/664) - Support Array in OpenApiParser [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
- [#667](https://github.com/WireMock-Net/WireMock.Net/pull/667) - Add JsonPartialWildcardMatcher [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#669](https://github.com/WireMock-Net/WireMock.Net/pull/669) - Support Schema Example and Support AllOf in definitions [feature] contributed by [StefH](https://github.com/StefH)
|
||||
|
||||
# 1.4.24 (20 October 2021)
|
||||
- [#637](https://github.com/WireMock-Net/WireMock.Net/pull/637) - Add support for AzureAD authentication for REST admin interface [feature] contributed by [StefH](https://github.com/StefH)
|
||||
- [#643](https://github.com/WireMock-Net/WireMock.Net/pull/643) - Support edge case: first object, next an array. [feature] contributed by [leolplex](https://github.com/leolplex)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<VersionPrefix>1.4.24</VersionPrefix>
|
||||
<VersionPrefix>1.4.30</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.24
|
||||
SET version=1.4.30
|
||||
|
||||
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc duplicate --version %version% --token %GH_TOKEN%
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# 1.4.24 (20 October 2021)
|
||||
- #637 Add support for AzureAD authentication for REST admin interface [feature]
|
||||
- #643 Support edge case: first object, next an array. [feature]
|
||||
- #644 Mapping headers in OpenAPI [feature]
|
||||
- #649 Refactor method name MapHeaders and httpStatusCode
|
||||
- #651 Implement PatternAsFile for StringMatcher [feature]
|
||||
- #654 Update NotNullOrEmptyMatcher to also implement IStringMatcher [feature]
|
||||
# 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]
|
||||
|
||||
The full release notes can be found here: https://github.com/WireMock-Net/WireMock.Net/blob/master/CHANGELOG.md
|
||||
@@ -1,4 +1,5 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AD/@EntryIndexedValue">AD</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CS/@EntryIndexedValue">CS</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||
@@ -11,11 +12,15 @@
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XUA/@EntryIndexedValue">XUA</s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Flurl/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=funcs/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=guidb/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Heyenrath/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Jmes/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Raml/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=randomizer/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Scriban/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Sigil/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Stef/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Victoor/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Webhook/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Webhooks/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@@ -7,6 +7,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
internal class CustomFileSystemFileHandler : IFileSystemHandler
|
||||
{
|
||||
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings");
|
||||
private static readonly string UnmatchedRequestsFolder = Path.Combine("requests", "unmatched");
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/>
|
||||
public bool FolderExists(string path)
|
||||
@@ -86,6 +87,21 @@ namespace WireMock.Net.ConsoleApplication
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.GetUnmatchedRequestsFolder"/>
|
||||
public string GetUnmatchedRequestsFolder()
|
||||
{
|
||||
return Path.Combine(@"c:\temp-wiremock", UnmatchedRequestsFolder);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteUnmatchedRequest"/>
|
||||
public void WriteUnmatchedRequest(string filename, string text)
|
||||
{
|
||||
var folder = GetUnmatchedRequestsFolder();
|
||||
Directory.CreateDirectory(folder);
|
||||
|
||||
File.WriteAllText(Path.Combine(folder, filename), text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adjusts the path to the MappingFolder.
|
||||
/// </summary>
|
||||
|
||||
@@ -556,7 +556,7 @@ namespace WireMock.Net.ConsoleApplication
|
||||
.Given(Request.Create().WithPath("/random200or505async").UsingGet())
|
||||
.RespondWith(Response.Create().WithCallback(async request =>
|
||||
{
|
||||
await Task.Delay(1);
|
||||
await Task.Delay(1).ConfigureAwait(false);
|
||||
|
||||
int code = new Random().Next(1, 2) == 1 ? 505 : 200;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net472" />
|
||||
<package id="System.Security.Cryptography.Cng" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Security.Principal.Windows" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Text.Encodings.Web" version="4.5.0" targetFramework="net472" />
|
||||
<package id="System.Text.Encodings.Web" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
<package id="WireMock.Net" version="1.4.2" targetFramework="net472" />
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "Swagger API Team"
|
||||
},
|
||||
"license": {
|
||||
"name": "MIT"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.io",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"get": {
|
||||
"description": "Returns all pets from the system that the user has access to",
|
||||
"operationId": "findPets",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [{
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"example": [{
|
||||
"name": "MEXAMPLE",
|
||||
"tag": "MEXAMPLE",
|
||||
"id": 9988
|
||||
}, {
|
||||
"name": "OtherExample",
|
||||
"tag": "OtherExample",
|
||||
"id": 8877
|
||||
}],
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Creates a new pet in the store. Duplicates are allowed",
|
||||
"operationId": "addPet",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [{
|
||||
"name": "pet",
|
||||
"in": "body",
|
||||
"description": "Pet to add to the store",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/NewPet"
|
||||
}
|
||||
}],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pet": {
|
||||
"get": {
|
||||
"description": "Returns a pet from the system that the user has access to",
|
||||
"operationId": "findPet",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [{
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"collectionFormat": "csv"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pets/{id}": {
|
||||
"get": {
|
||||
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
|
||||
"operationId": "findPetById",
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html"
|
||||
],
|
||||
"parameters": [{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to fetch",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Pet"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "deletes a single pet based on the ID supplied",
|
||||
"operationId": "deletePet",
|
||||
"parameters": [{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to delete",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "pet deleted"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/ErrorModel"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Pet": {
|
||||
"type": "object",
|
||||
"allOf": [{
|
||||
"$ref": "#/definitions/NewPet"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"id"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"NewPet": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"ErrorModel": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,732 @@
|
||||
swagger: '2.0'
|
||||
info:
|
||||
description: 'This is a sample server Petstore server. Copied from https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml.'
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
termsOfService: 'http://swagger.io/terms/'
|
||||
contact:
|
||||
email: apiteam@swagger.io
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
|
||||
host: petstore.swagger.io
|
||||
basePath: /v2
|
||||
tags:
|
||||
- name: pet
|
||||
description: Everything about your Pets
|
||||
externalDocs:
|
||||
description: Find out more
|
||||
url: 'http://swagger.io'
|
||||
- name: store
|
||||
description: Access to Petstore orders
|
||||
- name: user
|
||||
description: Operations about user
|
||||
externalDocs:
|
||||
description: Find out more about our store
|
||||
url: 'http://swagger.io'
|
||||
schemes:
|
||||
- http
|
||||
paths:
|
||||
/pet:
|
||||
post:
|
||||
tags:
|
||||
- pet
|
||||
summary: Add a new pet to the store
|
||||
description: ''
|
||||
operationId: addPet
|
||||
consumes:
|
||||
- application/json
|
||||
- application/xml
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: Pet object that needs to be added to the store
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Pet'
|
||||
responses:
|
||||
'405':
|
||||
description: Invalid input
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
put:
|
||||
tags:
|
||||
- pet
|
||||
summary: Update an existing pet
|
||||
description: ''
|
||||
operationId: updatePet
|
||||
consumes:
|
||||
- application/json
|
||||
- application/xml
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: Pet object that needs to be added to the store
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Pet'
|
||||
responses:
|
||||
'400':
|
||||
description: Invalid ID supplied
|
||||
'404':
|
||||
description: Pet not found
|
||||
'405':
|
||||
description: Validation exception
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
/pet/findByStatus:
|
||||
get:
|
||||
tags:
|
||||
- pet
|
||||
summary: Finds Pets by status
|
||||
description: Multiple status values can be provided with comma separated strings
|
||||
operationId: findPetsByStatus
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: status
|
||||
in: query
|
||||
description: Status values that need to be considered for filter
|
||||
required: true
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- available
|
||||
- pending
|
||||
- sold
|
||||
default: available
|
||||
collectionFormat: csv
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Pet'
|
||||
'400':
|
||||
description: Invalid status value
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
/pet/findByTags:
|
||||
get:
|
||||
tags:
|
||||
- pet
|
||||
summary: Finds Pets by tags
|
||||
description: 'Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.'
|
||||
operationId: findPetsByTags
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: tags
|
||||
in: query
|
||||
description: Tags to filter by
|
||||
required: true
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
collectionFormat: csv
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Pet'
|
||||
'400':
|
||||
description: Invalid tag value
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
deprecated: true
|
||||
'/pet/{petId}':
|
||||
get:
|
||||
tags:
|
||||
- pet
|
||||
summary: Find pet by ID
|
||||
description: Returns a single pet
|
||||
operationId: getPetById
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
description: ID of pet to return
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/Pet'
|
||||
'400':
|
||||
description: Invalid ID supplied
|
||||
'404':
|
||||
description: Pet not found
|
||||
security:
|
||||
- api_key: []
|
||||
post:
|
||||
tags:
|
||||
- pet
|
||||
summary: Updates a pet in the store with form data
|
||||
description: ''
|
||||
operationId: updatePetWithForm
|
||||
consumes:
|
||||
- application/x-www-form-urlencoded
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
description: ID of pet that needs to be updated
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
- name: name
|
||||
in: formData
|
||||
description: Updated name of the pet
|
||||
required: false
|
||||
type: string
|
||||
- name: status
|
||||
in: formData
|
||||
description: Updated status of the pet
|
||||
required: false
|
||||
type: string
|
||||
responses:
|
||||
'405':
|
||||
description: Invalid input
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
delete:
|
||||
tags:
|
||||
- pet
|
||||
summary: Deletes a pet
|
||||
description: ''
|
||||
operationId: deletePet
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: api_key
|
||||
in: header
|
||||
required: false
|
||||
type: string
|
||||
- name: petId
|
||||
in: path
|
||||
description: Pet id to delete
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
'400':
|
||||
description: Invalid pet value
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
'/pet/{petId}/uploadImage':
|
||||
post:
|
||||
tags:
|
||||
- pet
|
||||
summary: uploads an image
|
||||
description: ''
|
||||
operationId: uploadFile
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
produces:
|
||||
- application/json
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
description: ID of pet to update
|
||||
required: true
|
||||
type: integer
|
||||
format: int64
|
||||
- name: additionalMetadata
|
||||
in: formData
|
||||
description: Additional data to pass to server
|
||||
required: false
|
||||
type: string
|
||||
- name: file
|
||||
in: formData
|
||||
description: file to upload
|
||||
required: false
|
||||
type: file
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/ApiResponse'
|
||||
security:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
/store/inventory:
|
||||
get:
|
||||
tags:
|
||||
- store
|
||||
summary: Returns pet inventories by status
|
||||
description: Returns a map of status codes to quantities
|
||||
operationId: getInventory
|
||||
produces:
|
||||
- application/json
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: integer
|
||||
format: int32
|
||||
security:
|
||||
- api_key: []
|
||||
/store/order:
|
||||
post:
|
||||
tags:
|
||||
- store
|
||||
summary: Place an order for a pet
|
||||
description: ''
|
||||
operationId: placeOrder
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: order placed for purchasing the pet
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/Order'
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/Order'
|
||||
'400':
|
||||
description: Invalid Order
|
||||
'/store/order/{orderId}':
|
||||
get:
|
||||
tags:
|
||||
- store
|
||||
summary: Find purchase order by ID
|
||||
description: 'For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions'
|
||||
operationId: getOrderById
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: orderId
|
||||
in: path
|
||||
description: ID of pet that needs to be fetched
|
||||
required: true
|
||||
type: integer
|
||||
maximum: 5
|
||||
minimum: 1
|
||||
format: int64
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/Order'
|
||||
'400':
|
||||
description: Invalid ID supplied
|
||||
'404':
|
||||
description: Order not found
|
||||
delete:
|
||||
tags:
|
||||
- store
|
||||
summary: Delete purchase order by ID
|
||||
description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
operationId: deleteOrder
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: orderId
|
||||
in: path
|
||||
description: ID of the order that needs to be deleted
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
'400':
|
||||
description: Invalid ID supplied
|
||||
'404':
|
||||
description: Order not found
|
||||
/user:
|
||||
post:
|
||||
tags:
|
||||
- user
|
||||
summary: Create user
|
||||
description: This can only be done by the logged in user.
|
||||
operationId: createUser
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: Created user object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/User'
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
/user/createWithArray:
|
||||
post:
|
||||
tags:
|
||||
- user
|
||||
summary: Creates list of users with given input array
|
||||
description: ''
|
||||
operationId: createUsersWithArrayInput
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: List of user object
|
||||
required: true
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/User'
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
/user/createWithList:
|
||||
post:
|
||||
tags:
|
||||
- user
|
||||
summary: Creates list of users with given input array
|
||||
description: ''
|
||||
operationId: createUsersWithListInput
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- in: body
|
||||
name: body
|
||||
description: List of user object
|
||||
required: true
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/User'
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
/user/login:
|
||||
get:
|
||||
tags:
|
||||
- user
|
||||
summary: Logs user into the system
|
||||
description: ''
|
||||
operationId: loginUser
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: username
|
||||
in: query
|
||||
description: The user name for login
|
||||
required: true
|
||||
type: string
|
||||
- name: password
|
||||
in: query
|
||||
description: The password for login in clear text
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
type: string
|
||||
headers:
|
||||
X-Rate-Limit:
|
||||
type: integer
|
||||
format: int32
|
||||
description: calls per hour allowed by the user
|
||||
X-Expires-After:
|
||||
type: string
|
||||
format: date-time
|
||||
description: date in UTC when toekn expires
|
||||
'400':
|
||||
description: Invalid username/password supplied
|
||||
/user/logout:
|
||||
get:
|
||||
tags:
|
||||
- user
|
||||
summary: Logs out current logged in user session
|
||||
description: ''
|
||||
operationId: logoutUser
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters: []
|
||||
responses:
|
||||
default:
|
||||
description: successful operation
|
||||
'/user/{username}':
|
||||
get:
|
||||
tags:
|
||||
- user
|
||||
summary: Get user by user name
|
||||
description: ''
|
||||
operationId: getUserByName
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: username
|
||||
in: path
|
||||
description: 'The name that needs to be fetched. Use user1 for testing.'
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/User'
|
||||
'400':
|
||||
description: Invalid username supplied
|
||||
'404':
|
||||
description: User not found
|
||||
put:
|
||||
tags:
|
||||
- user
|
||||
summary: Updated user
|
||||
description: This can only be done by the logged in user.
|
||||
operationId: updateUser
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: username
|
||||
in: path
|
||||
description: name that need to be deleted
|
||||
required: true
|
||||
type: string
|
||||
- in: body
|
||||
name: body
|
||||
description: Updated user object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/User'
|
||||
responses:
|
||||
'400':
|
||||
description: Invalid user supplied
|
||||
'404':
|
||||
description: User not found
|
||||
delete:
|
||||
tags:
|
||||
- user
|
||||
summary: Delete user
|
||||
description: This can only be done by the logged in user.
|
||||
operationId: deleteUser
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters:
|
||||
- name: username
|
||||
in: path
|
||||
description: The name that needs to be deleted
|
||||
required: true
|
||||
type: string
|
||||
responses:
|
||||
'400':
|
||||
description: Invalid username supplied
|
||||
'404':
|
||||
description: User not found
|
||||
securityDefinitions:
|
||||
petstore_auth:
|
||||
type: oauth2
|
||||
authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog'
|
||||
flow: implicit
|
||||
scopes:
|
||||
'write:pets': modify pets in your account
|
||||
'read:pets': read your pets
|
||||
api_key:
|
||||
type: apiKey
|
||||
name: api_key
|
||||
in: header
|
||||
definitions:
|
||||
Order:
|
||||
title: Pet Order
|
||||
description: An order for a pets from the pet store
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
petId:
|
||||
type: integer
|
||||
format: int64
|
||||
quantity:
|
||||
type: integer
|
||||
format: int32
|
||||
shipDate:
|
||||
type: string
|
||||
format: date-time
|
||||
status:
|
||||
type: string
|
||||
description: Order Status
|
||||
enum:
|
||||
- placed
|
||||
- approved
|
||||
- delivered
|
||||
complete:
|
||||
type: boolean
|
||||
default: false
|
||||
xml:
|
||||
name: Order
|
||||
Category:
|
||||
title: Pet category
|
||||
description: A category for a pet
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
xml:
|
||||
name: Category
|
||||
User:
|
||||
title: a User
|
||||
description: A User who is purchasing from the pet store
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
username:
|
||||
type: string
|
||||
firstName:
|
||||
type: string
|
||||
lastName:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
userStatus:
|
||||
type: integer
|
||||
format: int32
|
||||
description: User Status
|
||||
xml:
|
||||
name: User
|
||||
Tag:
|
||||
title: Pet Tag
|
||||
description: A tag for a pet
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
xml:
|
||||
name: Tag
|
||||
Pet:
|
||||
title: a Pet
|
||||
description: A pet for sale in the pet store
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- photoUrls
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
category:
|
||||
$ref: '#/definitions/Category'
|
||||
name:
|
||||
type: string
|
||||
example: doggie
|
||||
photoUrls:
|
||||
type: array
|
||||
xml:
|
||||
name: photoUrl
|
||||
wrapped: true
|
||||
items:
|
||||
type: string
|
||||
tags:
|
||||
type: array
|
||||
xml:
|
||||
name: tag
|
||||
wrapped: true
|
||||
items:
|
||||
$ref: '#/definitions/Tag'
|
||||
status:
|
||||
type: string
|
||||
description: pet status in the store
|
||||
enum:
|
||||
- available
|
||||
- pending
|
||||
- sold
|
||||
xml:
|
||||
name: Pet
|
||||
ApiResponse:
|
||||
title: An uploaded response
|
||||
description: Describes the result of uploading an image resource
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
type:
|
||||
type: string
|
||||
message:
|
||||
type: string
|
||||
#issue: https://github.com/swagger-api/swagger-codegen/issues/7980
|
||||
Amount:
|
||||
type: object
|
||||
description: >
|
||||
some description
|
||||
properties:
|
||||
value:
|
||||
format: double
|
||||
type: number
|
||||
minimum: 0.01
|
||||
maximum: 1000000000000000
|
||||
description: >
|
||||
some description
|
||||
currency:
|
||||
$ref: '#/definitions/Currency'
|
||||
required:
|
||||
- value
|
||||
- currency
|
||||
Currency:
|
||||
type: string
|
||||
pattern: '^[A-Z]{3,3}$'
|
||||
description: >
|
||||
some description
|
||||
externalDocs:
|
||||
description: Find out more about Swagger
|
||||
url: 'http://swagger.io'
|
||||
@@ -0,0 +1,109 @@
|
||||
openapi: "3.0.0"
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Swagger Petstore
|
||||
license:
|
||||
name: MIT
|
||||
servers:
|
||||
- url: http://petstore.swagger.io/v1
|
||||
paths:
|
||||
/pets:
|
||||
get:
|
||||
summary: List all pets
|
||||
operationId: listPets
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: limit
|
||||
in: query
|
||||
description: How many items to return at one time (max 100)
|
||||
required: false
|
||||
schema:
|
||||
type: integer
|
||||
format: int32
|
||||
responses:
|
||||
200:
|
||||
description: An paged array of pets
|
||||
headers:
|
||||
x-next:
|
||||
description: A link to the next page of responses
|
||||
schema:
|
||||
type: string
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
post:
|
||||
summary: Create a pet
|
||||
operationId: createPets
|
||||
tags:
|
||||
- pets
|
||||
responses:
|
||||
201:
|
||||
description: Null response
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
/pets/{petId}:
|
||||
get:
|
||||
summary: Info for a specific pet
|
||||
operationId: showPetById
|
||||
tags:
|
||||
- pets
|
||||
parameters:
|
||||
- name: petId
|
||||
in: path
|
||||
required: true
|
||||
description: The id of the pet to retrieve
|
||||
schema:
|
||||
type: string
|
||||
responses:
|
||||
200:
|
||||
description: Expected response to a valid request
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Pets"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
components:
|
||||
schemas:
|
||||
Pet:
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
format: int64
|
||||
name:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
Pets:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
Error:
|
||||
required:
|
||||
- code
|
||||
- message
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
openapi: 3.0.1
|
||||
info:
|
||||
title: API_Test
|
||||
version: v1
|
||||
paths:
|
||||
/WeatherForecast:
|
||||
get:
|
||||
tags:
|
||||
- WeatherForecast
|
||||
parameters:
|
||||
- in: "header"
|
||||
name: X-Correlation-ID
|
||||
type: "string"
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/WeatherForecast'
|
||||
/leolplex:
|
||||
get:
|
||||
tags:
|
||||
- WeatherForecast
|
||||
parameters:
|
||||
- in: "header"
|
||||
name: X-Correlation-ID
|
||||
type: "string"
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
content:
|
||||
application/json:
|
||||
example:
|
||||
- date: 2021-10-21T09:13:00.552+00:00
|
||||
temperatureC: 111
|
||||
temperatureF: 111
|
||||
summary: Just-summary
|
||||
- date: 2021-10-21T09:13:00.000+00:00
|
||||
temperatureC: 222
|
||||
temperatureF: 222
|
||||
summary: Just-summary2
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/WeatherForecast'
|
||||
/exampleop:
|
||||
get:
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
content:
|
||||
application/json:
|
||||
example:
|
||||
id: 1
|
||||
name: get food
|
||||
completed: false
|
||||
schema:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
name:
|
||||
type: string
|
||||
completed:
|
||||
type: boolean
|
||||
completed_at:
|
||||
type: string
|
||||
format: date-time
|
||||
nullable: true
|
||||
required:
|
||||
- id
|
||||
- name
|
||||
- completed
|
||||
components:
|
||||
schemas:
|
||||
WeatherForecast:
|
||||
type: object
|
||||
properties:
|
||||
date:
|
||||
type: string
|
||||
format: date-time
|
||||
temperatureC:
|
||||
type: integer
|
||||
format: int32
|
||||
temperatureF:
|
||||
type: integer
|
||||
format: int32
|
||||
readOnly: true
|
||||
summary:
|
||||
type: string
|
||||
nullable: true
|
||||
additionalProperties: false
|
||||
@@ -1,5 +1,3 @@
|
||||
using Microsoft.OpenApi.Readers;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
@@ -7,15 +5,23 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
{
|
||||
class Program
|
||||
{
|
||||
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
Formatting = Formatting.Indented
|
||||
};
|
||||
|
||||
private const string Folder = "OpenApiFiles";
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Run.RunServer("petstore-openapi3.json");
|
||||
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();
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Admin.Mappings;
|
||||
@@ -13,19 +13,18 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
{
|
||||
public static class Run
|
||||
{
|
||||
public static void RunServer(string path)
|
||||
public static WireMockServer RunServer(string path, string url, bool dynamicExamples = true)
|
||||
{
|
||||
string url1 = "http://localhost:9091/";
|
||||
|
||||
var server = WireMockServer.Start(new WireMockServerSettings
|
||||
{
|
||||
AllowCSharpCodeMatcher = true,
|
||||
Urls = new[] { url1 },
|
||||
Urls = new[] { url },
|
||||
StartAdminInterface = true,
|
||||
ReadStaticMappings = false,
|
||||
WatchStaticMappings = false,
|
||||
WatchStaticMappingsInSubdirectories = false,
|
||||
Logger = new WireMockConsoleLogger()
|
||||
Logger = new WireMockConsoleLogger(),
|
||||
SaveUnmatchedRequests = true
|
||||
});
|
||||
Console.WriteLine("WireMockServer listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
@@ -33,14 +32,14 @@ namespace WireMock.Net.OpenApiParser.ConsoleApp
|
||||
|
||||
var settings = new WireMockOpenApiParserSettings
|
||||
{
|
||||
PathPatternToUse = ExampleValueType.Wildcard
|
||||
DynamicExamples = dynamicExamples,
|
||||
PathPatternToUse = ExampleValueType.Wildcard,
|
||||
HeaderPatternToUse = ExampleValueType.Wildcard
|
||||
};
|
||||
|
||||
server.WithMappingFromOpenApiFile(path, settings, out var diag);
|
||||
|
||||
Console.WriteLine("Press any key to stop the server");
|
||||
System.Console.ReadKey();
|
||||
server.Stop();
|
||||
return server;
|
||||
}
|
||||
|
||||
public static void RunServer(IEnumerable<MappingModel> mappings)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -15,6 +15,21 @@
|
||||
<None Update="infura.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\openAPIExamples.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\Swagger_Petstore_V2.0.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\Swagger_Petstore_V2.0.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\Swagger_Petstore_V3.0.0.yaml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="OpenApiFiles\Swagger_Petstore_V3.0.2.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Update="petstore-openapi3.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
|
||||
@@ -2,6 +2,5 @@
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
|
||||
<add key="coverlet" value="https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Admin.Mappings
|
||||
{
|
||||
@@ -13,6 +14,11 @@ namespace WireMock.Admin.Mappings
|
||||
/// </summary>
|
||||
public Guid? Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the TimeSettings when which this mapping should be used.
|
||||
/// </summary>
|
||||
public TimeSettingsModel TimeSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The unique title.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// TimeSettingsModel: Start, End and TTL
|
||||
/// </summary>
|
||||
[FluentBuilder.AutoGenerateBuilder]
|
||||
public class TimeSettingsModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
|
||||
/// </summary>
|
||||
public DateTime? Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
|
||||
/// </summary>
|
||||
public DateTime? End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
|
||||
/// </summary>
|
||||
public int? TTL { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace WireMock.Admin.Settings
|
||||
using System.Text.RegularExpressions;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Admin.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// Settings
|
||||
@@ -40,5 +43,15 @@
|
||||
/// Throw an exception when the Matcher fails because of invalid input. (default set to false).
|
||||
/// </summary>
|
||||
public bool? ThrowExceptionWhenMatcherFails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use the RegexExtended instead of the default <see cref="Regex"/>. (default set to true).
|
||||
/// </summary>
|
||||
public bool? UseRegexExtended { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save unmatched requests to a file using the <see cref="IFileSystemHandler"/>. (default set to false).
|
||||
/// </summary>
|
||||
public bool? SaveUnmatchedRequests { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -96,5 +96,18 @@ namespace WireMock.Handlers
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <returns>The file content as a string.</returns>
|
||||
string ReadFileAsString([NotNull] string filename);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the folder where the unmatched requests should be stored. For local file system, this would be `{CurrentFolder}/requests/unmatched`.
|
||||
/// </summary>
|
||||
/// <returns>The folder name.</returns>
|
||||
string GetUnmatchedRequestsFolder();
|
||||
|
||||
/// <summary>
|
||||
/// Write a unmatched request to the Unmatched RequestsFolder.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <param name="text">The text.</param>
|
||||
void WriteUnmatchedRequest([NotNull] string filename, [NotNull] string text);
|
||||
}
|
||||
}
|
||||
25
src/WireMock.Net.Abstractions/Models/ITimeSettings.cs
Normal file
25
src/WireMock.Net.Abstractions/Models/ITimeSettings.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// TimeSettings: Start, End and TTL
|
||||
/// </summary>
|
||||
public interface ITimeSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
|
||||
/// </summary>
|
||||
DateTime? Start { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
|
||||
/// </summary>
|
||||
DateTime? End { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
|
||||
/// </summary>
|
||||
int? TTL { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
|
||||
<!-- See also https://mstack.nl/blog/20210801-source-generators -->
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<Target Name="CheckIfShouldKillVBCSCompiler" />
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
|
||||
<ProjectReference Include="..\WireMock.Net\WireMock.Net.csproj" />
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#if NET46 || NETSTANDARD2_0
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Extensions
|
||||
{
|
||||
internal static class DictionaryExtensions
|
||||
{
|
||||
public static bool TryAdd<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, TValue value)
|
||||
{
|
||||
if (dictionary is null || dictionary.ContainsKey(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dictionary[key] = value;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -6,7 +6,9 @@ using Microsoft.OpenApi;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Microsoft.OpenApi.Writers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Stef.Validation;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Net.OpenApiParser.Extensions;
|
||||
using WireMock.Net.OpenApiParser.Settings;
|
||||
@@ -17,31 +19,33 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
{
|
||||
internal class OpenApiPathsMapper
|
||||
{
|
||||
private const string HeaderContentType = "Content-Type";
|
||||
|
||||
private readonly WireMockOpenApiParserSettings _settings;
|
||||
private readonly ExampleValueGenerator _exampleValueGenerator;
|
||||
|
||||
public OpenApiPathsMapper(WireMockOpenApiParserSettings settings)
|
||||
{
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_settings = Guard.NotNull(settings, nameof(settings));
|
||||
_exampleValueGenerator = new ExampleValueGenerator(settings);
|
||||
}
|
||||
|
||||
public IEnumerable<MappingModel> ToMappingModels(OpenApiPaths paths)
|
||||
public IEnumerable<MappingModel> ToMappingModels(OpenApiPaths paths, IList<OpenApiServer> servers)
|
||||
{
|
||||
return paths.Select(p => MapPath(p.Key, p.Value)).SelectMany(x => x);
|
||||
return paths.Select(p => MapPath(p.Key, p.Value, servers)).SelectMany(x => x);
|
||||
}
|
||||
|
||||
private IEnumerable<MappingModel> MapPaths(OpenApiPaths paths)
|
||||
private IEnumerable<MappingModel> MapPaths(OpenApiPaths paths, IList<OpenApiServer> servers)
|
||||
{
|
||||
return paths.Select(p => MapPath(p.Key, p.Value)).SelectMany(x => x);
|
||||
return paths.Select(p => MapPath(p.Key, p.Value, servers)).SelectMany(x => x);
|
||||
}
|
||||
|
||||
private IEnumerable<MappingModel> MapPath(string path, OpenApiPathItem pathItem)
|
||||
private IEnumerable<MappingModel> MapPath(string path, OpenApiPathItem pathItem, IList<OpenApiServer> servers)
|
||||
{
|
||||
return pathItem.Operations.Select(o => MapOperationToMappingModel(path, o.Key.ToString().ToUpperInvariant(), o.Value));
|
||||
return pathItem.Operations.Select(o => MapOperationToMappingModel(path, o.Key.ToString().ToUpperInvariant(), o.Value, servers));
|
||||
}
|
||||
|
||||
private MappingModel MapOperationToMappingModel(string path, string httpMethod, OpenApiOperation operation)
|
||||
private MappingModel MapOperationToMappingModel(string path, string httpMethod, OpenApiOperation operation, IList<OpenApiServer> servers)
|
||||
{
|
||||
var queryParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Query);
|
||||
var pathParameters = operation.Parameters.Where(p => p.In == ParameterLocation.Path);
|
||||
@@ -52,8 +56,28 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
TryGetContent(response.Value?.Content, out OpenApiMediaType responseContent, out string responseContentType);
|
||||
var responseSchema = response.Value?.Content?.FirstOrDefault().Value?.Schema;
|
||||
var responseExample = responseContent?.Example;
|
||||
var responseSchemaExample = responseContent?.Schema?.Example;
|
||||
|
||||
var body = responseExample != null ? MapOpenApiAnyToJToken(responseExample) : MapSchemaToObject(responseSchema);
|
||||
var body = responseExample != null ? MapOpenApiAnyToJToken(responseExample) :
|
||||
responseSchemaExample != null ? MapOpenApiAnyToJToken(responseSchemaExample) :
|
||||
MapSchemaToObject(responseSchema);
|
||||
|
||||
var requestBodyModel = new BodyModel();
|
||||
if (operation.RequestBody != null && operation.RequestBody.Content != null && operation.RequestBody.Required)
|
||||
{
|
||||
var request = operation.RequestBody.Content;
|
||||
TryGetContent(request, out OpenApiMediaType requestContent, out string requestContentType);
|
||||
|
||||
var requestBodySchema = operation.RequestBody.Content.First().Value?.Schema;
|
||||
var requestBodyExample = requestContent.Example;
|
||||
var requestBodySchemaExample = requestContent.Schema?.Example;
|
||||
|
||||
var requestBodyMapped = requestBodyExample != null ? MapOpenApiAnyToJToken(requestBodyExample) :
|
||||
requestBodySchemaExample != null ? MapOpenApiAnyToJToken(requestBodySchemaExample) :
|
||||
MapSchemaToObject(requestBodySchema);
|
||||
|
||||
requestBodyModel = MapRequestBody(requestBodyMapped);
|
||||
}
|
||||
|
||||
if (!int.TryParse(response.Key, out var httpStatusCode))
|
||||
{
|
||||
@@ -66,9 +90,10 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
Request = new RequestModel
|
||||
{
|
||||
Methods = new[] { httpMethod },
|
||||
Path = MapPathWithParameters(path, pathParameters),
|
||||
Path = MapBasePath(servers) + MapPathWithParameters(path, pathParameters),
|
||||
Params = MapQueryParameters(queryParameters),
|
||||
Headers = MapRequestHeaders(headers)
|
||||
Headers = MapRequestHeaders(headers),
|
||||
Body = requestBodyModel
|
||||
},
|
||||
Response = new ResponseModel
|
||||
{
|
||||
@@ -79,6 +104,24 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
};
|
||||
}
|
||||
|
||||
private BodyModel MapRequestBody(object requestBody)
|
||||
{
|
||||
if (requestBody == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BodyModel
|
||||
{
|
||||
Matcher = new MatcherModel
|
||||
{
|
||||
Name = "JsonMatcher",
|
||||
Pattern = JsonConvert.SerializeObject(requestBody, Formatting.Indented),
|
||||
IgnoreCase = _settings.RequestBodyIgnoreCase
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private bool TryGetContent(IDictionary<string, OpenApiMediaType> contents, out OpenApiMediaType openApiMediaType, out string contentType)
|
||||
{
|
||||
openApiMediaType = null;
|
||||
@@ -141,6 +184,11 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.AllOf.Count > 0)
|
||||
{
|
||||
jArray.Add(MapSchemaAllOfToObject(schema));
|
||||
}
|
||||
|
||||
return jArray;
|
||||
|
||||
case SchemaType.Boolean:
|
||||
@@ -153,25 +201,16 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
var propertyAsJObject = new JObject();
|
||||
foreach (var schemaProperty in schema.Properties)
|
||||
{
|
||||
string propertyName = schemaProperty.Key;
|
||||
var openApiSchema = schemaProperty.Value;
|
||||
if (openApiSchema.GetSchemaType() == SchemaType.Object || openApiSchema.GetSchemaType() == SchemaType.Array)
|
||||
propertyAsJObject.Add(MapPropertyAsJObject(schemaProperty.Value, schemaProperty.Key));
|
||||
}
|
||||
if (schema.AllOf.Count > 0)
|
||||
{
|
||||
foreach (var property in schema.AllOf)
|
||||
{
|
||||
var mapped = MapSchemaToObject(schemaProperty.Value, schemaProperty.Key);
|
||||
if (mapped is JProperty jp)
|
||||
foreach (var item in property.Properties)
|
||||
{
|
||||
propertyAsJObject.Add(jp);
|
||||
propertyAsJObject.Add(MapPropertyAsJObject(item.Value, item.Key));
|
||||
}
|
||||
else
|
||||
{
|
||||
propertyAsJObject.Add(new JProperty(schemaProperty.Key, mapped));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
||||
|
||||
propertyAsJObject.Add(new JProperty(propertyName, _exampleValueGenerator.GetExampleValue(openApiSchema)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,6 +221,40 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
}
|
||||
}
|
||||
|
||||
private JObject MapSchemaAllOfToObject(OpenApiSchema schema)
|
||||
{
|
||||
var arrayItem = new JObject();
|
||||
foreach (var property in schema.AllOf)
|
||||
{
|
||||
foreach (var item in property.Properties)
|
||||
{
|
||||
arrayItem.Add(MapPropertyAsJObject(item.Value, item.Key));
|
||||
}
|
||||
}
|
||||
return arrayItem;
|
||||
}
|
||||
|
||||
private object MapPropertyAsJObject(OpenApiSchema openApiSchema, string key)
|
||||
{
|
||||
if (openApiSchema.GetSchemaType() == SchemaType.Object || openApiSchema.GetSchemaType() == SchemaType.Array)
|
||||
{
|
||||
var mapped = MapSchemaToObject(openApiSchema, key);
|
||||
if (mapped is JProperty jp)
|
||||
{
|
||||
return jp;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new JProperty(key, mapped);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// bool propertyIsNullable = openApiSchema.Nullable || (openApiSchema.TryGetXNullable(out bool x) && x);
|
||||
return new JProperty(key, _exampleValueGenerator.GetExampleValue(openApiSchema));
|
||||
}
|
||||
}
|
||||
|
||||
private string MapPathWithParameters(string path, IEnumerable<OpenApiParameter> parameters)
|
||||
{
|
||||
if (parameters == null)
|
||||
@@ -192,12 +265,29 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
string newPath = path;
|
||||
foreach (var parameter in parameters)
|
||||
{
|
||||
newPath = newPath.Replace($"{{{parameter.Name}}}", GetExampleValue(parameter.Schema, _settings.PathPatternToUse));
|
||||
var exampleMatcherModel = GetExampleMatcherModel(parameter.Schema, _settings.PathPatternToUse);
|
||||
newPath = newPath.Replace($"{{{parameter.Name}}}", exampleMatcherModel.Pattern as string);
|
||||
}
|
||||
|
||||
return newPath;
|
||||
}
|
||||
|
||||
private string MapBasePath(IList<OpenApiServer> servers)
|
||||
{
|
||||
if (servers == null || servers.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
OpenApiServer server = servers.First();
|
||||
if (Uri.TryCreate(server.Url, UriKind.RelativeOrAbsolute, out Uri uriResult))
|
||||
{
|
||||
return uriResult.IsAbsoluteUri ? uriResult.AbsolutePath : uriResult.ToString();
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
private JToken MapOpenApiAnyToJToken(IOpenApiAny any)
|
||||
{
|
||||
if (any == null)
|
||||
@@ -209,26 +299,26 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
var writer = new OpenApiJsonWriter(outputString);
|
||||
any.Write(writer, OpenApiSpecVersion.OpenApi3_0);
|
||||
|
||||
return JObject.Parse(outputString.ToString());
|
||||
if (any.AnyType == AnyType.Array)
|
||||
{
|
||||
return JArray.Parse(outputString.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return JObject.Parse(outputString.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private IDictionary<string, object> MapHeaders(string responseContentType, IDictionary<string, OpenApiHeader> headers)
|
||||
{
|
||||
var mappedHeaders = headers.ToDictionary(
|
||||
item => item.Key,
|
||||
item => GetExampleValue(null, _settings.HeaderPatternToUse) as object
|
||||
item => GetExampleMatcherModel(null, _settings.HeaderPatternToUse).Pattern
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(responseContentType))
|
||||
{
|
||||
if (!mappedHeaders.ContainsKey("Content-Type"))
|
||||
{
|
||||
mappedHeaders.Add("Content-Type", responseContentType);
|
||||
}
|
||||
else
|
||||
{
|
||||
mappedHeaders["Content-Type"] = responseContentType;
|
||||
}
|
||||
mappedHeaders.TryAdd(HeaderContentType, responseContentType);
|
||||
}
|
||||
|
||||
return mappedHeaders.Keys.Any() ? mappedHeaders : null;
|
||||
@@ -237,16 +327,14 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
private IList<ParamModel> MapQueryParameters(IEnumerable<OpenApiParameter> queryParameters)
|
||||
{
|
||||
var list = queryParameters
|
||||
.Where(req => req.Required)
|
||||
.Select(qp => new ParamModel
|
||||
{
|
||||
Name = qp.Name,
|
||||
IgnoreCase = _settings.QueryParameterPatternIgnoreCase,
|
||||
Matchers = new[]
|
||||
{
|
||||
new MatcherModel
|
||||
{
|
||||
Name = "ExactMatcher",
|
||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
||||
}
|
||||
GetExampleMatcherModel(qp.Schema, _settings.QueryParameterPatternToUse)
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
@@ -257,16 +345,14 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
private IList<HeaderModel> MapRequestHeaders(IEnumerable<OpenApiParameter> headers)
|
||||
{
|
||||
var list = headers
|
||||
.Where(req => req.Required)
|
||||
.Select(qp => new HeaderModel
|
||||
{
|
||||
Name = qp.Name,
|
||||
IgnoreCase = _settings.HeaderPatternIgnoreCase,
|
||||
Matchers = new[]
|
||||
{
|
||||
new MatcherModel
|
||||
{
|
||||
Name = "ExactMatcher",
|
||||
Pattern = GetDefaultValueAsStringForSchemaType(qp.Schema)
|
||||
}
|
||||
GetExampleMatcherModel(qp.Schema, _settings.HeaderPatternToUse)
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
@@ -274,30 +360,26 @@ namespace WireMock.Net.OpenApiParser.Mappers
|
||||
return list.Any() ? list : null;
|
||||
}
|
||||
|
||||
private string GetDefaultValueAsStringForSchemaType(OpenApiSchema schema)
|
||||
private MatcherModel GetExampleMatcherModel(OpenApiSchema schema, ExampleValueType type)
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
ExampleValueType.Value => new MatcherModel { Name = "ExactMatcher", Pattern = GetExampleValueAsStringForSchemaType(schema), IgnoreCase = _settings.IgnoreCaseExampleValues },
|
||||
|
||||
_ => new MatcherModel { Name = "WildcardMatcher", Pattern = "*" }
|
||||
};
|
||||
}
|
||||
|
||||
private string GetExampleValueAsStringForSchemaType(OpenApiSchema schema)
|
||||
{
|
||||
var value = _exampleValueGenerator.GetExampleValue(schema);
|
||||
|
||||
switch (value)
|
||||
return value switch
|
||||
{
|
||||
case string valueAsString:
|
||||
return valueAsString;
|
||||
string valueAsString => valueAsString,
|
||||
|
||||
default:
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetExampleValue(OpenApiSchema schema, ExampleValueType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ExampleValueType.Value:
|
||||
return GetDefaultValueAsStringForSchemaType(schema);
|
||||
|
||||
default:
|
||||
return "*";
|
||||
}
|
||||
_ => value.ToString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// A interface defining the example values to use for the different types.
|
||||
/// </summary>
|
||||
public interface IWireMockOpenApiParserExampleValues
|
||||
{
|
||||
/// <summary>
|
||||
/// An example value for a Boolean.
|
||||
/// </summary>
|
||||
bool Boolean { get; set; }
|
||||
/// <summary>
|
||||
/// An example value for an Integer.
|
||||
/// </summary>
|
||||
int Integer { get; set; }
|
||||
/// <summary>
|
||||
/// An example value for a Float.
|
||||
/// </summary>
|
||||
float Float { get; set; }
|
||||
/// <summary>
|
||||
/// An example value for a Double.
|
||||
/// </summary>
|
||||
double Double { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An example value for a Date.
|
||||
/// </summary>
|
||||
Func<DateTime> Date { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An example value for a DateTime.
|
||||
/// </summary>
|
||||
Func<DateTime> DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An example value for Bytes.
|
||||
/// </summary>
|
||||
byte[] Bytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An example value for a Object.
|
||||
/// </summary>
|
||||
object Object { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An example value for a String.
|
||||
/// </summary>
|
||||
string String { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using RandomDataGenerator.FieldOptions;
|
||||
using RandomDataGenerator.Randomizers;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Settings
|
||||
{
|
||||
/// <summary>
|
||||
/// A class defining the random example values to use for the different types.
|
||||
/// </summary>
|
||||
public class WireMockOpenApiParserDynamicExampleValues : IWireMockOpenApiParserExampleValues
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public bool Boolean { get { return RandomizerFactory.GetRandomizer(new FieldOptionsBoolean()).Generate() ?? true; } set { } }
|
||||
/// <inheritdoc />
|
||||
public 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 { } }
|
||||
/// <inheritdoc />
|
||||
public 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 { } }
|
||||
/// <inheritdoc />
|
||||
public 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 { } }
|
||||
/// <inheritdoc />
|
||||
public 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 { } }
|
||||
}
|
||||
}
|
||||
@@ -5,26 +5,25 @@ namespace WireMock.Net.OpenApiParser.Settings
|
||||
/// <summary>
|
||||
/// A class defining the example values to use for the different types.
|
||||
/// </summary>
|
||||
public class WireMockOpenApiParserExampleValues
|
||||
public class WireMockOpenApiParserExampleValues : IWireMockOpenApiParserExampleValues
|
||||
{
|
||||
#pragma warning disable 1591
|
||||
/// <inheritdoc />
|
||||
public bool Boolean { get; set; } = true;
|
||||
|
||||
/// <inheritdoc />
|
||||
public int Integer { get; set; } = 42;
|
||||
|
||||
/// <inheritdoc />
|
||||
public float Float { get; set; } = 4.2f;
|
||||
|
||||
/// <inheritdoc />
|
||||
public double Double { get; set; } = 4.2d;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> Date { get; set; } = () => System.DateTime.UtcNow.Date;
|
||||
|
||||
/// <inheritdoc />
|
||||
public Func<DateTime> DateTime { get; set; } = () => System.DateTime.UtcNow;
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] Bytes { get; set; } = { 48, 49, 50 };
|
||||
|
||||
/// <inheritdoc />
|
||||
public object Object { get; set; } = "example-object";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string String { get; set; } = "example-string";
|
||||
#pragma warning restore 1591
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using WireMock.Net.OpenApiParser.Types;
|
||||
using WireMock.Net.OpenApiParser.Types;
|
||||
|
||||
namespace WireMock.Net.OpenApiParser.Settings
|
||||
{
|
||||
@@ -23,8 +23,42 @@ namespace WireMock.Net.OpenApiParser.Settings
|
||||
public ExampleValueType HeaderPatternToUse { get; set; } = ExampleValueType.Value;
|
||||
|
||||
/// <summary>
|
||||
/// The example values to use
|
||||
/// The example value type to use when generating a Query Parameter
|
||||
/// </summary>
|
||||
public WireMockOpenApiParserExampleValues ExampleValues { get; } = new WireMockOpenApiParserExampleValues();
|
||||
public ExampleValueType QueryParameterPatternToUse { get; set; } = ExampleValueType.Value;
|
||||
|
||||
/// <summary>
|
||||
/// The example values to use.
|
||||
///
|
||||
/// Default implementations are:
|
||||
/// - <see cref="WireMockOpenApiParserExampleValues"/>
|
||||
/// - <see cref="WireMockOpenApiParserDynamicExampleValues"/>
|
||||
/// </summary>
|
||||
public IWireMockOpenApiParserExampleValues ExampleValues { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is a Header match case insensitive? (default is true).
|
||||
/// </summary>
|
||||
public bool HeaderPatternIgnoreCase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Is a Query Parameter match case insensitive? (default is true).
|
||||
/// </summary>
|
||||
public bool QueryParameterPatternIgnoreCase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Is a Request Body match case insensitive? (default is true).
|
||||
/// </summary>
|
||||
public bool RequestBodyIgnoreCase { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Is a ExampleValue match case insensitive? (default is true).
|
||||
/// </summary>
|
||||
public bool IgnoreCaseExampleValues { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Are examples generated dynamically? (default is false).
|
||||
/// </summary>
|
||||
public bool DynamicExamples { get; set; } = false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace WireMock.Net.OpenApiParser.Types
|
||||
namespace WireMock.Net.OpenApiParser.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// The example value to use
|
||||
@@ -6,7 +6,9 @@
|
||||
public enum ExampleValueType
|
||||
{
|
||||
/// <summary>
|
||||
/// Use a generated example value based on the SchemaType (default).
|
||||
/// 1. Use a generated example value based on the SchemaType (default).
|
||||
/// 2. If there is no example value defined in the schema,
|
||||
/// then the <see cref="Settings.IWireMockOpenApiParserExampleValues"/> will be used (custom, fixed or dynamic).
|
||||
/// </summary>
|
||||
Value,
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Stef.Validation;
|
||||
using WireMock.Net.OpenApiParser.Extensions;
|
||||
using WireMock.Net.OpenApiParser.Settings;
|
||||
using WireMock.Net.OpenApiParser.Types;
|
||||
@@ -12,48 +15,111 @@ namespace WireMock.Net.OpenApiParser.Utils
|
||||
|
||||
public ExampleValueGenerator(WireMockOpenApiParserSettings settings)
|
||||
{
|
||||
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
_settings = Guard.NotNull(settings, nameof(settings));
|
||||
|
||||
// Check if user provided an own implementation
|
||||
if (settings.ExampleValues is null)
|
||||
{
|
||||
if (_settings.DynamicExamples)
|
||||
{
|
||||
_settings.ExampleValues = new WireMockOpenApiParserDynamicExampleValues();
|
||||
}
|
||||
else
|
||||
{
|
||||
_settings.ExampleValues = new WireMockOpenApiParserExampleValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public object GetExampleValue(OpenApiSchema schema)
|
||||
{
|
||||
var schemaExample = schema?.Example;
|
||||
var schemaEnum = GetRandomEnumValue(schema?.Enum);
|
||||
|
||||
switch (schema?.GetSchemaType())
|
||||
{
|
||||
case SchemaType.Boolean:
|
||||
return _settings.ExampleValues.Boolean;
|
||||
var exampleBoolean = (OpenApiBoolean)schemaExample;
|
||||
return exampleBoolean is null ? _settings.ExampleValues.Boolean : exampleBoolean.Value;
|
||||
|
||||
case SchemaType.Integer:
|
||||
return _settings.ExampleValues.Integer;
|
||||
switch (schema?.GetSchemaFormat())
|
||||
{
|
||||
case SchemaFormat.Int64:
|
||||
var exampleLong = (OpenApiLong)schemaExample;
|
||||
var enumLong = (OpenApiLong)schemaEnum;
|
||||
var valueLongEnumOrExample = enumLong is null ? exampleLong?.Value : enumLong?.Value;
|
||||
return valueLongEnumOrExample ?? _settings.ExampleValues.Integer;
|
||||
|
||||
default:
|
||||
var exampleInteger = (OpenApiInteger)schemaExample;
|
||||
var enumInteger = (OpenApiInteger)schemaEnum;
|
||||
var valueIntegerEnumOrExample = enumInteger is null ? exampleInteger?.Value : enumInteger?.Value;
|
||||
return valueIntegerEnumOrExample ?? _settings.ExampleValues.Integer;
|
||||
}
|
||||
|
||||
case SchemaType.Number:
|
||||
switch (schema?.GetSchemaFormat())
|
||||
{
|
||||
case SchemaFormat.Float:
|
||||
return _settings.ExampleValues.Float;
|
||||
var exampleFloat = (OpenApiFloat)schemaExample;
|
||||
var enumFloat = (OpenApiFloat)schemaEnum;
|
||||
var valueFloatEnumOrExample = enumFloat is null ? exampleFloat?.Value : enumFloat?.Value;
|
||||
return valueFloatEnumOrExample ?? _settings.ExampleValues.Float;
|
||||
|
||||
default:
|
||||
return _settings.ExampleValues.Double;
|
||||
var exampleDouble = (OpenApiDouble)schemaExample;
|
||||
var enumDouble = (OpenApiDouble)schemaEnum;
|
||||
var valueDoubleEnumOrExample = enumDouble is null ? exampleDouble?.Value : enumDouble?.Value;
|
||||
return valueDoubleEnumOrExample ?? _settings.ExampleValues.Double;
|
||||
}
|
||||
|
||||
default:
|
||||
switch (schema?.GetSchemaFormat())
|
||||
{
|
||||
case SchemaFormat.Date:
|
||||
return DateTimeUtils.ToRfc3339Date(_settings.ExampleValues.Date());
|
||||
var exampleDate = (OpenApiDate)schemaExample;
|
||||
var enumDate = (OpenApiDate)schemaEnum;
|
||||
var valueDateEnumOrExample = enumDate is null ? exampleDate?.Value : enumDate?.Value;
|
||||
return DateTimeUtils.ToRfc3339Date(valueDateEnumOrExample ?? _settings.ExampleValues.Date());
|
||||
|
||||
case SchemaFormat.DateTime:
|
||||
return DateTimeUtils.ToRfc3339DateTime(_settings.ExampleValues.DateTime());
|
||||
var exampleDateTime = (OpenApiDateTime)schemaExample;
|
||||
var enumDateTime = (OpenApiDateTime)schemaEnum;
|
||||
var valueDateTimeEnumOrExample = enumDateTime is null ? exampleDateTime?.Value : enumDateTime?.Value;
|
||||
return DateTimeUtils.ToRfc3339DateTime(valueDateTimeEnumOrExample?.DateTime ?? _settings.ExampleValues.DateTime());
|
||||
|
||||
case SchemaFormat.Byte:
|
||||
return _settings.ExampleValues.Bytes;
|
||||
var exampleByte = (OpenApiByte)schemaExample;
|
||||
var enumByte = (OpenApiByte)schemaEnum;
|
||||
var valueByteEnumOrExample = enumByte is null ? exampleByte?.Value : enumByte?.Value;
|
||||
return valueByteEnumOrExample ?? _settings.ExampleValues.Bytes;
|
||||
|
||||
case SchemaFormat.Binary:
|
||||
return _settings.ExampleValues.Object;
|
||||
var exampleBinary = (OpenApiBinary)schemaExample;
|
||||
var enumBinary = (OpenApiBinary)schemaEnum;
|
||||
var valueBinaryEnumOrExample = enumBinary is null ? exampleBinary?.Value : enumBinary?.Value;
|
||||
return valueBinaryEnumOrExample ?? _settings.ExampleValues.Object;
|
||||
|
||||
default:
|
||||
return _settings.ExampleValues.String;
|
||||
var exampleString = (OpenApiString)schemaExample;
|
||||
var enumString = (OpenApiString)schemaEnum;
|
||||
var valueStringEnumOrExample = enumString is null ? exampleString?.Value : enumString?.Value;
|
||||
return valueStringEnumOrExample ?? _settings.ExampleValues.String;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IOpenApiAny GetRandomEnumValue(IList<IOpenApiAny> schemaEnum)
|
||||
{
|
||||
if (schemaEnum?.Count > 0)
|
||||
{
|
||||
int maxValue = schemaEnum.Count - 1;
|
||||
int randomEnum = new Random().Next(0, maxValue);
|
||||
return schemaEnum[randomEnum];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,11 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />
|
||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.1.1" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="RamlToOpenApiConverter" Version="0.6.0" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Stef.Validation" Version="0.0.3" />
|
||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||
<PackageReference Include="Stef.Validation" Version="0.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace WireMock.Net.OpenApiParser
|
||||
[PublicAPI]
|
||||
public IEnumerable<MappingModel> FromDocument(OpenApiDocument openApiDocument, WireMockOpenApiParserSettings settings = null)
|
||||
{
|
||||
return new OpenApiPathsMapper(settings).ToMappingModels(openApiDocument.Paths);
|
||||
return new OpenApiPathsMapper(settings).ToMappingModels(openApiDocument.Paths, openApiDocument.Servers);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Server;
|
||||
@@ -12,6 +13,8 @@ namespace WireMock.Net.StandAlone
|
||||
/// </summary>
|
||||
public static class StandAloneApp
|
||||
{
|
||||
private static readonly string Version = typeof(StandAloneApp).GetTypeInfo().Assembly.GetName().Version.ToString();
|
||||
|
||||
/// <summary>
|
||||
/// Start WireMock.Net standalone Server based on the IWireMockServerSettings.
|
||||
/// </summary>
|
||||
@@ -23,7 +26,8 @@ namespace WireMock.Net.StandAlone
|
||||
|
||||
var server = WireMockServer.Start(settings);
|
||||
|
||||
settings.Logger?.Info("WireMock.Net server listening at {0}", string.Join(",", server.Urls));
|
||||
settings.Logger?.Info("Version [{0}]", Version);
|
||||
settings.Logger?.Info("Server listening at {0}", string.Join(",", server.Urls));
|
||||
|
||||
return server;
|
||||
}
|
||||
@@ -40,7 +44,8 @@ namespace WireMock.Net.StandAlone
|
||||
|
||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||
{
|
||||
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
settings.Logger?.Info("Version [{0}]", Version);
|
||||
settings.Logger?.Debug("Server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
return Start(settings);
|
||||
}
|
||||
@@ -61,7 +66,8 @@ namespace WireMock.Net.StandAlone
|
||||
|
||||
if (WireMockServerSettingsParser.TryParseArguments(args, out var settings, logger))
|
||||
{
|
||||
settings.Logger?.Debug("WireMock.Net server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
settings.Logger?.Info("Version [{0}]", Version);
|
||||
settings.Logger?.Debug("Server arguments [{0}]", string.Join(", ", args.Select(a => $"'{a}'")));
|
||||
|
||||
server = Start(settings);
|
||||
return true;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.8.0.7320">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace WireMock.Authentication
|
||||
try
|
||||
{
|
||||
var configManager = new ConfigurationManager<OpenIdConnectConfiguration>(_stsDiscoveryEndpoint, new OpenIdConnectConfigurationRetriever());
|
||||
var config = configManager.GetConfigurationAsync().GetAwaiter().GetResult();
|
||||
var config = configManager.GetConfigurationAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
|
||||
var validationParameters = new TokenValidationParameters
|
||||
{
|
||||
|
||||
@@ -1,23 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AnyOfTypes;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Extensions
|
||||
{
|
||||
internal static class AnyOfExtensions
|
||||
{
|
||||
public static string GetPattern(this AnyOf<string, StringPattern> value)
|
||||
public static string GetPattern([NotNull] this AnyOf<string, StringPattern> value)
|
||||
{
|
||||
return value.IsFirst ? value.First : value.Second.Pattern;
|
||||
}
|
||||
|
||||
public static AnyOf<string, StringPattern>[] ToAnyOfPatterns(this IEnumerable<string> patterns)
|
||||
public static AnyOf<string, StringPattern>[] ToAnyOfPatterns([NotNull] this IEnumerable<string> patterns)
|
||||
{
|
||||
return patterns.Select(p => p.ToAnyOfPattern()).ToArray();
|
||||
}
|
||||
|
||||
public static AnyOf<string, StringPattern> ToAnyOfPattern(this string pattern)
|
||||
public static AnyOf<string, StringPattern> ToAnyOfPattern([CanBeNull] this string pattern)
|
||||
{
|
||||
return new AnyOf<string, StringPattern>(pattern);
|
||||
}
|
||||
|
||||
35
src/WireMock.Net/Extensions/TimeSettingsExtensions.cs
Normal file
35
src/WireMock.Net/Extensions/TimeSettingsExtensions.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Extensions
|
||||
{
|
||||
internal static class TimeSettingsExtensions
|
||||
{
|
||||
public static bool IsValid([CanBeNull] this ITimeSettings settings)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var now = DateTime.Now;
|
||||
var start = settings.Start != null ? settings.Start.Value : now;
|
||||
DateTime end;
|
||||
if (settings.End != null)
|
||||
{
|
||||
end = settings.End.Value;
|
||||
}
|
||||
else if (settings.TTL != null)
|
||||
{
|
||||
end = start.AddSeconds(settings.TTL.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
end = DateTime.MaxValue;
|
||||
}
|
||||
|
||||
return now >= start && now <= end;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace WireMock.Handlers
|
||||
public class LocalFileSystemHandler : IFileSystemHandler
|
||||
{
|
||||
private static readonly string AdminMappingsFolder = Path.Combine("__admin", "mappings");
|
||||
private static readonly string UnmatchedRequestsFolder = Path.Combine("requests", "unmatched");
|
||||
|
||||
private readonly string _rootFolder;
|
||||
|
||||
@@ -31,7 +32,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.FolderExists"/>
|
||||
public bool FolderExists(string path)
|
||||
public virtual bool FolderExists(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.CreateFolder"/>
|
||||
public void CreateFolder(string path)
|
||||
public virtual void CreateFolder(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
@@ -47,7 +48,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.EnumerateFiles"/>
|
||||
public IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories)
|
||||
public virtual IEnumerable<string> EnumerateFiles(string path, bool includeSubdirectories)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
@@ -55,13 +56,13 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.GetMappingFolder"/>
|
||||
public string GetMappingFolder()
|
||||
public virtual string GetMappingFolder()
|
||||
{
|
||||
return Path.Combine(_rootFolder, AdminMappingsFolder);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadMappingFile"/>
|
||||
public string ReadMappingFile(string path)
|
||||
public virtual string ReadMappingFile(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
|
||||
@@ -69,7 +70,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteMappingFile(string, string)"/>
|
||||
public void WriteMappingFile(string path, string text)
|
||||
public virtual void WriteMappingFile(string path, string text)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
Check.NotNull(text, nameof(text));
|
||||
@@ -78,7 +79,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsFile"/>
|
||||
public byte[] ReadResponseBodyAsFile(string path)
|
||||
public virtual byte[] ReadResponseBodyAsFile(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
path = PathUtils.CleanPath(path);
|
||||
@@ -88,7 +89,7 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadResponseBodyAsString"/>
|
||||
public string ReadResponseBodyAsString(string path)
|
||||
public virtual string ReadResponseBodyAsString(string path)
|
||||
{
|
||||
Check.NotNullOrEmpty(path, nameof(path));
|
||||
path = PathUtils.CleanPath(path);
|
||||
@@ -98,42 +99,63 @@ namespace WireMock.Handlers
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.FileExists"/>
|
||||
public bool FileExists(string filename)
|
||||
public virtual bool FileExists(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
return File.Exists(AdjustPath(filename));
|
||||
return File.Exists(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteFile(string, byte[])"/>
|
||||
public void WriteFile(string filename, byte[] bytes)
|
||||
public virtual void WriteFile(string filename, byte[] bytes)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Check.NotNull(bytes, nameof(bytes));
|
||||
|
||||
File.WriteAllBytes(AdjustPath(filename), bytes);
|
||||
File.WriteAllBytes(AdjustPathForMappingFolder(filename), bytes);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.DeleteFile"/>
|
||||
public void DeleteFile(string filename)
|
||||
public virtual void DeleteFile(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
File.Delete(AdjustPath(filename));
|
||||
File.Delete(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadFile"/>
|
||||
public byte[] ReadFile(string filename)
|
||||
public virtual byte[] ReadFile(string filename)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
|
||||
return File.ReadAllBytes(AdjustPath(filename));
|
||||
return File.ReadAllBytes(AdjustPathForMappingFolder(filename));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.ReadFileAsString"/>
|
||||
public string ReadFileAsString(string filename)
|
||||
public virtual string ReadFileAsString(string filename)
|
||||
{
|
||||
return File.ReadAllText(AdjustPath(Check.NotNullOrEmpty(filename, nameof(filename))));
|
||||
return File.ReadAllText(AdjustPathForMappingFolder(Check.NotNullOrEmpty(filename, nameof(filename))));
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.GetUnmatchedRequestsFolder"/>
|
||||
public virtual string GetUnmatchedRequestsFolder()
|
||||
{
|
||||
return Path.Combine(_rootFolder, UnmatchedRequestsFolder);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IFileSystemHandler.WriteUnmatchedRequest"/>
|
||||
public virtual void WriteUnmatchedRequest(string filename, string text)
|
||||
{
|
||||
Check.NotNullOrEmpty(filename, nameof(filename));
|
||||
Check.NotNull(text, nameof(text));
|
||||
|
||||
var folder = GetUnmatchedRequestsFolder();
|
||||
if (!FolderExists(folder))
|
||||
{
|
||||
CreateFolder(folder);
|
||||
}
|
||||
|
||||
File.WriteAllText(Path.Combine(folder, filename), text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -141,7 +163,7 @@ namespace WireMock.Handlers
|
||||
/// </summary>
|
||||
/// <param name="filename">The path.</param>
|
||||
/// <returns>Adjusted path</returns>
|
||||
private string AdjustPath(string filename)
|
||||
private string AdjustPathForMappingFolder(string filename)
|
||||
{
|
||||
return Path.Combine(GetMappingFolder(), filename);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -17,7 +17,7 @@ namespace WireMock.Http
|
||||
var headers = (httpResponseMessage.Content?.Headers.Union(httpResponseMessage.Headers) ?? Enumerable.Empty<KeyValuePair<string, IEnumerable<string>>>()).ToArray();
|
||||
if (httpResponseMessage.Content != null)
|
||||
{
|
||||
var stream = await httpResponseMessage.Content.ReadAsStreamAsync();
|
||||
var stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false);
|
||||
IEnumerable<string> contentTypeHeader = null;
|
||||
if (headers.Any(header => string.Equals(header.Key, HttpKnownHeaderNames.ContentType, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
@@ -38,7 +38,7 @@ namespace WireMock.Http
|
||||
ContentEncoding = contentEncodingHeader?.FirstOrDefault(),
|
||||
DecompressGZipAndDeflate = decompressGzipAndDeflate
|
||||
};
|
||||
responseMessage.BodyData = await BodyParser.Parse(bodyParserSettings);
|
||||
responseMessage.BodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
foreach (var header in headers)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using JetBrains.Annotations;
|
||||
using JetBrains.Annotations;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Matchers.Request;
|
||||
@@ -18,6 +18,11 @@ namespace WireMock
|
||||
/// </summary>
|
||||
Guid Guid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the TimeSettings (Start, End and TTL).
|
||||
/// </summary>
|
||||
ITimeSettings TimeSettings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique title.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Matchers.Request;
|
||||
@@ -13,51 +13,54 @@ namespace WireMock
|
||||
/// </summary>
|
||||
public class Mapping : IMapping
|
||||
{
|
||||
/// <inheritdoc cref="IMapping.Guid" />
|
||||
/// <inheritdoc />
|
||||
public Guid Guid { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Title" />
|
||||
/// <inheritdoc />
|
||||
public string Title { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Path" />
|
||||
/// <inheritdoc />
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Priority" />
|
||||
/// <inheritdoc />
|
||||
public int Priority { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Scenario" />
|
||||
/// <inheritdoc />
|
||||
public string Scenario { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.ExecutionConditionState" />
|
||||
/// <inheritdoc />
|
||||
public string ExecutionConditionState { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.NextState" />
|
||||
/// <inheritdoc />
|
||||
public string NextState { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.StateTimes" />
|
||||
/// <inheritdoc />
|
||||
public int? StateTimes { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.RequestMatcher" />
|
||||
/// <inheritdoc />
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Provider" />
|
||||
/// <inheritdoc />
|
||||
public IResponseProvider Provider { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.Settings" />
|
||||
/// <inheritdoc />
|
||||
public IWireMockServerSettings Settings { get; }
|
||||
|
||||
/// <inheritdoc cref="IMapping.IsStartState" />
|
||||
/// <inheritdoc />
|
||||
public bool IsStartState => Scenario == null || Scenario != null && NextState != null && ExecutionConditionState == null;
|
||||
|
||||
/// <inheritdoc cref="IMapping.IsAdminInterface" />
|
||||
/// <inheritdoc />
|
||||
public bool IsAdminInterface => Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider || Provider is ProxyAsyncResponseProvider;
|
||||
|
||||
/// <inheritdoc cref="IMapping.LogMapping" />
|
||||
/// <inheritdoc />
|
||||
public bool LogMapping => !(Provider is DynamicResponseProvider || Provider is DynamicAsyncResponseProvider);
|
||||
|
||||
/// <inheritdoc cref="IMapping.Webhooks" />
|
||||
/// <inheritdoc />
|
||||
public IWebhook[] Webhooks { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITimeSettings TimeSettings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Mapping"/> class.
|
||||
/// </summary>
|
||||
@@ -73,6 +76,7 @@ namespace WireMock
|
||||
/// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param>
|
||||
/// <param name="stateTimes">Only when the current state is executed this number, the next state which will occur. [Optional]</param>
|
||||
/// <param name="webhooks">The Webhooks. [Optional]</param>
|
||||
/// <param name="timeSettings">The TimeSettings. [Optional]</param>
|
||||
public Mapping(
|
||||
Guid guid,
|
||||
[CanBeNull] string title,
|
||||
@@ -85,7 +89,8 @@ namespace WireMock
|
||||
[CanBeNull] string executionConditionState,
|
||||
[CanBeNull] string nextState,
|
||||
[CanBeNull] int? stateTimes,
|
||||
[CanBeNull] IWebhook[] webhooks)
|
||||
[CanBeNull] IWebhook[] webhooks,
|
||||
[CanBeNull] ITimeSettings timeSettings)
|
||||
{
|
||||
Guid = guid;
|
||||
Title = title;
|
||||
@@ -99,12 +104,13 @@ namespace WireMock
|
||||
NextState = nextState;
|
||||
StateTimes = stateTimes;
|
||||
Webhooks = webhooks;
|
||||
TimeSettings = timeSettings;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMapping.ProvideResponseAsync" />
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage)
|
||||
public Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage)
|
||||
{
|
||||
return await Provider.ProvideResponseAsync(requestMessage, Settings);
|
||||
return Provider.ProvideResponseAsync(requestMessage, Settings);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IMapping.GetRequestMatchResult" />
|
||||
|
||||
89
src/WireMock.Net/Matchers/AbstractJsonPartialMatcher.cs
Normal file
89
src/WireMock.Net/Matchers/AbstractJsonPartialMatcher.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
/// <summary>
|
||||
/// Generic AbstractJsonPartialMatcher
|
||||
/// </summary>
|
||||
public abstract class AbstractJsonPartialMatcher : JsonMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The string value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
protected AbstractJsonPartialMatcher([NotNull] string value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The object value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
protected AbstractJsonPartialMatcher([NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractJsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
/// <param name="value">The value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
protected AbstractJsonPartialMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(matchBehaviour, value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsMatch(JToken value, JToken input)
|
||||
{
|
||||
if (value == null || value == input)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (input == null || value.Type != input.Type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (value.Type)
|
||||
{
|
||||
case JTokenType.Object:
|
||||
var nestedValues = value.ToObject<Dictionary<string, JToken>>();
|
||||
return nestedValues?.Any() != true ||
|
||||
nestedValues.All(pair => IsMatch(pair.Value, input.SelectToken(pair.Key)));
|
||||
|
||||
case JTokenType.Array:
|
||||
var valuesArray = value.ToObject<JToken[]>();
|
||||
var tokenArray = input.ToObject<JToken[]>();
|
||||
|
||||
if (valuesArray?.Any() != true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return tokenArray?.Any() == true &&
|
||||
valuesArray.All(subFilter => tokenArray.Any(subToken => IsMatch(subFilter, subToken)));
|
||||
|
||||
default:
|
||||
return IsMatch(value.ToString(), input.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if two strings are a match (matching can be done exact or wildcard)
|
||||
/// </summary>
|
||||
protected abstract bool IsMatch(string value, string input);
|
||||
}
|
||||
}
|
||||
@@ -63,8 +63,8 @@ namespace WireMock.Matchers
|
||||
{
|
||||
try
|
||||
{
|
||||
var jtoken = JToken.Parse(input);
|
||||
match = IsMatch(jtoken);
|
||||
var jToken = JToken.Parse(input);
|
||||
match = IsMatch(jToken);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@@ -89,8 +89,8 @@ namespace WireMock.Matchers
|
||||
try
|
||||
{
|
||||
// Check if JToken or object
|
||||
JToken jtoken = input is JToken token ? token : JObject.FromObject(input);
|
||||
match = IsMatch(jtoken);
|
||||
JToken jToken = input is JToken token ? token : JObject.FromObject(input);
|
||||
match = IsMatch(jToken);
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
@@ -113,9 +113,9 @@ namespace WireMock.Matchers
|
||||
/// <inheritdoc cref="IMatcher.Name"/>
|
||||
public string Name => "JsonPathMatcher";
|
||||
|
||||
private double IsMatch(JToken jtoken)
|
||||
private double IsMatch(JToken jToken)
|
||||
{
|
||||
return MatchScores.ToScore(_patterns.Select(pattern => jtoken.SelectToken(pattern.GetPattern()) != null));
|
||||
return MatchScores.ToScore(_patterns.Select(pattern => jToken.SelectToken(pattern.GetPattern()) != null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,87 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
/// <summary>
|
||||
/// JsonPartialMatcher
|
||||
/// </summary>
|
||||
public class JsonPartialMatcher : JsonMatcher
|
||||
public class JsonPartialMatcher : AbstractJsonPartialMatcher
|
||||
{
|
||||
/// <inheritdoc cref="IMatcher.Name"/>
|
||||
public override string Name => "JsonPartialMatcher";
|
||||
/// <inheritdoc />
|
||||
public override string Name => nameof(JsonPartialMatcher);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The string value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public JsonPartialMatcher([NotNull] string value, bool ignoreCase = false, bool throwException = false)
|
||||
/// <inheritdoc />
|
||||
public JsonPartialMatcher([NotNull] string value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The object value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public JsonPartialMatcher([NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
/// <inheritdoc />
|
||||
public JsonPartialMatcher([NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JsonPartialMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
/// <param name="value">The value to check for equality.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the PropertyName and PropertyValue (string only).</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public JsonPartialMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
/// <inheritdoc />
|
||||
public JsonPartialMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(matchBehaviour, value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsMatch(JToken value, JToken input)
|
||||
protected override bool IsMatch(string value, string input)
|
||||
{
|
||||
if (value == null || value == input)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (input == null || value.Type != input.Type)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (value.Type)
|
||||
{
|
||||
case JTokenType.Object:
|
||||
var nestedValues = value.ToObject<Dictionary<string, JToken>>();
|
||||
return nestedValues?.Any() != true ||
|
||||
nestedValues.All(pair => IsMatch(pair.Value, input.SelectToken(pair.Key)));
|
||||
|
||||
case JTokenType.Array:
|
||||
var valuesArray = value.ToObject<JToken[]>();
|
||||
var tokenArray = input.ToObject<JToken[]>();
|
||||
|
||||
if (valuesArray?.Any() != true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return tokenArray?.Any() == true &&
|
||||
valuesArray.All(subFilter => tokenArray.Any(subToken => IsMatch(subFilter, subToken)));
|
||||
|
||||
default:
|
||||
return value.ToString() == input.ToString();
|
||||
}
|
||||
var exactStringMatcher = new ExactMatcher(MatchBehaviour.AcceptOnMatch, ThrowException, value);
|
||||
return MatchScores.IsPerfect(exactStringMatcher.IsMatch(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs
Normal file
38
src/WireMock.Net/Matchers/JsonPartialWildCardMatcher.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
{
|
||||
/// <summary>
|
||||
/// JsonPartialWildCardMatcher
|
||||
/// </summary>
|
||||
public class JsonPartialWildcardMatcher : AbstractJsonPartialMatcher
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override string Name => nameof(JsonPartialWildcardMatcher);
|
||||
|
||||
/// <inheritdoc />
|
||||
public JsonPartialWildcardMatcher([NotNull] string value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public JsonPartialWildcardMatcher([NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public JsonPartialWildcardMatcher(MatchBehaviour matchBehaviour, [NotNull] object value, bool ignoreCase = false, bool throwException = false)
|
||||
: base(matchBehaviour, value, ignoreCase, throwException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override bool IsMatch(string value, string input)
|
||||
{
|
||||
var wildcardStringMatcher = new WildcardMatcher(MatchBehaviour.AcceptOnMatch, value, IgnoreCase);
|
||||
return MatchScores.IsPerfect(wildcardStringMatcher.IsMatch(input));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using AnyOfTypes;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Models;
|
||||
using WireMock.RegularExpressions;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Matchers
|
||||
@@ -30,7 +31,10 @@ namespace WireMock.Matchers
|
||||
/// </summary>
|
||||
/// <param name="pattern">The pattern.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
public RegexMatcher([NotNull, RegexPattern] AnyOf<string, StringPattern> pattern, bool ignoreCase = false) : this(new[] { pattern }, ignoreCase)
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
/// <param name="useRegexExtended">Use RegexExtended (default = true).</param>
|
||||
public RegexMatcher([NotNull, RegexPattern] AnyOf<string, StringPattern> pattern, bool ignoreCase = false, bool throwException = false, bool useRegexExtended = true) :
|
||||
this(MatchBehaviour.AcceptOnMatch, new[] { pattern }, ignoreCase, throwException, useRegexExtended)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -40,16 +44,10 @@ namespace WireMock.Matchers
|
||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||
/// <param name="pattern">The pattern.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] AnyOf<string, StringPattern> pattern, bool ignoreCase = false) : this(matchBehaviour, new[] { pattern }, ignoreCase)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegexMatcher"/> class.
|
||||
/// </summary>
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
public RegexMatcher([NotNull, RegexPattern] AnyOf<string, StringPattern>[] patterns, bool ignoreCase = false) : this(MatchBehaviour.AcceptOnMatch, patterns, ignoreCase)
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
/// <param name="useRegexExtended">Use RegexExtended (default = true).</param>
|
||||
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] AnyOf<string, StringPattern> pattern, bool ignoreCase = false, bool throwException = false, bool useRegexExtended = true) :
|
||||
this(matchBehaviour, new[] { pattern }, ignoreCase, throwException, useRegexExtended)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -60,7 +58,8 @@ namespace WireMock.Matchers
|
||||
/// <param name="patterns">The patterns.</param>
|
||||
/// <param name="ignoreCase">Ignore the case from the pattern.</param>
|
||||
/// <param name="throwException">Throw an exception when the internal matching fails because of invalid input.</param>
|
||||
public RegexMatcher(MatchBehaviour matchBehaviour, [NotNull, RegexPattern] AnyOf<string, StringPattern>[] patterns, bool ignoreCase = false, bool throwException = false)
|
||||
/// <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));
|
||||
|
||||
@@ -76,7 +75,7 @@ namespace WireMock.Matchers
|
||||
options |= RegexOptions.IgnoreCase;
|
||||
}
|
||||
|
||||
_expressions = patterns.Select(p => new Regex(p.GetPattern(), options)).ToArray();
|
||||
_expressions = patterns.Select(p => useRegexExtended ? new RegexExtended(p.GetPattern(), options) : new Regex(p.GetPattern(), options)).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||
|
||||
@@ -83,9 +83,9 @@ namespace WireMock.Matchers
|
||||
/// <inheritdoc cref="IStringMatcher.IsMatch"/>
|
||||
public double IsMatch(string input)
|
||||
{
|
||||
IStringMetric stringmetricType = GetStringMetricType();
|
||||
IStringMetric stringMetricType = GetStringMetricType();
|
||||
|
||||
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => stringmetricType.GetSimilarity(p.GetPattern(), input))));
|
||||
return MatchBehaviourHelper.Convert(MatchBehaviour, MatchScores.ToScore(_patterns.Select(p => stringMetricType.GetSimilarity(p.GetPattern(), input))));
|
||||
}
|
||||
|
||||
private IStringMetric GetStringMetricType()
|
||||
|
||||
19
src/WireMock.Net/Models/TimeSettings.cs
Normal file
19
src/WireMock.Net/Models/TimeSettings.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace WireMock.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// TimeSettingsModel: Start, End and TTL
|
||||
/// </summary>
|
||||
public class TimeSettings : ITimeSettings
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public DateTime? Start { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public DateTime? End { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public int? TTL { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#if USE_ASPNETCORE
|
||||
#if USE_ASPNETCORE
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -118,17 +118,17 @@ namespace WireMock.Owin
|
||||
});
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
_logger.Info("WireMock.Net server using netstandard1.3");
|
||||
_logger.Info("Server using netstandard1.3");
|
||||
#elif NETSTANDARD2_0
|
||||
_logger.Info("WireMock.Net server using netstandard2.0");
|
||||
_logger.Info("Server using netstandard2.0");
|
||||
#elif NETSTANDARD2_1
|
||||
_logger.Info("WireMock.Net server using netstandard2.1");
|
||||
_logger.Info("Server using netstandard2.1");
|
||||
#elif NETCOREAPP3_1
|
||||
_logger.Info("WireMock.Net server using .NET Core 3.1");
|
||||
_logger.Info("Server using .NET Core 3.1");
|
||||
#elif NET5_0
|
||||
_logger.Info("WireMock.Net server using .NET 5.0");
|
||||
_logger.Info("Server using .NET 5.0");
|
||||
#elif NET46
|
||||
_logger.Info("WireMock.Net server using .NET Framework 4.6.1 or higher");
|
||||
_logger.Info("Server using .NET Framework 4.6.1 or higher");
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
#if !USE_ASPNETCORE
|
||||
@@ -52,19 +52,22 @@ namespace WireMock.Owin
|
||||
public Task Invoke(IContext ctx)
|
||||
#endif
|
||||
{
|
||||
return InvokeInternal(ctx);
|
||||
return InvokeInternalAsync(ctx);
|
||||
}
|
||||
|
||||
private async Task InvokeInternal(IContext ctx)
|
||||
private async Task InvokeInternalAsync(IContext ctx)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Next?.Invoke(ctx);
|
||||
if (Next != null)
|
||||
{
|
||||
await Next.Invoke(ctx).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
|
||||
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
|
||||
await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,5 +64,7 @@ namespace WireMock.Owin
|
||||
string X509CertificatePassword { get; set; }
|
||||
|
||||
bool CustomCertificateDefined { get; }
|
||||
|
||||
bool? SaveUnmatchedRequests { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@@ -23,7 +23,7 @@ namespace WireMock.Owin.Mappers
|
||||
/// <inheritdoc cref="IOwinRequestMapper.MapAsync"/>
|
||||
public async Task<RequestMessage> MapAsync(IRequest request, IWireMockMiddlewareOptions options)
|
||||
{
|
||||
(UrlDetails urldetails, string clientIP) = ParseRequest(request);
|
||||
var (urlDetails, clientIP) = ParseRequest(request);
|
||||
|
||||
string method = request.Method;
|
||||
|
||||
@@ -65,25 +65,25 @@ namespace WireMock.Owin.Mappers
|
||||
DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
|
||||
};
|
||||
|
||||
body = await BodyParser.Parse(bodyParserSettings);
|
||||
body = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new RequestMessage(urldetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||
return new RequestMessage(urlDetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||
}
|
||||
|
||||
private (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||
private static (UrlDetails UrlDetails, string ClientIP) ParseRequest(IRequest request)
|
||||
{
|
||||
#if !USE_ASPNETCORE
|
||||
var urldetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
||||
var urlDetails = UrlUtils.Parse(request.Uri, request.PathBase);
|
||||
string clientIP = request.RemoteIpAddress;
|
||||
#else
|
||||
var urldetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
||||
var urlDetails = UrlUtils.Parse(new Uri(request.GetEncodedUrl()), request.PathBase);
|
||||
var connection = request.HttpContext.Connection;
|
||||
string clientIP = connection.RemoteIpAddress.IsIPv4MappedToIPv6
|
||||
? connection.RemoteIpAddress.MapToIPv4().ToString()
|
||||
: connection.RemoteIpAddress.ToString();
|
||||
#endif
|
||||
return (urldetails, clientIP);
|
||||
return (urlDetails, clientIP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -103,7 +103,7 @@ namespace WireMock.Owin.Mappers
|
||||
|
||||
if (bytes != null)
|
||||
{
|
||||
await response.Body.WriteAsync(bytes, 0, bytes.Length);
|
||||
await response.Body.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
@@ -19,7 +20,8 @@ namespace WireMock.Owin
|
||||
public (MappingMatcherResult Match, MappingMatcherResult Partial) FindBestMatch(RequestMessage request)
|
||||
{
|
||||
var mappings = new List<MappingMatcherResult>();
|
||||
foreach (var mapping in _options.Mappings.Values)
|
||||
|
||||
foreach (var mapping in _options.Mappings.Values.Where(m => m.TimeSettings.IsValid()))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !USE_ASPNETCORE
|
||||
#if !USE_ASPNETCORE
|
||||
using JetBrains.Annotations;
|
||||
using Microsoft.Owin.Hosting;
|
||||
using Owin;
|
||||
@@ -63,9 +63,9 @@ namespace WireMock.Owin
|
||||
private void StartServers()
|
||||
{
|
||||
#if NET46
|
||||
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
|
||||
_logger.Info("Server using .net 4.6.1 or higher");
|
||||
#else
|
||||
_logger.Info("WireMock.Net server using .net 4.5.x");
|
||||
_logger.Info("Server using .net 4.5.x");
|
||||
#endif
|
||||
var servers = new List<IDisposable>();
|
||||
|
||||
|
||||
@@ -35,28 +35,18 @@ namespace WireMock.Owin
|
||||
#if !USE_ASPNETCORE
|
||||
public WireMockMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinRequestMapper requestMapper, IOwinResponseMapper responseMapper, IMappingMatcher mappingMatcher) : base(next)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(requestMapper, nameof(requestMapper));
|
||||
Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
Check.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
|
||||
_options = options;
|
||||
_requestMapper = requestMapper;
|
||||
_responseMapper = responseMapper;
|
||||
_mappingMatcher = 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));
|
||||
}
|
||||
#else
|
||||
public WireMockMiddleware(Next next, IWireMockMiddlewareOptions options, IOwinRequestMapper requestMapper, IOwinResponseMapper responseMapper, IMappingMatcher mappingMatcher)
|
||||
{
|
||||
Check.NotNull(options, nameof(options));
|
||||
Check.NotNull(requestMapper, nameof(requestMapper));
|
||||
Check.NotNull(responseMapper, nameof(responseMapper));
|
||||
Check.NotNull(mappingMatcher, nameof(mappingMatcher));
|
||||
|
||||
_options = options;
|
||||
_requestMapper = requestMapper;
|
||||
_responseMapper = responseMapper;
|
||||
_mappingMatcher = 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));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -70,20 +60,18 @@ namespace WireMock.Owin
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
return InvokeInternal(ctx);
|
||||
return InvokeInternalAsync(ctx);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return InvokeInternal(ctx);
|
||||
}
|
||||
|
||||
return InvokeInternalAsync(ctx);
|
||||
}
|
||||
|
||||
private async Task InvokeInternal(IContext ctx)
|
||||
private async Task InvokeInternalAsync(IContext ctx)
|
||||
{
|
||||
var request = await _requestMapper.MapAsync(ctx.Request, _options);
|
||||
var request = await _requestMapper.MapAsync(ctx.Request, _options).ConfigureAwait(false);
|
||||
|
||||
bool logRequest = false;
|
||||
var logRequest = false;
|
||||
ResponseMessage response = null;
|
||||
(MappingMatcherResult Match, MappingMatcherResult Partial) result = (null, null);
|
||||
try
|
||||
@@ -126,22 +114,22 @@ namespace WireMock.Owin
|
||||
|
||||
if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero)
|
||||
{
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value);
|
||||
await Task.Delay(_options.RequestProcessingDelay.Value).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var (theResponse, theOptionalNewMapping) = await targetMapping.ProvideResponseAsync(request);
|
||||
var (theResponse, theOptionalNewMapping) = await targetMapping.ProvideResponseAsync(request).ConfigureAwait(false);
|
||||
response = theResponse;
|
||||
|
||||
var responseBuilder = targetMapping.Provider as Response;
|
||||
|
||||
if (!targetMapping.IsAdminInterface && theOptionalNewMapping != null)
|
||||
{
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMapping == true || targetMapping?.Settings?.ProxyAndRecordSettings?.SaveMapping == true)
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMapping == true || targetMapping.Settings?.ProxyAndRecordSettings?.SaveMapping == true)
|
||||
{
|
||||
_options.Mappings.TryAdd(theOptionalNewMapping.Guid, theOptionalNewMapping);
|
||||
}
|
||||
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMappingToFile == true || targetMapping?.Settings?.ProxyAndRecordSettings?.SaveMappingToFile == true)
|
||||
if (responseBuilder?.ProxyAndRecordSettings?.SaveMappingToFile == true || targetMapping.Settings?.ProxyAndRecordSettings?.SaveMappingToFile == true)
|
||||
{
|
||||
var matcherMapper = new MatcherMapper(targetMapping.Settings);
|
||||
var mappingConverter = new MappingConverter(matcherMapper);
|
||||
@@ -185,10 +173,23 @@ namespace WireMock.Owin
|
||||
|
||||
LogRequest(log, logRequest);
|
||||
|
||||
await _responseMapper.MapAsync(response, ctx.Response);
|
||||
try
|
||||
{
|
||||
if (_options.SaveUnmatchedRequests == true && result.Match?.RequestMatchResult.IsPerfectMatch != true)
|
||||
{
|
||||
var filename = $"{log.Guid}.LogEntry.json";
|
||||
_options.FileSystemHandler?.WriteUnmatchedRequest(filename, Util.JsonUtils.Serialize(log));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Empty catch
|
||||
}
|
||||
|
||||
await _responseMapper.MapAsync(response, ctx.Response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await CompletedTask;
|
||||
await CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task SendToWebhooksAsync(IMapping mapping, RequestMessage request, ResponseMessage response)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
@@ -78,5 +78,8 @@ namespace WireMock.Owin
|
||||
public bool CustomCertificateDefined =>
|
||||
!string.IsNullOrEmpty(X509StoreName) && !string.IsNullOrEmpty(X509StoreLocation) ||
|
||||
!string.IsNullOrEmpty(X509CertificateFilePath) && !string.IsNullOrEmpty(X509CertificatePassword);
|
||||
|
||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.SaveUnmatchedRequests"/>
|
||||
public bool? SaveUnmatchedRequests { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@@ -21,8 +21,7 @@ namespace WireMock.Proxy
|
||||
|
||||
public ProxyHelper([NotNull] IWireMockServerSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
_settings = settings;
|
||||
_settings = Check.NotNull(settings, nameof(settings));
|
||||
}
|
||||
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> SendAsync(
|
||||
@@ -42,13 +41,13 @@ namespace WireMock.Proxy
|
||||
var httpRequestMessage = HttpRequestMessageHelper.Create(requestMessage, url);
|
||||
|
||||
// Call the URL
|
||||
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead);
|
||||
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false);
|
||||
|
||||
// Create ResponseMessage
|
||||
bool deserializeJson = !_settings.DisableJsonBodyParsing.GetValueOrDefault(false);
|
||||
bool decompressGzipAndDeflate = !_settings.DisableRequestBodyDecompressing.GetValueOrDefault(false);
|
||||
|
||||
var responseMessage = await HttpResponseMessageHelper.CreateAsync(httpResponseMessage, requiredUri, originalUri, deserializeJson, decompressGzipAndDeflate);
|
||||
var responseMessage = await HttpResponseMessageHelper.CreateAsync(httpResponseMessage, requiredUri, originalUri, deserializeJson, decompressGzipAndDeflate).ConfigureAwait(false);
|
||||
|
||||
IMapping mapping = null;
|
||||
if (HttpStatusRangeParser.IsMatch(proxyAndRecordSettings.SaveMappingForStatusCodePattern, responseMessage.StatusCode) &&
|
||||
@@ -105,7 +104,7 @@ namespace WireMock.Proxy
|
||||
|
||||
var response = Response.Create(responseMessage);
|
||||
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null, null, null);
|
||||
return new Mapping(Guid.NewGuid(), string.Empty, null, _settings, request, response, 0, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
90
src/WireMock.Net/RegularExpressions/RegexExtended.cs
Normal file
90
src/WireMock.Net/RegularExpressions/RegexExtended.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.RegularExpressions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension to the <see cref="Regex"/> object, adding support for GUID tokens for matching on.
|
||||
/// </summary>
|
||||
#if !NETSTANDARD1_3
|
||||
[Serializable]
|
||||
#endif
|
||||
internal class RegexExtended : Regex
|
||||
{
|
||||
/// <inheritdoc cref="Regex"/>
|
||||
public RegexExtended(string pattern) : this(pattern, RegexOptions.None)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Regex"/>
|
||||
public RegexExtended(string pattern, RegexOptions options) :
|
||||
this(pattern, options, Regex.InfiniteMatchTimeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Regex"/>
|
||||
public RegexExtended(string pattern, RegexOptions options, TimeSpan matchTimeout) :
|
||||
base(ReplaceGuidPattern(pattern), options, matchTimeout)
|
||||
{
|
||||
}
|
||||
|
||||
#if !NETSTANDARD1_3
|
||||
/// <inheritdoc cref="Regex"/>
|
||||
protected RegexExtended(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) :
|
||||
base(info, context)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
// Dictionary of various Guid tokens with a corresponding regular expression pattern to use instead.
|
||||
private static readonly Dictionary<string, string> GuidTokenPatterns = new Dictionary<string, string>
|
||||
{
|
||||
// Lower case format `B` Guid pattern
|
||||
{ @"\guidb", @"(\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\})" },
|
||||
|
||||
// Upper case format `B` Guid pattern
|
||||
{ @"\GUIDB", @"(\{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}\})" },
|
||||
|
||||
// Lower case format `D` Guid pattern
|
||||
{ @"\guidd", "([a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12})" },
|
||||
|
||||
// Upper case format `D` Guid pattern
|
||||
{ @"\GUIDD", "([A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12})" },
|
||||
|
||||
// Lower case format `N` Guid pattern
|
||||
{ @"\guidn", "([a-z0-9]{32})" },
|
||||
|
||||
// Upper case format `N` Guid pattern
|
||||
{ @"\GUIDN", "([A-Z0-9]{32})" },
|
||||
|
||||
// Lower case format `P` Guid pattern
|
||||
{ @"\guidp", @"(\([a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\))" },
|
||||
|
||||
// Upper case format `P` Guid pattern
|
||||
{ @"\GUIDP", @"(\([A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}\))" },
|
||||
|
||||
// Lower case format `X` Guid pattern
|
||||
{ @"\guidx", @"(\{0x[a-f0-9]{8},0x[a-f0-9]{4},0x[a-f0-9]{4},\{(0x[a-f0-9]{2},){7}(0x[a-f0-9]{2})\}\})" },
|
||||
|
||||
// Upper case format `X` Guid pattern
|
||||
{ @"\GUIDX", @"(\{0x[A-F0-9]{8},0x[A-F0-9]{4},0x[A-F0-9]{4},\{(0x[A-F0-9]{2},){7}(0x[A-F0-9]{2})\}\})" },
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Replaces all instances of valid GUID tokens with the correct regular expression to match.
|
||||
/// </summary>
|
||||
/// <param name="pattern">Pattern to replace token for.</param>
|
||||
private static string ReplaceGuidPattern(string pattern)
|
||||
{
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
|
||||
foreach (var tokenPattern in GuidTokenPatterns)
|
||||
{
|
||||
pattern = pattern.Replace(tokenPattern.Key, tokenPattern.Value);
|
||||
}
|
||||
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,10 +54,7 @@ namespace WireMock.ResponseBuilders
|
||||
return _delay;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_delay = value;
|
||||
}
|
||||
private set => _delay = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -219,7 +216,7 @@ namespace WireMock.ResponseBuilders
|
||||
BodyData = new BodyData
|
||||
{
|
||||
DetectedBodyType = BodyType.String,
|
||||
BodyAsString = await bodyFactory(req),
|
||||
BodyAsString = await bodyFactory(req).ConfigureAwait(false),
|
||||
Encoding = encoding ?? Encoding.UTF8
|
||||
}
|
||||
});
|
||||
@@ -385,7 +382,7 @@ namespace WireMock.ResponseBuilders
|
||||
|
||||
if (Delay != null)
|
||||
{
|
||||
await Task.Delay(Delay.Value);
|
||||
await Task.Delay(Delay.Value).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (ProxyAndRecordSettings != null && _httpClientForProxy != null)
|
||||
@@ -409,7 +406,7 @@ namespace WireMock.ResponseBuilders
|
||||
_httpClientForProxy,
|
||||
requestMessage,
|
||||
requestMessage.ProxyUrl
|
||||
);
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
ResponseMessage responseMessage;
|
||||
@@ -425,7 +422,7 @@ namespace WireMock.ResponseBuilders
|
||||
}
|
||||
else
|
||||
{
|
||||
responseMessage = await CallbackAsync(requestMessage);
|
||||
responseMessage = await CallbackAsync(requestMessage).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// Copy StatusCode from ResponseMessage (if defined)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Settings;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace WireMock.ResponseProviders
|
||||
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings)
|
||||
{
|
||||
return (await _responseMessageFunc(requestMessage), null);
|
||||
return (await _responseMessageFunc(requestMessage).ConfigureAwait(false), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Settings;
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace WireMock.ResponseProviders
|
||||
|
||||
public async Task<(ResponseMessage Message, IMapping Mapping)> ProvideResponseAsync(RequestMessage requestMessage, IWireMockServerSettings settings)
|
||||
{
|
||||
return (await _responseMessageFunc(requestMessage, _settings), null);
|
||||
return (await _responseMessageFunc(requestMessage, _settings).ConfigureAwait(false), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WireMock.Serialization
|
||||
{
|
||||
@@ -15,5 +15,10 @@ namespace WireMock.Serialization
|
||||
Formatting = Formatting.Indented,
|
||||
NullValueHandling = NullValueHandling.Include
|
||||
};
|
||||
|
||||
public static readonly JsonSerializerSettings JsonDeserializerSettingsWithDateParsingNone = new JsonSerializerSettings
|
||||
{
|
||||
DateParseHandling = DateParseHandling.None
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ namespace WireMock.Serialization
|
||||
var mappingModel = new MappingModel
|
||||
{
|
||||
Guid = mapping.Guid,
|
||||
TimeSettings = TimeSettingsMapper.Map(mapping.TimeSettings),
|
||||
Title = mapping.Title,
|
||||
Priority = mapping.Priority != 0 ? mapping.Priority : (int?)null,
|
||||
Scenario = mapping.Scenario,
|
||||
|
||||
@@ -41,10 +41,11 @@ namespace WireMock.Serialization
|
||||
var matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
||||
bool ignoreCase = matcher.IgnoreCase == true;
|
||||
bool throwExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails == true;
|
||||
bool useRegexExtended = _settings.UseRegexExtended == true;
|
||||
|
||||
switch (matcherName)
|
||||
{
|
||||
case "NotNullOrEmptyMatcher":
|
||||
case nameof(NotNullOrEmptyMatcher):
|
||||
return new NotNullOrEmptyMatcher(matchBehaviour);
|
||||
|
||||
case "CSharpCodeMatcher":
|
||||
@@ -55,42 +56,46 @@ namespace WireMock.Serialization
|
||||
|
||||
throw new NotSupportedException("It's not allowed to use the 'CSharpCodeMatcher' because IWireMockServerSettings.AllowCSharpCodeMatcher is not set to 'true'.");
|
||||
|
||||
case "LinqMatcher":
|
||||
case nameof(LinqMatcher):
|
||||
return new LinqMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||
|
||||
case "ExactMatcher":
|
||||
case nameof(ExactMatcher):
|
||||
return new ExactMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||
|
||||
case "ExactObjectMatcher":
|
||||
case nameof(ExactObjectMatcher):
|
||||
return CreateExactObjectMatcher(matchBehaviour, stringPatterns[0], throwExceptionWhenMatcherFails);
|
||||
|
||||
case "RegexMatcher":
|
||||
return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
case nameof(RegexMatcher):
|
||||
return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails, useRegexExtended);
|
||||
|
||||
case "JsonMatcher":
|
||||
case nameof(JsonMatcher):
|
||||
object valueForJsonMatcher = matcher.Pattern ?? matcher.Patterns;
|
||||
return new JsonMatcher(matchBehaviour, valueForJsonMatcher, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
|
||||
case "JsonPartialMatcher":
|
||||
case nameof(JsonPartialMatcher):
|
||||
object valueForJsonPartialMatcher = matcher.Pattern ?? matcher.Patterns;
|
||||
return new JsonPartialMatcher(matchBehaviour, valueForJsonPartialMatcher, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
|
||||
case "JsonPathMatcher":
|
||||
case nameof(JsonPartialWildcardMatcher):
|
||||
object valueForJsonPartialWildcardMatcher = matcher.Pattern ?? matcher.Patterns;
|
||||
return new JsonPartialWildcardMatcher(matchBehaviour, valueForJsonPartialWildcardMatcher, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
|
||||
case nameof(JsonPathMatcher):
|
||||
return new JsonPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||
|
||||
case "JmesPathMatcher":
|
||||
case nameof(JmesPathMatcher):
|
||||
return new JmesPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||
|
||||
case "XPathMatcher":
|
||||
case nameof(XPathMatcher):
|
||||
return new XPathMatcher(matchBehaviour, throwExceptionWhenMatcherFails, stringPatterns);
|
||||
|
||||
case "WildcardMatcher":
|
||||
case nameof(WildcardMatcher):
|
||||
return new WildcardMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
|
||||
case "ContentTypeMatcher":
|
||||
case nameof(ContentTypeMatcher):
|
||||
return new ContentTypeMatcher(matchBehaviour, stringPatterns, ignoreCase, throwExceptionWhenMatcherFails);
|
||||
|
||||
case "SimMetricsMatcher":
|
||||
case nameof(SimMetricsMatcher):
|
||||
SimMetricType type = SimMetricType.Levenstein;
|
||||
if (!string.IsNullOrEmpty(matcherType) && !Enum.TryParse(matcherType, out type))
|
||||
{
|
||||
|
||||
27
src/WireMock.Net/Serialization/TimeSettingsMapper.cs
Normal file
27
src/WireMock.Net/Serialization/TimeSettingsMapper.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using WireMock.Models;
|
||||
|
||||
namespace WireMock.Serialization
|
||||
{
|
||||
internal static class TimeSettingsMapper
|
||||
{
|
||||
public static TimeSettingsModel Map(ITimeSettings settings)
|
||||
{
|
||||
return settings != null ? new TimeSettingsModel
|
||||
{
|
||||
Start = settings.Start,
|
||||
End = settings.End,
|
||||
TTL = settings.TTL
|
||||
} : null;
|
||||
}
|
||||
|
||||
public static ITimeSettings Map(TimeSettingsModel settings)
|
||||
{
|
||||
return settings != null ? new TimeSettings
|
||||
{
|
||||
Start = settings.Start,
|
||||
End = settings.End,
|
||||
TTL = settings.TTL
|
||||
} : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Models;
|
||||
@@ -24,6 +24,13 @@ namespace WireMock.Server
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithGuid(Guid guid);
|
||||
|
||||
/// <summary>
|
||||
/// Define the TimeSettings for this mapping.
|
||||
/// </summary>
|
||||
/// <param name="timeSettings">The TimeSettings.</param>
|
||||
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
|
||||
IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings);
|
||||
|
||||
/// <summary>
|
||||
/// Define a unique title for this mapping.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
||||
// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License.
|
||||
// For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -34,6 +34,8 @@ namespace WireMock.Server
|
||||
|
||||
public IWebhook[] Webhooks { get; private set; }
|
||||
|
||||
public ITimeSettings TimeSettings { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
|
||||
/// </summary>
|
||||
@@ -55,7 +57,7 @@ namespace WireMock.Server
|
||||
/// <param name="provider">The provider.</param>
|
||||
public void RespondWith(IResponseProvider provider)
|
||||
{
|
||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState, Webhooks), _saveToFile);
|
||||
_registrationCallback(new Mapping(Guid, _title, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState, Webhooks, TimeSettings), _saveToFile);
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
||||
@@ -149,6 +151,16 @@ namespace WireMock.Server
|
||||
return WillSetStateTo(state.ToString(), times);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings)
|
||||
{
|
||||
Check.NotNull(timeSettings, nameof(timeSettings));
|
||||
|
||||
TimeSettings = timeSettings;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <see cref="IRespondWithAProvider.WithWebhook(IWebhook[])"/>
|
||||
public IRespondWithAProvider WithWebhook(params IWebhook[] webhooks)
|
||||
{
|
||||
@@ -207,7 +219,7 @@ namespace WireMock.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
private IWebhook InitWebhook(
|
||||
private static IWebhook InitWebhook(
|
||||
string url,
|
||||
string method,
|
||||
IDictionary<string, WireMockList<string>> headers,
|
||||
|
||||
@@ -261,7 +261,7 @@ namespace WireMock.Server
|
||||
_httpClientForProxy,
|
||||
requestMessage,
|
||||
proxyUriWithRequestPathAndQuery.AbsoluteUri
|
||||
);
|
||||
).ConfigureAwait(false);
|
||||
|
||||
if (mapping != null)
|
||||
{
|
||||
@@ -291,7 +291,9 @@ namespace WireMock.Server
|
||||
GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds,
|
||||
AllowBodyForAllHttpMethods = _settings.AllowBodyForAllHttpMethods,
|
||||
HandleRequestsSynchronously = _settings.HandleRequestsSynchronously,
|
||||
ThrowExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails
|
||||
ThrowExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails,
|
||||
UseRegexExtended = _settings.UseRegexExtended,
|
||||
SaveUnmatchedRequests = _settings.SaveUnmatchedRequests
|
||||
};
|
||||
|
||||
return ToJson(model);
|
||||
@@ -302,31 +304,16 @@ namespace WireMock.Server
|
||||
var settings = DeserializeObject<SettingsModel>(requestMessage);
|
||||
_options.MaxRequestLogCount = settings.MaxRequestLogCount;
|
||||
_options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
|
||||
|
||||
if (settings.AllowPartialMapping != null)
|
||||
{
|
||||
_options.AllowPartialMapping = settings.AllowPartialMapping.Value;
|
||||
}
|
||||
|
||||
_options.AllowPartialMapping = settings.AllowPartialMapping;
|
||||
if (settings.GlobalProcessingDelay != null)
|
||||
{
|
||||
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
|
||||
}
|
||||
|
||||
if (settings.AllowBodyForAllHttpMethods != null)
|
||||
{
|
||||
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods.Value;
|
||||
}
|
||||
|
||||
if (settings.HandleRequestsSynchronously != null)
|
||||
{
|
||||
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously.Value;
|
||||
}
|
||||
|
||||
if (settings.ThrowExceptionWhenMatcherFails != null)
|
||||
{
|
||||
_settings.ThrowExceptionWhenMatcherFails = settings.ThrowExceptionWhenMatcherFails.Value;
|
||||
}
|
||||
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods;
|
||||
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
||||
_settings.ThrowExceptionWhenMatcherFails = settings.ThrowExceptionWhenMatcherFails;
|
||||
_settings.UseRegexExtended = settings.UseRegexExtended;
|
||||
_settings.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
||||
|
||||
return ResponseMessageBuilder.Create("Settings updated");
|
||||
}
|
||||
@@ -450,6 +437,11 @@ namespace WireMock.Server
|
||||
respondProvider = respondProvider.WithGuid(mappingModel.Guid.Value);
|
||||
}
|
||||
|
||||
if (mappingModel.TimeSettings != null)
|
||||
{
|
||||
respondProvider = respondProvider.WithTimeSettings(TimeSettingsMapper.Map(mappingModel.TimeSettings));
|
||||
}
|
||||
|
||||
if (path != null)
|
||||
{
|
||||
respondProvider = respondProvider.WithPath(path);
|
||||
@@ -681,13 +673,13 @@ namespace WireMock.Server
|
||||
}
|
||||
}
|
||||
|
||||
bool pathOrUrlmatchersValid = false;
|
||||
bool pathOrUrlMatchersValid = false;
|
||||
if (requestModel.Path != null)
|
||||
{
|
||||
if (requestModel.Path is string path)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithPath(path);
|
||||
pathOrUrlmatchersValid = true;
|
||||
pathOrUrlMatchersValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -695,7 +687,7 @@ namespace WireMock.Server
|
||||
if (pathModel?.Matchers != null)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||
pathOrUrlmatchersValid = true;
|
||||
pathOrUrlMatchersValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -704,7 +696,7 @@ namespace WireMock.Server
|
||||
if (requestModel.Url is string url)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithUrl(url);
|
||||
pathOrUrlmatchersValid = true;
|
||||
pathOrUrlMatchersValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -712,12 +704,12 @@ namespace WireMock.Server
|
||||
if (urlModel?.Matchers != null)
|
||||
{
|
||||
requestBuilder = requestBuilder.WithUrl(urlModel.Matchers.Select(_matcherMapper.Map).OfType<IStringMatcher>().ToArray());
|
||||
pathOrUrlmatchersValid = true;
|
||||
pathOrUrlMatchersValid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pathOrUrlRequired && !pathOrUrlmatchersValid)
|
||||
if (pathOrUrlRequired && !pathOrUrlMatchersValid)
|
||||
{
|
||||
_settings.Logger.Error("Path or Url matcher is missing for this mapping, this mapping will not be added.");
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using WireMock.Matchers;
|
||||
@@ -9,7 +9,7 @@ namespace WireMock.Server
|
||||
{
|
||||
public partial class WireMockServer
|
||||
{
|
||||
private readonly RegexMatcher _adminFilesFilenamePathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/files\/.*$");
|
||||
private readonly RegexMatcher _adminFilesFilenamePathMatcher = new RegexMatcher(@"^\/__admin\/files\/.*$");
|
||||
private static readonly Encoding[] FileBodyIsString = { Encoding.UTF8, Encoding.ASCII };
|
||||
|
||||
#region Files/{filename}
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace WireMock.Server
|
||||
{
|
||||
ProcessWireMockOrgJObjectAndUseStringMatcher(headers, (key, match) =>
|
||||
{
|
||||
requestBuilder = requestBuilder.WithHeader(key, match as IStringMatcher);
|
||||
requestBuilder = requestBuilder.WithHeader(key, match);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace WireMock.Server
|
||||
{
|
||||
ProcessWireMockOrgJObjectAndUseStringMatcher(cookies, (key, match) =>
|
||||
{
|
||||
requestBuilder = requestBuilder.WithCookie(key, match as IStringMatcher);
|
||||
requestBuilder = requestBuilder.WithCookie(key, match);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -77,7 +77,7 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public bool DeleteLogEntry(Guid guid)
|
||||
{
|
||||
// Check a logentry exists with the same GUID, if so, remove it.
|
||||
// Check a LogEntry exists with the same GUID, if so, remove it.
|
||||
var existing = _options.LogEntries.ToList().FirstOrDefault(m => m.Guid == guid);
|
||||
if (existing != null)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using JetBrains.Annotations;
|
||||
using Newtonsoft.Json;
|
||||
@@ -13,7 +12,6 @@ using WireMock.Authentication;
|
||||
using WireMock.Exceptions;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Matchers.Request;
|
||||
using WireMock.Owin;
|
||||
using WireMock.RequestBuilders;
|
||||
@@ -202,8 +200,8 @@ namespace WireMock.Server
|
||||
_settings.Logger = settings.Logger ?? new WireMockNullLogger();
|
||||
_settings.FileSystemHandler = settings.FileSystemHandler ?? new LocalFileSystemHandler();
|
||||
|
||||
_settings.Logger.Info("WireMock.Net by Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)");
|
||||
_settings.Logger.Debug("WireMock.Net server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
_settings.Logger.Info("By Stef Heyenrath (https://github.com/WireMock-Net/WireMock.Net)");
|
||||
_settings.Logger.Debug("Server settings {0}", JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
|
||||
HostUrlOptions urlOptions;
|
||||
if (settings.Urls != null)
|
||||
@@ -228,6 +226,7 @@ namespace WireMock.Server
|
||||
_options.Logger = _settings.Logger;
|
||||
_options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing;
|
||||
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
|
||||
_options.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
|
||||
|
||||
if (settings.CustomCertificateDefined)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using HandlebarsDotNet;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.RegularExpressions;
|
||||
#if USE_ASPNETCORE
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endif
|
||||
@@ -211,9 +213,21 @@ namespace WireMock.Settings
|
||||
bool CustomCertificateDefined { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the global IWebhookSettingsto use
|
||||
/// Defines the global IWebhookSettings to use.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
IWebhookSettings WebhookSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Use the <see cref="RegexExtended"/> instead of the default <see cref="Regex"/> (default set to true).
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
bool? UseRegexExtended { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Save unmatched requests to a file using the <see cref="IFileSystemHandler"/> (default set to false).
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
bool? SaveUnmatchedRequests { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ namespace WireMock.Settings
|
||||
public int? Port { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.UseSSL"/>
|
||||
// ReSharper disable once InconsistentNaming
|
||||
[PublicAPI]
|
||||
public bool? UseSSL { get; set; }
|
||||
|
||||
@@ -151,5 +150,13 @@ namespace WireMock.Settings
|
||||
/// <inheritdoc cref="IWireMockServerSettings.WebhookSettings"/>
|
||||
[PublicAPI]
|
||||
public IWebhookSettings WebhookSettings { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.UseRegexExtended"/>
|
||||
[PublicAPI]
|
||||
public bool? UseRegexExtended { get; set; } = true;
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.SaveUnmatchedRequests"/>
|
||||
[PublicAPI]
|
||||
public bool? SaveUnmatchedRequests { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,9 @@ namespace WireMock.Settings
|
||||
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"),
|
||||
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing"),
|
||||
HandleRequestsSynchronously = parser.GetBoolValue("HandleRequestsSynchronously"),
|
||||
ThrowExceptionWhenMatcherFails = parser.GetBoolValue("ThrowExceptionWhenMatcherFails")
|
||||
ThrowExceptionWhenMatcherFails = parser.GetBoolValue("ThrowExceptionWhenMatcherFails"),
|
||||
UseRegexExtended = parser.GetBoolValue(nameof(IWireMockServerSettings.UseRegexExtended), true),
|
||||
SaveUnmatchedRequests = parser.GetBoolValue(nameof(IWireMockServerSettings.SaveUnmatchedRequests))
|
||||
};
|
||||
|
||||
if (logger != null)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
@@ -7,7 +7,7 @@ using Newtonsoft.Json.Linq;
|
||||
using WireMock.Types;
|
||||
using WireMock.Util;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
namespace WireMock.Transformers
|
||||
{
|
||||
internal class Transformer : ITransformer
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
@@ -107,15 +107,15 @@ namespace WireMock.Util
|
||||
return BodyType.Bytes;
|
||||
}
|
||||
|
||||
public static async Task<BodyData> Parse([NotNull] BodyParserSettings settings)
|
||||
public static async Task<BodyData> ParseAsync([NotNull] BodyParserSettings settings)
|
||||
{
|
||||
Check.NotNull(settings, nameof(settings));
|
||||
|
||||
var bodyWithContentEncoding = await ReadBytesAsync(settings.Stream, settings.ContentEncoding, settings.DecompressGZipAndDeflate);
|
||||
var bodyWithContentEncoding = await ReadBytesAsync(settings.Stream, settings.ContentEncoding, settings.DecompressGZipAndDeflate).ConfigureAwait(false);
|
||||
var data = new BodyData
|
||||
{
|
||||
BodyAsBytes = bodyWithContentEncoding.Value,
|
||||
DetectedCompression = bodyWithContentEncoding.Key,
|
||||
BodyAsBytes = bodyWithContentEncoding.Bytes,
|
||||
DetectedCompression = bodyWithContentEncoding.ContentType,
|
||||
DetectedBodyType = BodyType.Bytes,
|
||||
DetectedBodyTypeFromContentType = DetectBodyTypeFromContentType(settings.ContentType)
|
||||
};
|
||||
@@ -163,20 +163,20 @@ namespace WireMock.Util
|
||||
return data;
|
||||
}
|
||||
|
||||
private static async Task<KeyValuePair<string, byte[]>> ReadBytesAsync(Stream stream, string contentEncoding = null, bool decompressGZipAndDeflate = true)
|
||||
private static async Task<(string ContentType, byte[] Bytes)> ReadBytesAsync(Stream stream, string contentEncoding = null, bool decompressGZipAndDeflate = true)
|
||||
{
|
||||
using (var memoryStream = new MemoryStream())
|
||||
{
|
||||
await stream.CopyToAsync(memoryStream);
|
||||
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||
byte[] data = memoryStream.ToArray();
|
||||
|
||||
string type = contentEncoding?.ToLowerInvariant();
|
||||
if (decompressGZipAndDeflate && (type == "gzip" || type == "deflate"))
|
||||
{
|
||||
return new KeyValuePair<string, byte[]>(type, CompressionUtils.Decompress(type, data));
|
||||
return (type, CompressionUtils.Decompress(type, data));
|
||||
}
|
||||
|
||||
return new KeyValuePair<string, byte[]>(null, data);
|
||||
return (null, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using JetBrains.Annotations;
|
||||
@@ -16,7 +16,7 @@ namespace WireMock.Util
|
||||
// Default Watch Interval in Milliseconds
|
||||
private const int DefaultWatchInterval = 100;
|
||||
|
||||
// This Dictionary keeps the track of when an event occured last for a particular file
|
||||
// This Dictionary keeps the track of when an event occurred last for a particular file
|
||||
private ConcurrentDictionary<string, DateTime> _lastFileEvent;
|
||||
|
||||
// Watch Interval in Milliseconds
|
||||
@@ -176,13 +176,13 @@ namespace WireMock.Util
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This method searches the dictionary to find out when the last event occured
|
||||
/// for a particular file. If that event occured within the specified timespan
|
||||
/// This method searches the dictionary to find out when the last event occurred
|
||||
/// for a particular file. If that event occurred within the specified timespan
|
||||
/// it returns true, else false
|
||||
/// </summary>
|
||||
/// <param name="fileName">The filename to be checked</param>
|
||||
/// <returns>True if an event has occured within the specified interval, False otherwise</returns>
|
||||
private bool HasAnotherFileEventOccuredRecently(string fileName)
|
||||
/// <returns>True if an event has occurred within the specified interval, False otherwise</returns>
|
||||
private bool HasAnotherFileEventOccurredRecently(string fileName)
|
||||
{
|
||||
// Check dictionary only if user wants to filter recent events otherwise return value stays false.
|
||||
if (!FilterRecentEvents)
|
||||
@@ -194,7 +194,7 @@ namespace WireMock.Util
|
||||
if (_lastFileEvent.ContainsKey(fileName))
|
||||
{
|
||||
// If dictionary contains the filename, check how much time has elapsed
|
||||
// since the last event occured. If the timespan is less that the
|
||||
// since the last event occurred. If the timespan is less that the
|
||||
// specified interval, set return value to true
|
||||
// and store current datetime in dictionary for this file
|
||||
DateTime lastEventTime = _lastFileEvent[fileName];
|
||||
@@ -206,7 +206,7 @@ namespace WireMock.Util
|
||||
else
|
||||
{
|
||||
// If dictionary does not contain the filename,
|
||||
// no event has occured in past for this file, so set return value to false
|
||||
// no event has occurred in past for this file, so set return value to false
|
||||
// and append filename along with current datetime to the dictionary
|
||||
_lastFileEvent.TryAdd(fileName, DateTime.Now);
|
||||
}
|
||||
@@ -215,11 +215,11 @@ namespace WireMock.Util
|
||||
}
|
||||
|
||||
#region FileSystemWatcher EventHandlers
|
||||
// Base class Event Handlers. Check if an event has occured recently and call method
|
||||
// Base class Event Handlers. Check if an event has occurred recently and call method
|
||||
// to raise appropriate event only if no recent event is detected
|
||||
private void OnChanged(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
if (!HasAnotherFileEventOccurredRecently(e.FullPath))
|
||||
{
|
||||
OnChanged(e);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ namespace WireMock.Util
|
||||
|
||||
private void OnCreated(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
if (!HasAnotherFileEventOccurredRecently(e.FullPath))
|
||||
{
|
||||
OnCreated(e);
|
||||
}
|
||||
@@ -235,7 +235,7 @@ namespace WireMock.Util
|
||||
|
||||
private void OnDeleted(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.FullPath))
|
||||
if (!HasAnotherFileEventOccurredRecently(e.FullPath))
|
||||
{
|
||||
OnDeleted(e);
|
||||
}
|
||||
@@ -243,7 +243,7 @@ namespace WireMock.Util
|
||||
|
||||
private void OnRenamed(object sender, RenamedEventArgs e)
|
||||
{
|
||||
if (!HasAnotherFileEventOccuredRecently(e.OldFullPath))
|
||||
if (!HasAnotherFileEventOccurredRecently(e.OldFullPath))
|
||||
{
|
||||
OnRenamed(e);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using WireMock.Serialization;
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
internal static class JsonUtils
|
||||
{
|
||||
private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
|
||||
public static string Serialize<T>(T value)
|
||||
{
|
||||
DateParseHandling = DateParseHandling.None
|
||||
};
|
||||
return JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsIncludeNullValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load a Newtonsoft.Json.Linq.JObject from a string that contains JSON.
|
||||
@@ -22,7 +23,7 @@ namespace WireMock.Util
|
||||
/// <returns>A Newtonsoft.Json.Linq.JToken populated from the string that contains JSON.</returns>
|
||||
public static JToken Parse(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializerSettings);
|
||||
return JsonConvert.DeserializeObject<JToken>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -33,7 +34,7 @@ namespace WireMock.Util
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
public static object DeserializeObject(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject(json, JsonSerializerSettings);
|
||||
return JsonConvert.DeserializeObject(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,7 +45,7 @@ namespace WireMock.Util
|
||||
/// <returns>The deserialized object from the JSON string.</returns>
|
||||
public static T DeserializeObject<T>(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(json, JsonSerializerSettings);
|
||||
return JsonConvert.DeserializeObject<T>(json, JsonSerializationConstants.JsonDeserializerSettingsWithDateParsingNone);
|
||||
}
|
||||
|
||||
public static T ParseJTokenToObject<T>(object value)
|
||||
|
||||
@@ -50,17 +50,19 @@
|
||||
<DefineConstants>USE_ASPNETCORE;NET46</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||
<!--<PackageReference Include="Stef.Validation" Version="0.0.3" />-->
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.12" />
|
||||
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
||||
<PackageReference Include="AnyOf" Version="0.2.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="SimMetrics.Net" Version="1.0.5" />
|
||||
<!--<PackageReference Include="Stef.Validation" Version="0.0.3" />-->
|
||||
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.0.12" />
|
||||
<PackageReference Include="RandomDataGenerator.Net" Version="1.0.13" />
|
||||
<PackageReference Include="JmesPath.Net" Version="1.0.125" />
|
||||
<PackageReference Include="AnyOf" Version="0.2.0" />
|
||||
<!--<PackageReference Include="TinyMapper" Version="3.0.3" />-->
|
||||
<!--<PackageReference Include="Mapster" Version="7.2.0" />-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(Configuration)' == 'Debug - Sonar'">
|
||||
<PackageReference Include="SonarAnalyzer.CSharp" Version="7.8.0.7320">
|
||||
@@ -69,10 +71,10 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
||||
<PackageReference Include="XPath2.Extensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard1.3' ">
|
||||
<PackageReference Include="XPath2.Extensions" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.12.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'net452' ">
|
||||
<!-- Required for WebRequestHandler -->
|
||||
@@ -81,11 +83,12 @@
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.6" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
|
||||
<PackageReference Include="Scriban.Signed" Version="2.1.4" />
|
||||
<PackageReference Include="Mapster" Version="7.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.6" />
|
||||
<PackageReference Include="Microsoft.Owin" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Owin" Version="4.1.1" />
|
||||
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.Owin.Hosting" Version="4.0.0" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.4" />
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<!--<PackageReference Include="AnyOf" Version="0.1.0" />-->
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2021.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Net.StandAlone;
|
||||
using WireMock.Server;
|
||||
|
||||
namespace WireMock
|
||||
namespace WireMock.Net
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static int SleepTime = 30000;
|
||||
private static readonly ILogger Logger = LoggerFactory.Create(o =>
|
||||
private static readonly int SleepTime = 30000;
|
||||
private static readonly ILogger xLogger = LoggerFactory.Create(o =>
|
||||
{
|
||||
o.SetMinimumLevel(LogLevel.Debug);
|
||||
o.AddSimpleConsole(options =>
|
||||
@@ -18,18 +19,19 @@ namespace WireMock
|
||||
options.SingleLine = false;
|
||||
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss ";
|
||||
});
|
||||
}).CreateLogger(string.Empty);
|
||||
}).CreateLogger("WireMock.Net");
|
||||
private static readonly IWireMockLogger Logger = new WireMockLogger(xLogger);
|
||||
|
||||
private static WireMockServer Server;
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
if (!StandAloneApp.TryStart(args, out Server, new WireMockLogger(Logger)))
|
||||
if (!StandAloneApp.TryStart(args, out Server, Logger))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.LogInformation("Press Ctrl+C to shut down");
|
||||
Logger.Info("Press Ctrl+C to shut down");
|
||||
|
||||
Console.CancelKeyPress += (s, e) =>
|
||||
{
|
||||
@@ -43,16 +45,16 @@ namespace WireMock
|
||||
|
||||
while (true)
|
||||
{
|
||||
Logger.LogInformation("WireMock.Net server running : {IsStarted}", Server.IsStarted);
|
||||
await Task.Delay(SleepTime);
|
||||
Logger.Info("Server running : {IsStarted}", Server.IsStarted);
|
||||
await Task.Delay(SleepTime).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Stop(string why)
|
||||
{
|
||||
Logger.LogInformation("WireMock.Net server stopping because '{why}'", why);
|
||||
Logger.Info("Server stopping because '{why}'", why);
|
||||
Server.Stop();
|
||||
Logger.LogInformation("WireMock.Net server stopped");
|
||||
Logger.Info("Server stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WireMock.Admin.Requests;
|
||||
using WireMock.Logging;
|
||||
|
||||
namespace WireMock
|
||||
namespace WireMock.Net
|
||||
{
|
||||
public class WireMockLogger : IWireMockLogger
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task AtAbsoluteUrl_WhenACallWasMadeToAbsoluteUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl");
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -56,7 +56,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task AtAbsoluteUrl_Should_ThrowWhenNoCallsMatchingTheAbsoluteUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -72,7 +72,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
public async Task WithHeader_WhenACallWasMadeWithExpectedHeader_Should_BeOK()
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer a");
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -84,7 +84,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -94,7 +94,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task WithHeader_Should_ThrowWhenNoCallsMatchingTheHeaderNameWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -110,7 +110,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -134,7 +134,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
{
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
|
||||
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -153,7 +153,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task AtUrl_WhenACallWasMadeToUrl_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("anyurl");
|
||||
await _httpClient.GetAsync("anyurl").ConfigureAwait(false);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -176,7 +176,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task AtUrl_Should_ThrowWhenNoCallsMatchingTheUrlWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -195,7 +195,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
_server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -226,7 +226,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
_server.Given(Request.Create().UsingAnyMethod())
|
||||
.RespondWith(Response.Create().WithProxy(new ProxyAndRecordSettings { Url = "http://localhost:9999" }));
|
||||
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
|
||||
Action act = () => _server.Should()
|
||||
.HaveReceivedACall()
|
||||
@@ -241,7 +241,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task FromClientIP_whenACallWasMadeFromClientIP_Should_BeOK()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
_server.Should()
|
||||
@@ -265,7 +265,7 @@ namespace WireMock.Net.Tests.FluentAssertions
|
||||
[Fact]
|
||||
public async Task FromClientIP_Should_ThrowWhenNoCallsFromClientIPWereMade()
|
||||
{
|
||||
await _httpClient.GetAsync("");
|
||||
await _httpClient.GetAsync("").ConfigureAwait(false);
|
||||
var clientIP = _server.LogEntries.Last().RequestMessage.ClientIP;
|
||||
|
||||
Action act = () => _server.Should()
|
||||
|
||||
@@ -85,5 +85,22 @@ namespace WireMock.Net.Tests.Handlers
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.DeleteFile(null)).Throws<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_GetUnmatchedRequestsFolder()
|
||||
{
|
||||
// Act
|
||||
string result = _sut.GetUnmatchedRequestsFolder();
|
||||
|
||||
// Assert
|
||||
Check.That(result).EndsWith(Path.Combine("requests", "unmatched"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalFileSystemHandler_WriteUnmatchedRequest()
|
||||
{
|
||||
// Act
|
||||
Check.ThatCode(() => _sut.WriteUnmatchedRequest(null, null)).Throws<ArgumentNullException>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
@@ -20,7 +20,7 @@ namespace WireMock.Net.Tests.Http
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.Should().BeNull();
|
||||
(await result.ReadAsByteArrayAsync()).Should().BeEquivalentTo(content);
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -38,7 +38,7 @@ namespace WireMock.Net.Tests.Http
|
||||
|
||||
// Assert
|
||||
result.Headers.ContentType.ToString().Should().Be(expected);
|
||||
(await result.ReadAsByteArrayAsync()).Should().BeEquivalentTo(content);
|
||||
(await result.ReadAsByteArrayAsync().ConfigureAwait(false)).Should().BeEquivalentTo(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -43,7 +43,7 @@ namespace WireMock.Net.Tests.Http
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsByteArrayAsync()).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
Check.That(await message.Content.ReadAsByteArrayAsync().ConfigureAwait(false)).ContainsExactly(Encoding.UTF8.GetBytes("hi"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +61,7 @@ namespace WireMock.Net.Tests.Http
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync()).Equals("{\"x\":42}");
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,7 +80,7 @@ namespace WireMock.Net.Tests.Http
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync()).Equals("{\"x\":42}");
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json");
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace WireMock.Net.Tests.Http
|
||||
var message = HttpRequestMessageHelper.Create(request, "http://url");
|
||||
|
||||
// Assert
|
||||
Check.That(await message.Content.ReadAsStringAsync()).Equals("{\"x\":42}");
|
||||
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals("{\"x\":42}");
|
||||
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/json; charset=utf-8");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,400 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
{
|
||||
public class JsonPartialWildcardMatcherTests
|
||||
{
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("{}");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("JsonPartialWildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_GetValue()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("{}");
|
||||
|
||||
// Act
|
||||
object value = matcher.Value;
|
||||
|
||||
// Assert
|
||||
Check.That(value).Equals("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_WithInvalidStringValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
Action action = () => new JsonPartialWildcardMatcher(MatchBehaviour.AcceptOnMatch, "{ \"Id\"");
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_WithInvalidObjectValue_Should_ThrowException()
|
||||
{
|
||||
// Act
|
||||
Action action = () => new JsonPartialWildcardMatcher(MatchBehaviour.AcceptOnMatch, new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsFalse_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithInvalidValue_And_ThrowExceptionIsTrue_Should_ReturnMismatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("", false, true);
|
||||
|
||||
// Act
|
||||
Action action = () => matcher.IsMatch(new MemoryStream());
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_ByteArray()
|
||||
{
|
||||
// Assign
|
||||
var bytes = new byte[0];
|
||||
var matcher = new JsonPartialWildcardMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(bytes);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_NullString()
|
||||
{
|
||||
// Assign
|
||||
string s = null;
|
||||
var matcher = new JsonPartialWildcardMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(s);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_NullObject()
|
||||
{
|
||||
// Assign
|
||||
object o = null;
|
||||
var matcher = new JsonPartialWildcardMatcher("");
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(o);
|
||||
|
||||
// Assert
|
||||
Check.That(match).IsEqualTo(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JArray()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new[] { "x", "y" });
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithIgnoreCaseTrue_JObject()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new { id = 1, Name = "test" }, true);
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "NaMe", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new { Id = 1, Name = "Test" });
|
||||
|
||||
// Act
|
||||
var jobject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithIgnoreCaseTrue_JObjectParsed()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(new { Id = 1, Name = "TESt" }, true);
|
||||
|
||||
// Act
|
||||
var jobject = JObject.Parse("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JArrayAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("[ \"x\", \"y\" ]");
|
||||
|
||||
// Act
|
||||
var jArray = new JArray
|
||||
{
|
||||
"x",
|
||||
"y"
|
||||
};
|
||||
double match = matcher.IsMatch(jArray);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_WithIgnoreCaseTrue_JObjectAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("{ \"Id\" : 1, \"Name\" : \"test\" }", true);
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JObjectAsString_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(MatchBehaviour.RejectOnMatch, "{ \"Id\" : 1, \"Name\" : \"Test\" }");
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "Id", new JValue(1) },
|
||||
{ "Name", new JValue("Test") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_JObjectWithDateTimeOffsetAsString()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher("{ \"preferredAt\" : \"2019-11-21T10:32:53.2210009+00:00\" }");
|
||||
|
||||
// Act
|
||||
var jobject = new JObject
|
||||
{
|
||||
{ "preferredAt", new JValue("2019-11-21T10:32:53.2210009+00:00") }
|
||||
};
|
||||
double match = matcher.IsMatch(jobject);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"test\":\"abc\"}", "{\"test\":\"abc\",\"other\":\"xyz\"}")]
|
||||
[InlineData("\"test\"", "\"test\"")]
|
||||
[InlineData("123", "123")]
|
||||
[InlineData("[\"test\"]", "[\"test\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test\", \"other\"]")]
|
||||
[InlineData("[123]", "[123]")]
|
||||
[InlineData("[123]", "[123, 456]")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\",\"other\":123}")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value\"}")]
|
||||
[InlineData("{\"test\":{\"nested\":\"value\"}}", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_StringInput_IsValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{\"test\":\"*\"}", "{\"test\":\"xxx\",\"other\":\"xyz\"}")]
|
||||
[InlineData("\"t*t\"", "\"test\"")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_StringInputWithWildcard_IsValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
match.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("\"test\"", null)]
|
||||
[InlineData("\"test1\"", "\"test2\"")]
|
||||
[InlineData("123", "1234")]
|
||||
[InlineData("[\"test\"]", "[\"test1\"]")]
|
||||
[InlineData("[\"test\"]", "[\"test1\", \"test2\"]")]
|
||||
[InlineData("[123]", "[1234]")]
|
||||
[InlineData("{}", "\"test\"")]
|
||||
[InlineData("{ \"test\":\"value\" }", "{\"test\":\"value2\"}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{\"test\":{\"test1\":\"value\"}}", "{\"test\":{\"test1\":\"value1\"}}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_StringInputWithInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":123}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[123, 456]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value\"}]")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_ValueAsJPathValidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1.0, match);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("{ \"test.nested\":123 }", "{\"test\":{\"nested\":456}}")]
|
||||
[InlineData("{ \"test.nested\":[123, 456] }", "{\"test\":{\"nested\":[1, 2]}}")]
|
||||
[InlineData("{ \"test.nested\":\"value\" }", "{\"test\":{\"nested\":\"value1\"}}")]
|
||||
[InlineData("{ \"['name.with.dot']\":\"value\" }", "{\"name.with.dot\":\"value1\"}")]
|
||||
[InlineData("[{ \"test.nested\":\"value\" }]", "[{\"test\":{\"nested\":\"value1\"}}]")]
|
||||
[InlineData("[{ \"['name.with.dot']\":\"value\" }]", "[{\"name.with.dot\":\"value1\"}]")]
|
||||
public void JsonPartialWildcardMatcher_IsMatch_ValueAsJPathInvalidMatch(string value, string input)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new JsonPartialWildcardMatcher(value);
|
||||
|
||||
// Act
|
||||
double match = matcher.IsMatch(input);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0.0, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
@@ -70,6 +72,32 @@ namespace WireMock.Net.Tests.Matchers
|
||||
Check.That(result).IsEqualTo(0.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_RegexExtended_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true);
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
|
||||
// Assert
|
||||
result.Should().Be(1.0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_Regex_Guid()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new RegexMatcher(@"\GUIDB", true, false, false);
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch(Guid.NewGuid().ToString("B"));
|
||||
|
||||
// Assert
|
||||
result.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_IsMatch_IgnoreCase()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -41,7 +41,7 @@ namespace WireMock.Net.Tests
|
||||
server.LogEntriesChanged += (sender, args) => throw new Exception();
|
||||
|
||||
// Act
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}");
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
loggerMock.Verify(l => l.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
@@ -65,7 +65,7 @@ namespace WireMock.Net.Tests
|
||||
server.LogEntriesChanged += (sender, args) => count++;
|
||||
|
||||
// Act
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}");
|
||||
await new HttpClient().GetAsync($"http://localhost:{server.Ports[0]}{path}").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(count).Equals(1);
|
||||
@@ -101,7 +101,7 @@ namespace WireMock.Net.Tests
|
||||
Thread.Sleep(50);
|
||||
listOfTasks.Add(http.GetAsync($"{server.Urls[0]}{path}"));
|
||||
}
|
||||
var responses = await Task.WhenAll(listOfTasks);
|
||||
var responses = await Task.WhenAll(listOfTasks).ConfigureAwait(false);
|
||||
var countResponsesWithStatusNotOk = responses.Count(r => r.StatusCode != HttpStatusCode.OK);
|
||||
|
||||
// Assert
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
using Moq;
|
||||
@@ -66,7 +66,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
public async Task OwinResponseMapper_MapAsync_Null()
|
||||
{
|
||||
// Act
|
||||
await _sut.MapAsync(null, _responseMock.Object);
|
||||
await _sut.MapAsync(null, _responseMock.Object).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -81,7 +81,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -102,7 +102,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -118,7 +118,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = It.IsAny<int>(), Times.Never);
|
||||
@@ -138,7 +138,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = expected, Times.Once);
|
||||
@@ -154,7 +154,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
@@ -172,7 +172,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 97, 98, 99, 100 }, 0, 4, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -190,7 +190,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(bytes, 0, bytes.Length, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -208,7 +208,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[] { 123, 34, 116, 34, 58, 34, 120, 34, 125 }, 0, 9, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -224,7 +224,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
#if NET452
|
||||
@@ -248,7 +248,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_stream.Verify(s => s.WriteAsync(new byte[0], 0, 0, It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -270,7 +270,7 @@ namespace WireMock.Net.Tests.Owin.Mappers
|
||||
};
|
||||
|
||||
// Act
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object);
|
||||
await _sut.MapAsync(responseMessage, _responseMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
_responseMock.VerifySet(r => r.StatusCode = 100, Times.Once);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -80,7 +80,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
public async Task WireMockMiddleware_Invoke_NoMatch()
|
||||
{
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Warn(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
@@ -103,7 +103,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
@@ -126,7 +126,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert and Verify
|
||||
_optionsMock.Verify(o => o.Logger.Error(It.IsAny<string>(), It.IsAny<object[]>()), Times.Once);
|
||||
@@ -142,7 +142,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_optionsMock.SetupGet(o => o.RequestLogExpirationDuration).Returns(1);
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -176,7 +176,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||
|
||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null);
|
||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
|
||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||
@@ -186,7 +186,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert and Verify
|
||||
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -230,7 +230,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
|
||||
_mappingMock.SetupGet(m => m.Settings).Returns(settings);
|
||||
|
||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null);
|
||||
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, null);
|
||||
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
|
||||
|
||||
var requestBuilder = Request.Create().UsingAnyMethod();
|
||||
@@ -240,7 +240,7 @@ namespace WireMock.Net.Tests.Owin
|
||||
_matcherMock.Setup(m => m.FindBestMatch(It.IsAny<RequestMessage>())).Returns((result, result));
|
||||
|
||||
// Act
|
||||
await _sut.Invoke(_contextMock.Object);
|
||||
await _sut.Invoke(_contextMock.Object).ConfigureAwait(false);
|
||||
|
||||
// Assert and Verify
|
||||
fileSystemHandlerMock.Verify(f => f.WriteMappingFile(It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
|
||||
100
test/WireMock.Net.Tests/RegularExpressions/RegexExtendedTests.cs
Normal file
100
test/WireMock.Net.Tests/RegularExpressions/RegexExtendedTests.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using NFluent;
|
||||
using WireMock.RegularExpressions;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.RegularExpressions
|
||||
{
|
||||
public class RegexExtendedTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Input guid used for testing
|
||||
/// </summary>
|
||||
public Guid InputGuid => Guid.NewGuid();
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidB_Pattern()
|
||||
{
|
||||
var guidbUpper = @".*\GUIDB.*";
|
||||
var guidbLower = @".*\guidb.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("B");
|
||||
var inputUpper = InputGuid.ToString("B").ToUpper();
|
||||
var regexLower = new RegexExtended(guidbLower);
|
||||
var regexUpper = new RegexExtended(guidbUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidD_Pattern()
|
||||
{
|
||||
var guiddUpper = @".*\GUIDD.*";
|
||||
var guiddLower = @".*\guidd.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("D");
|
||||
var inputUpper = InputGuid.ToString("D").ToUpper();
|
||||
var regexLower = new RegexExtended(guiddLower);
|
||||
var regexUpper = new RegexExtended(guiddUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidN_Pattern()
|
||||
{
|
||||
var guidnUpper = @".*\GUIDN.*";
|
||||
var guidnLower = @".*\guidn.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("N");
|
||||
var inputUpper = InputGuid.ToString("N").ToUpper();
|
||||
var regexLower = new RegexExtended(guidnLower);
|
||||
var regexUpper = new RegexExtended(guidnUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidP_Pattern()
|
||||
{
|
||||
var guidpUpper = @".*\GUIDP.*";
|
||||
var guidpLower = @".*\guidp.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("P");
|
||||
var inputUpper = InputGuid.ToString("P").ToUpper();
|
||||
var regexLower = new RegexExtended(guidpLower);
|
||||
var regexUpper = new RegexExtended(guidpUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RegexExtended_GuidX_Pattern()
|
||||
{
|
||||
var guidxUpper = @".*\GUIDX.*";
|
||||
var guidxLower = @".*\guidx.*";
|
||||
|
||||
var inputLower = InputGuid.ToString("X");
|
||||
var inputUpper = InputGuid.ToString("X").ToUpper().Replace("X", "x");
|
||||
var regexLower = new RegexExtended(guidxLower);
|
||||
var regexUpper = new RegexExtended(guidxUpper);
|
||||
|
||||
Check.That(regexLower.IsMatch(inputLower)).Equals(true);
|
||||
Check.That(regexLower.IsMatch(inputUpper)).Equals(false);
|
||||
Check.That(regexUpper.IsMatch(inputUpper)).Equals(true);
|
||||
Check.That(regexUpper.IsMatch(inputLower)).Equals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,7 +301,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
bodyData = await BodyParser.Parse(bodyParserSettings);
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
else if (body is string s)
|
||||
{
|
||||
@@ -311,7 +311,7 @@ namespace WireMock.Net.Tests.RequestMatchers
|
||||
ContentType = null,
|
||||
DeserializeJson = true
|
||||
};
|
||||
bodyData = await BodyParser.Parse(bodyParserSettings);
|
||||
bodyData = await BodyParser.ParseAsync(bodyParserSettings).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using NFluent;
|
||||
using WireMock.Models;
|
||||
using WireMock.ResponseBuilders;
|
||||
@@ -21,7 +21,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
var responseBuilder = Response.Create(() => responseMessage);
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(request, _settings);
|
||||
var response = await responseBuilder.ProvideResponseAsync(request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
Check.That(response.Message).Equals(responseMessage);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using FluentAssertions;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -37,7 +37,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
);
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Should().Contain("<hello>world</hello>");
|
||||
@@ -68,7 +68,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
);
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Should().Contain("<hello>world</hello>");
|
||||
@@ -99,7 +99,7 @@ namespace WireMock.Net.Tests.ResponseBuilders
|
||||
);
|
||||
|
||||
// Act
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content");
|
||||
var response = await new HttpClient().GetStringAsync("http://localhost:" + server.Ports[0] + "/v1/content").ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
response.Should().Contain("<hello>world</hello>");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user