mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-21 00:11:44 +02:00
Implement PatternAsFile for StringMatcher (#651)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new CSharpCodeMatcher("x");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using NFluent;
|
||||
using AnyOfTypes;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -49,7 +50,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new ContentTypeMatcher("x");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new ExactMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
@@ -27,7 +27,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new JmesPathMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
@@ -27,7 +27,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new JsonPathMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
@@ -103,7 +103,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new LinqMatcher("x");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new RegexMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new SimMetricsMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
@@ -1,35 +1,55 @@
|
||||
using NFluent;
|
||||
using AnyOfTypes;
|
||||
using FluentAssertions;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
{
|
||||
public class WildcardMatcherTest
|
||||
{
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringMatcher_And_StringPattern()
|
||||
{
|
||||
// Arrange
|
||||
var pattern = new StringPattern
|
||||
{
|
||||
Pattern = "*",
|
||||
PatternAsFile = "pf"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(pattern);
|
||||
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Positive()
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
new {p = "*", i = ""},
|
||||
new {p = "?", i = " "},
|
||||
new {p = "*", i = "a"},
|
||||
new {p = "*", i = "ab"},
|
||||
new {p = "?", i = "a"},
|
||||
new {p = "*?", i = "abc"},
|
||||
new {p = "?*", i = "abc"},
|
||||
new {p = "abc", i = "abc"},
|
||||
new {p = "abc*", i = "abc"},
|
||||
new {p = "abc*", i = "abcd"},
|
||||
new {p = "*abc*", i = "abc"},
|
||||
new {p = "*a*bc*", i = "abc"},
|
||||
new {p = "*a*b?", i = "aXXXbc"}
|
||||
new { p = "*", i = "" },
|
||||
new { p = "?", i = " "},
|
||||
new { p = "*", i = "a "},
|
||||
new { p = "*", i = "ab" },
|
||||
new { p = "?", i = "a" },
|
||||
new { p = "*?", i = "abc" },
|
||||
new { p = "?*", i = "abc" },
|
||||
new { p = "abc", i = "abc" },
|
||||
new { p = "abc*", i = "abc" },
|
||||
new { p = "abc*", i = "abcd" },
|
||||
new { p = "*abc*", i = "abc" },
|
||||
new { p = "*a*bc*", i = "abc" },
|
||||
new { p = "*a*b?", i = "aXXXbc" }
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
Check.That(matcher.IsMatch(test.i)).IsEqualTo(1.0d);
|
||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,17 +58,17 @@ namespace WireMock.Net.Tests.Matchers
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
new {p = "*a", i = ""},
|
||||
new {p = "a*", i = ""},
|
||||
new {p = "?", i = ""},
|
||||
new {p = "*b*", i = "a"},
|
||||
new {p = "b*a", i = "ab"},
|
||||
new {p = "??", i = "a"},
|
||||
new {p = "*?", i = ""},
|
||||
new {p = "??*", i = "a"},
|
||||
new {p = "*abc", i = "abX"},
|
||||
new {p = "*abc*", i = "Xbc"},
|
||||
new {p = "*a*bc*", i = "ac"}
|
||||
new { p = "*a", i = "" },
|
||||
new { p = "a*", i = "" },
|
||||
new { p = "?", i = "" },
|
||||
new { p = "*b*", i = "a" },
|
||||
new { p = "b*a", i = "ab" },
|
||||
new { p = "??", i = "a" },
|
||||
new { p = "*?", i = "" },
|
||||
new { p = "??*", i = "a" },
|
||||
new { p = "*abc", i = "abX" },
|
||||
new { p = "*abc*", i = "Xbc" },
|
||||
new { p = "*a*bc*", i = "ac" }
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
@@ -78,10 +98,10 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("x");
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using WireMock.Matchers;
|
||||
using Xunit;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace WireMock.Net.Tests.Matchers
|
||||
var matcher = new XPathMatcher("X");
|
||||
|
||||
// Act
|
||||
string[] patterns = matcher.GetPatterns();
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly("X");
|
||||
|
||||
Reference in New Issue
Block a user