mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 09:18:27 +02:00
Generate C# code from Mapping (#842)
* 1 * . * v * . * . * - * b * res b * Fix UT * . * Verify * v * ... * . * . * dir * m
This commit is contained in:
@@ -5,135 +5,134 @@ using WireMock.Matchers;
|
||||
using WireMock.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Matchers
|
||||
namespace WireMock.Net.Tests.Matchers;
|
||||
|
||||
public class WildcardMatcherTest
|
||||
{
|
||||
public class WildcardMatcherTest
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPattern()
|
||||
{
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPattern()
|
||||
// Arrange
|
||||
var pattern = new StringPattern
|
||||
{
|
||||
// Arrange
|
||||
var pattern = new StringPattern
|
||||
{
|
||||
Pattern = "*",
|
||||
PatternAsFile = "pf"
|
||||
};
|
||||
Pattern = "*",
|
||||
PatternAsFile = "pf"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(pattern);
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(pattern);
|
||||
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_With_StringPatterns()
|
||||
{
|
||||
// Arrange
|
||||
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
||||
{
|
||||
// Arrange
|
||||
AnyOf<string, StringPattern> pattern1 = new StringPattern
|
||||
{
|
||||
Pattern = "a"
|
||||
};
|
||||
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
||||
{
|
||||
Pattern = "b"
|
||||
};
|
||||
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
||||
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Positive()
|
||||
Pattern = "a"
|
||||
};
|
||||
AnyOf<string, StringPattern> pattern2 = new StringPattern
|
||||
{
|
||||
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" }
|
||||
};
|
||||
Pattern = "b"
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||
}
|
||||
}
|
||||
// Act
|
||||
var matcher = new WildcardMatcher(new [] { pattern1, pattern2 });
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Negative()
|
||||
// Assert
|
||||
matcher.IsMatch("a").Should().Be(1.0d);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Positive()
|
||||
{
|
||||
var tests = new[]
|
||||
{
|
||||
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 = "*", 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(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetName()
|
||||
foreach (var test in tests)
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("WildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("m");
|
||||
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
matcher.IsMatch(test.i).Should().Be(1.0d, $"Pattern '{test.p}' with value '{test.i}' should be 1.0");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_Negative()
|
||||
{
|
||||
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" }
|
||||
};
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
var matcher = new WildcardMatcher(test.p);
|
||||
Check.That(matcher.IsMatch(test.i)).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetName()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
string name = matcher.Name;
|
||||
|
||||
// Assert
|
||||
Check.That(name).Equals("WildcardMatcher");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_GetPatterns()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher("x");
|
||||
|
||||
// Act
|
||||
var patterns = matcher.GetPatterns();
|
||||
|
||||
// Assert
|
||||
Check.That(patterns).ContainsExactly(new AnyOf<string, StringPattern>("x"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WildcardMatcher_IsMatch_RejectOnMatch()
|
||||
{
|
||||
// Assign
|
||||
var matcher = new WildcardMatcher(MatchBehaviour.RejectOnMatch, "m");
|
||||
|
||||
// Act
|
||||
double result = matcher.IsMatch("m");
|
||||
|
||||
Check.That(result).IsEqualTo(0.0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user