mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-17 06:29:57 +02:00
RejectOnMatch (wip)
This commit is contained in:
@@ -150,6 +150,14 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
.WithBody(@"{ ""result"": ""data deleted with 200""}"));
|
||||||
|
|
||||||
|
server
|
||||||
|
.Given(Request.Create()
|
||||||
|
.WithPath("/reject")
|
||||||
|
.WithHeader("x", "1", MatchBehaviour.RejectOnMatch)
|
||||||
|
.UsingAnyMethod())
|
||||||
|
.RespondWith(Response.Create()
|
||||||
|
.WithBody(@"{ ""result"": ""reject""}"));
|
||||||
|
|
||||||
server
|
server
|
||||||
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
.Given(Request.Create().WithPath("/nobody").UsingGet())
|
||||||
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
|
.RespondWith(Response.Create().WithDelay(TimeSpan.FromSeconds(1))
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ namespace WireMock.RequestBuilders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
|
public interface IHeadersAndCookiesRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// WithHeader: matching based on name, pattern and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="pattern">The pattern.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithHeader([NotNull] string name, string pattern, MatchBehaviour matchBehaviour);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithHeader: matching based on name, pattern, ignoreCase and matchBehaviour.
|
/// WithHeader: matching based on name, pattern, ignoreCase and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,6 +30,15 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder WithHeader([NotNull] string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WithHeader: matching based on name, patterns and matchBehaviour.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <param name="patterns">The patterns.</param>
|
||||||
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
|
IRequestBuilder WithHeader([NotNull] string name, string[] patterns, MatchBehaviour matchBehaviour);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WithHeader: matching based on name, patterns, ignoreCase and matchBehaviour.
|
/// WithHeader: matching based on name, patterns, ignoreCase and matchBehaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -312,6 +312,12 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string, MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder WithHeader(string name, string pattern, MatchBehaviour matchBehaviour)
|
||||||
|
{
|
||||||
|
return WithHeader(name, pattern, true, matchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string, bool, MatchBehaviour)"/>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string, bool, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
public IRequestBuilder WithHeader(string name, string pattern, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
@@ -322,6 +328,12 @@ namespace WireMock.RequestBuilders
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string[], MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder WithHeader(string name, string[] patterns, MatchBehaviour matchBehaviour)
|
||||||
|
{
|
||||||
|
return WithHeader(name, patterns, true, matchBehaviour);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string[], bool, MatchBehaviour)"/>
|
/// <inheritdoc cref="IHeadersAndCookiesRequestBuilder.WithHeader(string, string[], bool, MatchBehaviour)"/>
|
||||||
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
public IRequestBuilder WithHeader(string name, string[] patterns, bool ignoreCase = true, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,9 +22,11 @@ namespace WireMock.Serialization
|
|||||||
|
|
||||||
string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0];
|
string[] patterns = matcher is IStringMatcher stringMatcher ? stringMatcher.GetPatterns() : new string[0];
|
||||||
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
|
bool? ignorecase = matcher is IIgnoreCaseMatcher ignoreCaseMatcher ? ignoreCaseMatcher.IgnoreCase : (bool?)null;
|
||||||
|
bool? rejectOnMatch = matcher.MatchBehaviour == MatchBehaviour.RejectOnMatch ? true : (bool?) null;
|
||||||
|
|
||||||
return new MatcherModel
|
return new MatcherModel
|
||||||
{
|
{
|
||||||
|
RejectOnMatch = rejectOnMatch,
|
||||||
IgnoreCase = ignorecase,
|
IgnoreCase = ignorecase,
|
||||||
Name = matcher.Name,
|
Name = matcher.Name,
|
||||||
Pattern = patterns.Length == 1 ? patterns.First() : null,
|
Pattern = patterns.Length == 1 ? patterns.First() : null,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace WireMock.Serialization
|
|||||||
string matcherType = parts.Length > 1 ? parts[1] : null;
|
string matcherType = parts.Length > 1 ? parts[1] : null;
|
||||||
|
|
||||||
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
|
string[] patterns = matcher.Patterns ?? new[] { matcher.Pattern };
|
||||||
var matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
MatchBehaviour matchBehaviour = matcher.RejectOnMatch == true ? MatchBehaviour.RejectOnMatch : MatchBehaviour.AcceptOnMatch;
|
||||||
|
|
||||||
switch (matcherName)
|
switch (matcherName)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user