From 89f4c87d313cd8c0ec1a006a553872c5d63eece6 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Thu, 29 Aug 2019 07:46:23 +0200 Subject: [PATCH] Updated Request Matching (markdown) --- Request-Matching.md | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Request-Matching.md b/Request-Matching.md index 6ae4817..5326b9e 100644 --- a/Request-Matching.md +++ b/Request-Matching.md @@ -14,6 +14,7 @@ The following paragraphs describe in detail which matchers can be used. At this moment these matchers are supported: * [ExactMatcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#exact-matcher-exactmatcher) * [LinqMatcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#dynamic-linq-linqmatcher) +* CSharpCodeMatcher * [JsonMatcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#json-jsonmatcher) * [JsonPathMatcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#json-path-jsonpathmatcher) * [JmesPathMatcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#jmes-path-jmespathmatcher) @@ -115,6 +116,56 @@ server } ``` +## CSharp Code (CSharpCodeMatcher) +*Advanced!* With this matcher you can use complex C# code to match an JObject or string value. +* Note that this functionality will only work if enabled in the settings (`AllowCSharpCodeMatcher = true`). +* The argument-name from the string or JObject to match will be `it`. + + +#### C# option +```csharp +var server = FluentMockServer.Start(); +server + .Given(Request.Create().WithPath("/cs") + .WithParam("from", new CSharpCodeMatcher("return it == \"x\";"))) + .RespondWith(Response.Create() + .WithBody("cs match") + ); +``` + +#### JSON Mapping option +``` js +{ + "Guid": "67ae335b-5d79-42dc-8ca7-236280ab9211", + "Priority": 0, + "Request": { + "Path": { + "Matchers": [ + { + "Name": "WildcardMatcher", + "Pattern": "/cs" + } + ] + }, + "Params": [ + { + "Name": "from", + "Matchers": [ + { + "Name": "CSharpCodeMatcher", + "Pattern": "return it == \"x\";" + } + ] + } + ], + "Body": {} + }, + "Response": { + "Body": "cs match" + } +} +``` + ## JSON (JsonMatcher) Checks if a JSON object (or JSON as string) is DeepEqual.