Add ThrowExceptionWhenMatcherFails option to all Matchers (#500)

* .

* ut

* IMatcher.ThrowException

* settings

* more tests

* linq matcher throw

* .

* .
This commit is contained in:
Stef Heyenrath
2020-08-13 08:58:18 +02:00
committed by GitHub
parent 0d102f3af4
commit 06be3aff95
29 changed files with 1798 additions and 1607 deletions

View File

@@ -1,4 +1,5 @@
using System;
using FluentAssertions;
using NFluent;
using WireMock.Admin.Mappings;
using WireMock.Matchers;
@@ -43,7 +44,8 @@ namespace WireMock.Net.Tests.Serialization
var matcher = (ExactMatcher)_sut.Map(model);
// Assert
Check.That(matcher.GetPatterns()).ContainsExactly("x");
matcher.GetPatterns().Should().ContainSingle("x");
matcher.ThrowException.Should().BeFalse();
}
[Fact]
@@ -63,6 +65,39 @@ namespace WireMock.Net.Tests.Serialization
Check.That(matcher.GetPatterns()).ContainsExactly("x", "y");
}
[Theory]
[InlineData(nameof(LinqMatcher))]
[InlineData(nameof(ExactMatcher))]
[InlineData(nameof(ExactObjectMatcher))]
[InlineData(nameof(RegexMatcher))]
[InlineData(nameof(JsonMatcher))]
[InlineData(nameof(JsonPathMatcher))]
[InlineData(nameof(JmesPathMatcher))]
[InlineData(nameof(XPathMatcher))]
[InlineData(nameof(WildcardMatcher))]
[InlineData(nameof(ContentTypeMatcher))]
[InlineData(nameof(SimMetricsMatcher))]
public void MatcherModelMapper_Map_ThrowExceptionWhenMatcherFails_True(string name)
{
// Assign
var settings = new WireMockServerSettings
{
ThrowExceptionWhenMatcherFails = true
};
var sut = new MatcherMapper(settings);
var model = new MatcherModel
{
Name = name,
Patterns = new[] { "" }
};
// Act
var matcher = sut.Map(model);
// Assert
matcher.ThrowException.Should().BeTrue();
}
[Fact]
public void MatcherModelMapper_Map_ExactObjectMatcher_ValidBase64StringPattern()
{