mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-22 09:30:18 +01:00
Add overloads to AtUrl and AtAbsoluteUrl which can use a IStringMatcher (#1221)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
#pragma warning disable CS1591
|
||||
using System;
|
||||
using WireMock.Extensions;
|
||||
using WireMock.Matchers;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace WireMock.FluentAssertions;
|
||||
@@ -11,7 +12,17 @@ public partial class WireMockAssertions
|
||||
[CustomAssertion]
|
||||
public AndWhichConstraint<WireMockAssertions, string> AtAbsoluteUrl(string absoluteUrl, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.AbsoluteUrl, absoluteUrl, StringComparison.OrdinalIgnoreCase));
|
||||
_ = AtAbsoluteUrl(new ExactMatcher(true, absoluteUrl), because, becauseArgs);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(this, absoluteUrl);
|
||||
}
|
||||
|
||||
[CustomAssertion]
|
||||
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtAbsoluteUrl(IStringMatcher absoluteUrlMatcher, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = BuildFilterAndCondition(request => absoluteUrlMatcher.IsPerfectMatch(request.AbsoluteUrl));
|
||||
|
||||
var absoluteUrl = absoluteUrlMatcher.GetPatterns().FirstOrDefault().GetPattern();
|
||||
|
||||
Execute.Assertion
|
||||
.BecauseOf(because, becauseArgs)
|
||||
@@ -31,13 +42,23 @@ public partial class WireMockAssertions
|
||||
|
||||
FilterRequestMessages(filter);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(this, absoluteUrl);
|
||||
return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, absoluteUrlMatcher);
|
||||
}
|
||||
|
||||
[CustomAssertion]
|
||||
public AndWhichConstraint<WireMockAssertions, string> AtUrl(string url, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = BuildFilterAndCondition(request => string.Equals(request.Url, url, StringComparison.OrdinalIgnoreCase));
|
||||
_ = AtUrl(new ExactMatcher(true, url), because, becauseArgs);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(this, url);
|
||||
}
|
||||
|
||||
[CustomAssertion]
|
||||
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtUrl(IStringMatcher urlMatcher, string because = "", params object[] becauseArgs)
|
||||
{
|
||||
var (filter, condition) = BuildFilterAndCondition(request => urlMatcher.IsPerfectMatch(request.Url));
|
||||
|
||||
var url = urlMatcher.GetPatterns().FirstOrDefault().GetPattern();
|
||||
|
||||
Execute.Assertion
|
||||
.BecauseOf(because, becauseArgs)
|
||||
@@ -57,6 +78,6 @@ public partial class WireMockAssertions
|
||||
|
||||
FilterRequestMessages(filter);
|
||||
|
||||
return new AndWhichConstraint<WireMockAssertions, string>(this, url);
|
||||
return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, urlMatcher);
|
||||
}
|
||||
}
|
||||
20
src/WireMock.Net/Matchers/MatcherExtensions.cs
Normal file
20
src/WireMock.Net/Matchers/MatcherExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
namespace WireMock.Matchers;
|
||||
|
||||
/// <summary>
|
||||
/// Provides some extension methods for matchers.
|
||||
/// </summary>
|
||||
public static class MatcherExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines if the match result is a perfect match.
|
||||
/// </summary>
|
||||
/// <param name="matcher">The string matcher.</param>
|
||||
/// <param name="input">The input string to match.</param>
|
||||
/// <returns><c>true</c>> if the match is perfect; otherwise, <c>false</c>>.</returns>
|
||||
public static bool IsPerfectMatch(this IStringMatcher matcher, string? input)
|
||||
{
|
||||
return matcher.IsMatch(input).IsPerfect();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user