Add MatchOperator "Or", "And" and "Average" for patterns (#755)

* wip

* ...

* .

* ...

* ...

* path

* url

* b

* t

* client

* .

* RequestMessageMethodMatcherTests

* .

* h

* .

* fix tests

* .
This commit is contained in:
Stef Heyenrath
2022-06-09 21:31:54 +02:00
committed by GitHub
parent 1f23022460
commit 0441c1d85e
95 changed files with 5736 additions and 5111 deletions

View File

@@ -0,0 +1,61 @@
using FluentAssertions;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Models;
using Xunit;
namespace WireMock.Net.Tests.RequestMatchers;
public class RequestMessageMethodMatcherTests
{
[Theory]
[InlineData("get", 1d)]
[InlineData("post", 1d)]
[InlineData("trace", 0d)]
public void RequestMessageMethodMatcherTests_GetMatchingScore_Or(string method, double expected)
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), method, "127.0.0.1");
var matcher = new RequestMessageMethodMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Or, "Get", "Post");
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
score.Should().Be(expected);
}
[Theory]
[InlineData("get", 0.5d)]
[InlineData("post", 0.5d)]
[InlineData("trace", 0d)]
public void RequestMessageMethodMatcherTests_GetMatchingScore_Average(string method, double expected)
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), method, "127.0.0.1");
var matcher = new RequestMessageMethodMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.Average, "Get", "Post");
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
score.Should().Be(expected);
}
[Fact]
public void RequestMessageMethodMatcherTests_GetMatchingScore_And()
{
// Assign
var requestMessage = new RequestMessage(new UrlDetails("http://localhost?key=test1"), "get", "127.0.0.1");
var matcher = new RequestMessageMethodMatcher(MatchBehaviour.AcceptOnMatch, MatchOperator.And, "Get", "Post");
// Act
var result = new RequestMatchResult();
double score = matcher.GetMatchingScore(requestMessage, result);
// Assert
score.Should().Be(0d);
}
}