# Summary

Class: | WireMock.Matchers.Request.RequestMessageBodyMatcher
Assembly: | WireMock.Net
File(s): | C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageBodyMatcher.cs
Covered lines: | 67
Uncovered lines: | 0
Coverable lines: | 67
Total lines: | 158
Line coverage: | 100%
Branch coverage: | 88.4%

# Metrics

Method | Cyclomatic complexity | NPath complexity | Sequence coverage | Branch coverage
--- | --- | --- | --- | ---
GetMatchingScore(...) | 0 | 0 | 1 | 0
IsMatch(...) | 0 | 0 | 1 | 0.885
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0
.ctor(...) | 0 | 0 | 1 | 0

# File(s)

## C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Matchers\Request\RequestMessageBodyMatcher.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using JetBrains.Annotations;`
|  | `3` |  | `using WireMock.Validation;`
|  | `4` |  | ``
|  | `5` |  | `namespace WireMock.Matchers.Request`
|  | `6` |  | `{`
|  | `7` |  | `/// <summary>`
|  | `8` |  | `/// The request body matcher.`
|  | `9` |  | `/// </summary>`
|  | `10` |  | `public class RequestMessageBodyMatcher : IRequestMatcher`
|  | `11` |  | `{`
|  | `12` |  | `/// <summary>`
|  | `13` |  | `/// The body function`
|  | `14` |  | `/// </summary>`
| 6 | `15` |  | `public Func<string, bool> Func { get; }`
|  | `16` |  | ``
|  | `17` |  | `/// <summary>`
|  | `18` |  | `/// The body data function for byte[]`
|  | `19` |  | `/// </summary>`
| 5 | `20` |  | `public Func<byte[], bool> DataFunc { get; }`
|  | `21` |  | ``
|  | `22` |  | `/// <summary>`
|  | `23` |  | `/// The body data function for json`
|  | `24` |  | `/// </summary>`
| 4 | `25` |  | `public Func<object, bool> JsonFunc { get; }`
|  | `26` |  | ``
|  | `27` |  | `/// <summary>`
|  | `28` |  | `/// The matcher.`
|  | `29` |  | `/// </summary>`
| 52 | `30` |  | `public IMatcher Matcher { get; }`
|  | `31` |  | ``
|  | `32` |  | `/// <summary>`
|  | `33` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `34` |  | `/// </summary>`
|  | `35` |  | `/// <param name="matchBehaviour">The match behaviour.</param>`
|  | `36` |  | `/// <param name="body">The body.</param>`
| 2 | `37` |  | `public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] string body) : this(new WildcardMatche`
| 2 | `38` |  | `{`
| 2 | `39` |  | `}`
|  | `40` |  | ``
|  | `41` |  | `/// <summary>`
|  | `42` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `43` |  | `/// </summary>`
|  | `44` |  | `/// <param name="matchBehaviour">The match behaviour.</param>`
|  | `45` |  | `/// <param name="body">The body.</param>`
| 1 | `46` |  | `public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] byte[] body) : this(new ExactObjectMat`
| 1 | `47` |  | `{`
| 1 | `48` |  | `}`
|  | `49` |  | ``
|  | `50` |  | `/// <summary>`
|  | `51` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `52` |  | `/// </summary>`
|  | `53` |  | `/// <param name="matchBehaviour">The match behaviour.</param>`
|  | `54` |  | `/// <param name="body">The body.</param>`
| 1 | `55` |  | `public RequestMessageBodyMatcher(MatchBehaviour matchBehaviour, [NotNull] object body) : this(new ExactObjectMat`
| 1 | `56` |  | `{`
| 1 | `57` |  | `}`
|  | `58` |  | ``
|  | `59` |  | `/// <summary>`
|  | `60` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `61` |  | `/// </summary>`
|  | `62` |  | `/// <param name="func">The function.</param>`
| 1 | `63` |  | `public RequestMessageBodyMatcher([NotNull] Func<string, bool> func)`
| 1 | `64` |  | `{`
| 1 | `65` |  | `Check.NotNull(func, nameof(func));`
| 1 | `66` |  | `Func = func;`
| 1 | `67` |  | `}`
|  | `68` |  | ``
|  | `69` |  | `/// <summary>`
|  | `70` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `71` |  | `/// </summary>`
|  | `72` |  | `/// <param name="func">The function.</param>`
| 1 | `73` |  | `public RequestMessageBodyMatcher([NotNull] Func<byte[], bool> func)`
| 1 | `74` |  | `{`
| 1 | `75` |  | `Check.NotNull(func, nameof(func));`
| 1 | `76` |  | `DataFunc = func;`
| 1 | `77` |  | `}`
|  | `78` |  | ``
|  | `79` |  | `/// <summary>`
|  | `80` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `81` |  | `/// </summary>`
|  | `82` |  | `/// <param name="func">The function.</param>`
| 1 | `83` |  | `public RequestMessageBodyMatcher([NotNull] Func<object, bool> func)`
| 1 | `84` |  | `{`
| 1 | `85` |  | `Check.NotNull(func, nameof(func));`
| 1 | `86` |  | `JsonFunc = func;`
| 1 | `87` |  | `}`
|  | `88` |  | ``
|  | `89` |  | `/// <summary>`
|  | `90` |  | `/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.`
|  | `91` |  | `/// </summary>`
|  | `92` |  | `/// <param name="matcher">The matcher.</param>`
| 30 | `93` |  | `public RequestMessageBodyMatcher([NotNull] IMatcher matcher)`
| 30 | `94` |  | `{`
| 30 | `95` |  | `Check.NotNull(matcher, nameof(matcher));`
| 30 | `96` |  | `Matcher = matcher;`
| 30 | `97` |  | `}`
|  | `98` |  | ``
|  | `99` |  | `/// <see cref="IRequestMatcher.GetMatchingScore"/>`
|  | `100` |  | `public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult)`
| 30 | `101` |  | `{`
| 30 | `102` |  | `double score = IsMatch(requestMessage);`
| 30 | `103` |  | `return requestMatchResult.AddScore(GetType(), score);`
| 30 | `104` |  | `}`
|  | `105` |  | ``
|  | `106` |  | `private double IsMatch(RequestMessage requestMessage)`
| 30 | `107` |  | `{`
|  | `108` |  | `// Check if the matcher is a IObjectMatcher`
| 30 | `109` |  | `if (Matcher is IObjectMatcher objectMatcher)`
| 11 | `110` |  | `{`
|  | `111` |  | `// If the body is a JSON object, try to match.`
| 11 | `112` |  | `if (requestMessage.BodyAsJson != null)`
| 6 | `113` |  | `{`
| 6 | `114` |  | `return objectMatcher.IsMatch(requestMessage.BodyAsJson);`
|  | `115` |  | `}`
|  | `116` |  | ``
|  | `117` |  | `// If the body is a byte array, try to match.`
| 5 | `118` |  | `if (requestMessage.BodyAsBytes != null)`
| 2 | `119` |  | `{`
| 2 | `120` |  | `return objectMatcher.IsMatch(requestMessage.BodyAsBytes);`
|  | `121` |  | `}`
| 3 | `122` |  | `}`
|  | `123` |  | ``
|  | `124` |  | `// Check if the matcher is a IStringMatcher`
| 22 | `125` |  | `if (Matcher is IStringMatcher stringMatcher)`
| 19 | `126` |  | `{`
|  | `127` |  | `// If the body is a JSON object, try to use Body (string) to match.`
| 19 | `128` |  | `if (requestMessage.BodyAsJson != null && requestMessage.Body != null)`
| 4 | `129` |  | `{`
| 4 | `130` |  | `return stringMatcher.IsMatch(requestMessage.Body);`
|  | `131` |  | `}`
|  | `132` |  | ``
|  | `133` |  | `// If the string body is defined, try to match.`
| 15 | `134` |  | `if (requestMessage.Body != null)`
| 13 | `135` |  | `{`
| 13 | `136` |  | `return stringMatcher.IsMatch(requestMessage.Body);`
|  | `137` |  | `}`
| 2 | `138` |  | `}`
|  | `139` |  | ``
| 5 | `140` |  | `if (Func != null)`
| 1 | `141` |  | `{`
| 1 | `142` |  | `return MatchScores.ToScore(requestMessage.Body != null && Func(requestMessage.Body));`
|  | `143` |  | `}`
|  | `144` |  | ``
| 4 | `145` |  | `if (DataFunc != null)`
| 1 | `146` |  | `{`
| 1 | `147` |  | `return MatchScores.ToScore(requestMessage.BodyAsBytes != null && DataFunc(requestMessage.BodyAsBytes));`
|  | `148` |  | `}`
|  | `149` |  | ``
| 3 | `150` |  | `if (JsonFunc != null)`
| 1 | `151` |  | `{`
| 1 | `152` |  | `return MatchScores.ToScore(requestMessage.BodyAsJson != null && JsonFunc(requestMessage.BodyAsJson));`
|  | `153` |  | `}`
|  | `154` |  | ``
| 2 | `155` |  | `return MatchScores.Mismatch;`
| 30 | `156` |  | `}`
|  | `157` |  | `}`
|  | `158` |  | `}`

# Methods/Properties

Func()
DataFunc()
JsonFunc()
Matcher()
.ctor(WireMock.Matchers.MatchBehaviour,System.String)
.ctor(WireMock.Matchers.MatchBehaviour,System.Byte[])
.ctor(WireMock.Matchers.MatchBehaviour,System.Object)
.ctor(System.Func`2<System.String,System.Boolean>)
.ctor(System.Func`2<System.Byte[],System.Boolean>)
.ctor(System.Func`2<System.Object,System.Boolean>)
.ctor(WireMock.Matchers.IMatcher)
GetMatchingScore(WireMock.RequestMessage,WireMock.Matchers.Request.RequestMatchResult)
IsMatch(WireMock.RequestMessage)