mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:50:36 +01:00
Implement PatternAsFile for StringMatcher (#651)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
using AnyOfTypes;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
@@ -60,7 +62,7 @@ namespace WireMock.Net.Tests.Serialization
|
||||
// Assign
|
||||
var matcherMock = new Mock<IStringMatcher>();
|
||||
matcherMock.Setup(m => m.Name).Returns("test");
|
||||
matcherMock.Setup(m => m.GetPatterns()).Returns(new[] { "p1", "p2" });
|
||||
matcherMock.Setup(m => m.GetPatterns()).Returns(new AnyOf<string, StringPattern>[] { "p1", "p2" });
|
||||
|
||||
// Act
|
||||
var model = _sut.Map(matcherMock.Object);
|
||||
@@ -69,7 +71,30 @@ namespace WireMock.Net.Tests.Serialization
|
||||
model.IgnoreCase.Should().BeNull();
|
||||
model.Name.Should().Be("test");
|
||||
model.Pattern.Should().BeNull();
|
||||
model.Patterns.Should().Contain("p1", "p2");
|
||||
model.Patterns.Should().HaveCount(2)
|
||||
.And.Contain("p1")
|
||||
.And.Contain("p2");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_IStringMatcher_With_PatternAsFile()
|
||||
{
|
||||
// Arrange
|
||||
var pattern = new StringPattern { Pattern = "p", PatternAsFile = "pf" };
|
||||
|
||||
var matcherMock = new Mock<IStringMatcher>();
|
||||
matcherMock.Setup(m => m.Name).Returns("test");
|
||||
matcherMock.Setup(m => m.GetPatterns()).Returns(new AnyOf<string, StringPattern>[] { pattern });
|
||||
|
||||
// Act
|
||||
var model = _sut.Map(matcherMock.Object);
|
||||
|
||||
// Assert
|
||||
model.IgnoreCase.Should().BeNull();
|
||||
model.Name.Should().Be("test");
|
||||
model.Pattern.Should().Be("p");
|
||||
model.Patterns.Should().BeNull();
|
||||
model.PatternAsFile.Should().Be("pf");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -301,5 +326,24 @@ namespace WireMock.Net.Tests.Serialization
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
matcher.Value.Should().BeEquivalentTo(patterns);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_JsonPartialMatcher_StringPattern_With_PatternAsFile()
|
||||
{
|
||||
// Assign
|
||||
var pattern = new StringPattern { Pattern = "{ \"AccountIds\": [ 1, 2, 3 ] }", PatternAsFile = "pf" };
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "JsonPartialMatcher",
|
||||
Pattern = pattern
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = (JsonPartialMatcher)_sut.Map(model);
|
||||
|
||||
// Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
matcher.Value.Should().BeEquivalentTo(pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using AnyOfTypes;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NFluent;
|
||||
using WireMock.Admin.Mappings;
|
||||
using WireMock.Handlers;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using WireMock.Serialization;
|
||||
using WireMock.Settings;
|
||||
using Xunit;
|
||||
@@ -193,7 +197,7 @@ namespace WireMock.Net.Tests.Serialization
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherModelMapper_Map_WildcardMatcher()
|
||||
public void MatcherModelMapper_Map_WildcardMatcher_IgnoreCase()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel
|
||||
@@ -211,6 +215,40 @@ namespace WireMock.Net.Tests.Serialization
|
||||
Check.That(matcher.IsMatch("X")).IsEqualTo(0.5d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherModelMapper_Map_WildcardMatcher_With_PatternAsFile()
|
||||
{
|
||||
// Arrange
|
||||
var file = "c:\\test.txt";
|
||||
var fileContent = "c";
|
||||
var stringPattern = new StringPattern
|
||||
{
|
||||
Pattern = fileContent,
|
||||
PatternAsFile = file
|
||||
};
|
||||
var fileSystemHandleMock = new Mock<IFileSystemHandler>();
|
||||
fileSystemHandleMock.Setup(f => f.ReadFileAsString(file)).Returns(fileContent);
|
||||
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "WildcardMatcher",
|
||||
PatternAsFile = file
|
||||
};
|
||||
|
||||
var settings = new WireMockServerSettings
|
||||
{
|
||||
FileSystemHandler = fileSystemHandleMock.Object
|
||||
};
|
||||
var sut = new MatcherMapper(settings);
|
||||
|
||||
// Act
|
||||
var matcher = (WildcardMatcher)sut.Map(model);
|
||||
|
||||
// Assert
|
||||
matcher.GetPatterns().Should().HaveCount(1).And.Contain(new AnyOf<string, StringPattern>(stringPattern));
|
||||
matcher.IsMatch("c").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherModelMapper_Map_SimMetricsMatcher()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user