mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-06-06 23:12:46 +02:00
Fixed Issue #1
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
|
||||||
|
|
||||||
namespace WireMock.Net.ConsoleApplication
|
namespace WireMock.Net.ConsoleApplication
|
||||||
{
|
{
|
||||||
@@ -16,12 +19,12 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
|
|
||||||
server
|
server
|
||||||
.Given(
|
.Given(
|
||||||
Requests
|
RequestBuilder
|
||||||
.WithUrl("/*")
|
.WithUrl("/*")
|
||||||
.UsingGet()
|
.UsingGet()
|
||||||
)
|
)
|
||||||
.RespondWith(
|
.RespondWith(
|
||||||
Responses
|
ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithBody(@"{ ""msg"": ""Hello world!""}")
|
.WithBody(@"{ ""msg"": ""Hello world!""}")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -26,7 +27,7 @@ namespace WireMock
|
|||||||
/// The listener request.
|
/// The listener request.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="Request"/>.
|
/// The <see cref="RequestBuilder"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public Request Map(HttpListenerRequest listenerRequest)
|
public Request Map(HttpListenerRequest listenerRequest)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||||
@@ -21,6 +22,6 @@ namespace WireMock
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// The <see cref="bool"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
bool IsSatisfiedBy(Request request);
|
bool IsSatisfiedBy([NotNull] Request request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace WireMock
|
|||||||
}
|
}
|
||||||
|
|
||||||
Path = path;
|
Path = path;
|
||||||
Headers = headers.ToDictionary(kv => kv.Key.ToLower(), kv => kv.Value.ToLower());
|
Headers = headers; //.ToDictionary(kv => kv.Key.ToLower(), kv => kv.Value.ToLower());
|
||||||
Verb = verb.ToLower();
|
Verb = verb.ToLower();
|
||||||
Body = body?.Trim() ?? string.Empty;
|
Body = body?.Trim() ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using WireMock.Validation;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -22,19 +25,20 @@ namespace WireMock
|
|||||||
public class RequestBodySpec : ISpecifyRequests
|
public class RequestBodySpec : ISpecifyRequests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _body.
|
/// The bodyRegex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _body;
|
private readonly Regex bodyRegex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
|
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="body">
|
/// <param name="body">
|
||||||
/// The body.
|
/// The body Regex pattern.
|
||||||
/// </param>
|
/// </param>
|
||||||
public RequestBodySpec(string body)
|
public RequestBodySpec([NotNull, RegexPattern] string body)
|
||||||
{
|
{
|
||||||
_body = body.Trim();
|
Check.NotNull(body, nameof(body));
|
||||||
|
bodyRegex = new Regex(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,7 +52,7 @@ namespace WireMock
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy(Request request)
|
||||||
{
|
{
|
||||||
return WildcardPatternMatcher.MatchWildcardString(_body, request.Body.Trim());
|
return bodyRegex.IsMatch(request.Body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The BodyRequestBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IBodyRequestBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="body">
|
||||||
|
/// The body.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="ISpecifyRequests"/>.
|
||||||
|
/// </returns>
|
||||||
|
ISpecifyRequests WithBody(string body);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The HeadersRequestBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IHeadersRequestBuilder : IBodyRequestBuilder, ISpecifyRequests, IParamsRequestBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">
|
||||||
|
/// The name.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="value">
|
||||||
|
/// The value.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="ignoreCase">ignore Case</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder WithHeader(string name, string value, bool ignoreCase = true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The ParametersRequestBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IParamsRequestBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with parameters.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">
|
||||||
|
/// The key.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="values">
|
||||||
|
/// The values.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="ISpecifyRequests"/>.
|
||||||
|
/// </returns>
|
||||||
|
ISpecifyRequests WithParam(string key, params string[] values);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
namespace WireMock.RequestBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The VerbRequestBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IVerbRequestBuilder : ISpecifyRequests, IHeadersRequestBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The using get.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingGet();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using post.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingPost();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using put.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingPut();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using head.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingHead();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using any verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingAnyVerb();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The using verb.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="verb">
|
||||||
|
/// The verb.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersRequestBuilder UsingVerb(string verb);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,12 +20,12 @@ using System.Linq;
|
|||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||||
// ReSharper disable ArrangeThisQualifier
|
// ReSharper disable ArrangeThisQualifier
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
namespace WireMock
|
namespace WireMock.RequestBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The requests.
|
/// The requests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Requests : CompositeRequestSpec, IVerbRequestBuilder, IHeadersRequestBuilder, IParamsRequestBuilder
|
public class RequestBuilder : CompositeRequestSpec, IVerbRequestBuilder, IHeadersRequestBuilder, IParamsRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _request specs.
|
/// The _request specs.
|
||||||
@@ -33,12 +33,12 @@ namespace WireMock
|
|||||||
private readonly IList<ISpecifyRequests> _requestSpecs;
|
private readonly IList<ISpecifyRequests> _requestSpecs;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Requests"/> class.
|
/// Initializes a new instance of the <see cref="RequestBuilder"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestSpecs">
|
/// <param name="requestSpecs">
|
||||||
/// The request specs.
|
/// The request specs.
|
||||||
/// </param>
|
/// </param>
|
||||||
private Requests(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
|
private RequestBuilder(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
|
||||||
{
|
{
|
||||||
_requestSpecs = requestSpecs;
|
_requestSpecs = requestSpecs;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,7 @@ namespace WireMock
|
|||||||
public static IVerbRequestBuilder WithUrl(string url)
|
public static IVerbRequestBuilder WithUrl(string url)
|
||||||
{
|
{
|
||||||
var specs = new List<ISpecifyRequests>();
|
var specs = new List<ISpecifyRequests>();
|
||||||
var requests = new Requests(specs);
|
var requests = new RequestBuilder(specs);
|
||||||
specs.Add(new RequestUrlSpec(url));
|
specs.Add(new RequestUrlSpec(url));
|
||||||
return requests;
|
return requests;
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ namespace WireMock
|
|||||||
public static IVerbRequestBuilder WithPath(string path)
|
public static IVerbRequestBuilder WithPath(string path)
|
||||||
{
|
{
|
||||||
var specs = new List<ISpecifyRequests>();
|
var specs = new List<ISpecifyRequests>();
|
||||||
var requests = new Requests(specs);
|
var requests = new RequestBuilder(specs);
|
||||||
specs.Add(new RequestPathSpec(path));
|
specs.Add(new RequestPathSpec(path));
|
||||||
return requests;
|
return requests;
|
||||||
}
|
}
|
||||||
@@ -188,17 +188,18 @@ namespace WireMock
|
|||||||
/// The with header.
|
/// The with header.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">
|
/// <param name="name">
|
||||||
/// The name.
|
/// The name.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="value">
|
/// <param name="value">
|
||||||
/// The value.
|
/// The value.
|
||||||
/// </param>
|
/// </param>
|
||||||
|
/// <param name="ignoreCase">ignore Case</param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
/// The <see cref="IHeadersRequestBuilder"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public IHeadersRequestBuilder WithHeader(string name, string value)
|
public IHeadersRequestBuilder WithHeader(string name, string value, bool ignoreCase = true)
|
||||||
{
|
{
|
||||||
_requestSpecs.Add(new RequestHeaderSpec(name, value));
|
_requestSpecs.Add(new RequestHeaderSpec(name, value, ignoreCase));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -22,14 +24,14 @@ namespace WireMock
|
|||||||
public class RequestHeaderSpec : ISpecifyRequests
|
public class RequestHeaderSpec : ISpecifyRequests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _name.
|
/// The name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _name;
|
private readonly string name;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _pattern.
|
/// The patternRegex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _pattern;
|
private readonly Regex patternRegex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
|
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
|
||||||
@@ -40,10 +42,11 @@ namespace WireMock
|
|||||||
/// <param name="pattern">
|
/// <param name="pattern">
|
||||||
/// The pattern.
|
/// The pattern.
|
||||||
/// </param>
|
/// </param>
|
||||||
public RequestHeaderSpec(string name, string pattern)
|
/// <param name="ignoreCase">The ignoreCase.</param>
|
||||||
|
public RequestHeaderSpec([NotNull] string name, [NotNull, RegexPattern] string pattern, bool ignoreCase = true)
|
||||||
{
|
{
|
||||||
_name = name.ToLower();
|
this.name = name;
|
||||||
_pattern = pattern.ToLower();
|
patternRegex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -55,10 +58,10 @@ namespace WireMock
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// The <see cref="bool"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy([NotNull] Request request)
|
||||||
{
|
{
|
||||||
string headerValue = request.Headers[_name];
|
string headerValue = request.Headers[name];
|
||||||
return WildcardPatternMatcher.MatchWildcardString(_pattern, headerValue);
|
return patternRegex.IsMatch(headerValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -57,7 +58,7 @@ namespace WireMock
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// The <see cref="bool"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy([NotNull] Request request)
|
||||||
{
|
{
|
||||||
return request.GetParameter(_key).Intersect(_values).Count() == _values.Count;
|
return request.GetParameter(_key).Intersect(_values).Count() == _values.Count;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using WireMock.Validation;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -24,17 +27,18 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _path.
|
/// The _path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _path;
|
private readonly Regex _path;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
|
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">
|
/// <param name="path">
|
||||||
/// The path.
|
/// The path Regex pattern.
|
||||||
/// </param>
|
/// </param>
|
||||||
public RequestPathSpec(string path)
|
public RequestPathSpec([NotNull, RegexPattern] string path)
|
||||||
{
|
{
|
||||||
_path = path;
|
Check.NotNull(path, nameof(path));
|
||||||
|
_path = new Regex(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -46,9 +50,9 @@ namespace WireMock
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// The <see cref="bool"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy([NotNull] Request request)
|
||||||
{
|
{
|
||||||
return WildcardPatternMatcher.MatchWildcardString(_path, request.Path);
|
return _path.IsMatch(request.Path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1633:FileMustHaveHeader",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
|
||||||
|
|
||||||
namespace WireMock
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The VerbRequestBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IVerbRequestBuilder : ISpecifyRequests, IHeadersRequestBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The using get.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingGet();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The using post.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingPost();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The using put.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingPut();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The using head.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingHead();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The using any verb.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingAnyVerb();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The using verb.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="verb">
|
|
||||||
/// The verb.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder UsingVerb(string verb);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The HeadersRequestBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IHeadersRequestBuilder : IBodyRequestBuilder, ISpecifyRequests, IParamsRequestBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The with header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">
|
|
||||||
/// The name.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="value">
|
|
||||||
/// The value.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersRequestBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersRequestBuilder WithHeader(string name, string value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The BodyRequestBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IBodyRequestBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The with body.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="body">
|
|
||||||
/// The body.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="ISpecifyRequests"/>.
|
|
||||||
/// </returns>
|
|
||||||
ISpecifyRequests WithBody(string body);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The ParametersRequestBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IParamsRequestBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The with parameters.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="key">
|
|
||||||
/// The key.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="values">
|
|
||||||
/// The values.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="ISpecifyRequests"/>.
|
|
||||||
/// </returns>
|
|
||||||
ISpecifyRequests WithParam(string key, params string[] values);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using WireMock.Validation;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -22,19 +25,20 @@ namespace WireMock
|
|||||||
public class RequestUrlSpec : ISpecifyRequests
|
public class RequestUrlSpec : ISpecifyRequests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _url.
|
/// The urlRegex.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _url;
|
private readonly Regex urlRegex;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
|
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url">
|
/// <param name="url">
|
||||||
/// The url.
|
/// The url Regex pattern.
|
||||||
/// </param>
|
/// </param>
|
||||||
public RequestUrlSpec(string url)
|
public RequestUrlSpec([NotNull, RegexPattern] string url)
|
||||||
{
|
{
|
||||||
_url = url;
|
Check.NotNull(url, nameof(url));
|
||||||
|
urlRegex = new Regex(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -48,7 +52,7 @@ namespace WireMock
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy(Request request)
|
||||||
{
|
{
|
||||||
return WildcardPatternMatcher.MatchWildcardString(_url, request.Url);
|
return urlRegex.IsMatch(request.Url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -46,7 +47,7 @@ namespace WireMock
|
|||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// The <see cref="bool"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsSatisfiedBy(Request request)
|
public bool IsSatisfiedBy([NotNull] Request request)
|
||||||
{
|
{
|
||||||
return request.Verb == _verb;
|
return request.Verb == _verb;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1633:FileMustHaveHeader",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
|
||||||
|
|
||||||
namespace WireMock
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The HeadersResponseBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IHeadersResponseBuilder : IBodyResponseBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The with header.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">
|
|
||||||
/// The name.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="value">
|
|
||||||
/// The value.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IHeadersResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IHeadersResponseBuilder WithHeader(string name, string value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The BodyResponseBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IBodyResponseBuilder : IDelayResponseBuilder
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The with body.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="body">
|
|
||||||
/// The body.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IDelayResponseBuilder"/>.
|
|
||||||
/// </returns>
|
|
||||||
IDelayResponseBuilder WithBody(string body);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The DelayResponseBuilder interface.
|
|
||||||
/// </summary>
|
|
||||||
public interface IDelayResponseBuilder : IProvideResponses
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The after delay.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="delay">
|
|
||||||
/// The delay.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="IProvideResponses"/>.
|
|
||||||
/// </returns>
|
|
||||||
IProvideResponses AfterDelay(TimeSpan delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace WireMock.ResponseBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The BodyResponseBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IBodyResponseBuilder : IDelayResponseBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with body.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="body">
|
||||||
|
/// The body.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IDelayResponseBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IDelayResponseBuilder WithBody(string body);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace WireMock.ResponseBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The DelayResponseBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IDelayResponseBuilder : IProvideResponses
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The after delay.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="delay">
|
||||||
|
/// The delay.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IProvideResponses"/>.
|
||||||
|
/// </returns>
|
||||||
|
IProvideResponses AfterDelay(TimeSpan delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
namespace WireMock.ResponseBuilders
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The HeadersResponseBuilder interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IHeadersResponseBuilder : IBodyResponseBuilder
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The with header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">
|
||||||
|
/// The name.
|
||||||
|
/// </param>
|
||||||
|
/// <param name="value">
|
||||||
|
/// The value.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The <see cref="IHeadersResponseBuilder"/>.
|
||||||
|
/// </returns>
|
||||||
|
IHeadersResponseBuilder WithHeader(string name, string value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,12 +16,12 @@ using System.Threading.Tasks;
|
|||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||||
// ReSharper disable ArrangeThisQualifier
|
// ReSharper disable ArrangeThisQualifier
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
namespace WireMock
|
namespace WireMock.ResponseBuilders
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The responses.
|
/// The responses.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Responses : IHeadersResponseBuilder
|
public class ResponseBuilder : IHeadersResponseBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _response.
|
/// The _response.
|
||||||
@@ -34,12 +34,12 @@ namespace WireMock
|
|||||||
private TimeSpan _delay = TimeSpan.Zero;
|
private TimeSpan _delay = TimeSpan.Zero;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Responses"/> class.
|
/// Initializes a new instance of the <see cref="ResponseBuilder"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="response">
|
/// <param name="response">
|
||||||
/// The response.
|
/// The response.
|
||||||
/// </param>
|
/// </param>
|
||||||
public Responses(Response response)
|
public ResponseBuilder(Response response)
|
||||||
{
|
{
|
||||||
_response = response;
|
_response = response;
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ namespace WireMock
|
|||||||
public static IHeadersResponseBuilder WithStatusCode(int code)
|
public static IHeadersResponseBuilder WithStatusCode(int code)
|
||||||
{
|
{
|
||||||
var response = new Response { StatusCode = code };
|
var response = new Response { StatusCode = code };
|
||||||
return new Responses(response);
|
return new ResponseBuilder(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
// Copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Shared/Check.cs
|
||||||
|
namespace WireMock.Validation
|
||||||
|
{
|
||||||
|
[DebuggerStepThrough]
|
||||||
|
internal static class Check
|
||||||
|
{
|
||||||
|
[ContractAnnotation("value:null => halt")]
|
||||||
|
public static T Condition<T>([NoEnumeration] T value, [NotNull] Predicate<T> condition, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
NotNull(condition, nameof(condition));
|
||||||
|
NotNull(value, nameof(value));
|
||||||
|
|
||||||
|
if (!condition(value))
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentOutOfRangeException(parameterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ContractAnnotation("value:null => halt")]
|
||||||
|
public static T NotNull<T>([NoEnumeration] T value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(value, null))
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentNullException(parameterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ContractAnnotation("value:null => halt")]
|
||||||
|
public static T NotNull<T>(
|
||||||
|
[NoEnumeration] T value,
|
||||||
|
[InvokerParameterName] [NotNull] string parameterName,
|
||||||
|
[NotNull] string propertyName)
|
||||||
|
{
|
||||||
|
if (ReferenceEquals(value, null))
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
NotEmpty(propertyName, nameof(propertyName));
|
||||||
|
|
||||||
|
throw new ArgumentException(CoreStrings.ArgumentPropertyNull(propertyName, parameterName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ContractAnnotation("value:null => halt")]
|
||||||
|
public static IList<T> NotEmpty<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
NotNull(value, parameterName);
|
||||||
|
|
||||||
|
if (value.Count == 0)
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentException(CoreStrings.CollectionArgumentIsEmpty(parameterName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[ContractAnnotation("value:null => halt")]
|
||||||
|
public static string NotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
Exception e = null;
|
||||||
|
if (ReferenceEquals(value, null))
|
||||||
|
{
|
||||||
|
e = new ArgumentNullException(parameterName);
|
||||||
|
}
|
||||||
|
else if (value.Trim().Length == 0)
|
||||||
|
{
|
||||||
|
e = new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e != null)
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string NullButNotEmpty(string value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
if (!ReferenceEquals(value, null)
|
||||||
|
&& (value.Length == 0))
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentException(CoreStrings.ArgumentIsEmpty(parameterName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IList<T> HasNoNulls<T>(IList<T> value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
where T : class
|
||||||
|
{
|
||||||
|
NotNull(value, parameterName);
|
||||||
|
|
||||||
|
if (value.Any(e => e == null))
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentException(parameterName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type ValidEntityType(Type value, [InvokerParameterName] [NotNull] string parameterName)
|
||||||
|
{
|
||||||
|
if (!value.GetTypeInfo().IsClass)
|
||||||
|
{
|
||||||
|
NotEmpty(parameterName, nameof(parameterName));
|
||||||
|
|
||||||
|
throw new ArgumentException(CoreStrings.InvalidEntityType(value, parameterName));
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
|
// copied from https://github.com/aspnet/EntityFramework/blob/dev/src/Microsoft.EntityFrameworkCore/Properties/CoreStrings.resx
|
||||||
|
namespace WireMock.Validation
|
||||||
|
{
|
||||||
|
internal static class CoreStrings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The property '{property}' of the argument '{argument}' cannot be null.
|
||||||
|
/// </summary>
|
||||||
|
public static string ArgumentPropertyNull([CanBeNull] string property, [CanBeNull] string argument)
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.CurrentCulture, $"The property '{property}' of the argument '{argument}' cannot be null.", property, argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The string argument '{argumentName}' cannot be empty.
|
||||||
|
/// </summary>
|
||||||
|
public static string ArgumentIsEmpty([CanBeNull] string argumentName)
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.CurrentCulture, $"The string argument '{argumentName}' cannot be empty.", argumentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.
|
||||||
|
/// </summary>
|
||||||
|
public static string InvalidEntityType([CanBeNull] Type type, [CanBeNull] string argumentName)
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.CurrentCulture, $"The entity type '{type}' provided for the argument '{argumentName}' must be a reference type.", type, argumentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The collection argument '{argumentName}' must contain at least one element.
|
||||||
|
/// </summary>
|
||||||
|
public static string CollectionArgumentIsEmpty([CanBeNull] string argumentName)
|
||||||
|
{
|
||||||
|
return string.Format(CultureInfo.CurrentCulture, $"The collection argument '{argumentName}' must contain at least one element.", argumentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1633:FileMustHaveHeader",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1650:ElementDocumentationMustBeSpelledCorrectly",
|
|
||||||
Justification = "Reviewed. Suppression is OK here.")]
|
|
||||||
|
|
||||||
namespace WireMock
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The wildcard pattern matcher.
|
|
||||||
/// </summary>
|
|
||||||
public static class WildcardPatternMatcher
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The match wildcard string.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="pattern">
|
|
||||||
/// The pattern.
|
|
||||||
/// </param>
|
|
||||||
/// <param name="input">
|
|
||||||
/// The input.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="bool"/>.
|
|
||||||
/// </returns>
|
|
||||||
/// <remarks>
|
|
||||||
/// Copy/paste from http://www.codeproject.com/Tips/57304/Use-wildcard-characters-and-to-compare-strings
|
|
||||||
/// </remarks>
|
|
||||||
public static bool MatchWildcardString(string pattern, string input)
|
|
||||||
{
|
|
||||||
if (string.CompareOrdinal(pattern, input) == 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(input))
|
|
||||||
{
|
|
||||||
return string.IsNullOrEmpty(pattern.Trim('*'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern.Length == 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern[0] == '?')
|
|
||||||
{
|
|
||||||
return MatchWildcardString(pattern.Substring(1), input.Substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern[pattern.Length - 1] == '?')
|
|
||||||
{
|
|
||||||
return MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input.Substring(0, input.Length - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern[0] == '*')
|
|
||||||
{
|
|
||||||
return MatchWildcardString(pattern.Substring(1), input) || MatchWildcardString(pattern, input.Substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pattern[pattern.Length - 1] == '*')
|
|
||||||
{
|
|
||||||
return MatchWildcardString(pattern.Substring(0, pattern.Length - 1), input) || MatchWildcardString(pattern, input.Substring(0, input.Length - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return pattern[0] == input[0] && MatchWildcardString(pattern.Substring(1), input.Substring(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,8 @@ using System.Net.Http;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
using WireMock.ResponseBuilders;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
@@ -41,10 +43,10 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
@@ -98,7 +100,7 @@ namespace WireMock.Net.Tests
|
|||||||
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
|
await new HttpClient().GetAsync("http://localhost:" + _server.Port + "/bar");
|
||||||
|
|
||||||
// then
|
// then
|
||||||
var result = _server.SearchLogsFor(Requests.WithUrl("/b*"));
|
var result = _server.SearchLogsFor(RequestBuilder.WithUrl("/b.*"));
|
||||||
Check.That(result).HasSize(1);
|
Check.That(result).HasSize(1);
|
||||||
var requestLogged = result.First();
|
var requestLogged = result.First();
|
||||||
Check.That(requestLogged.Url).IsEqualTo("/bar");
|
Check.That(requestLogged.Url).IsEqualTo("/bar");
|
||||||
@@ -125,10 +127,10 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
@@ -147,17 +149,17 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/foo")
|
.WithUrl("/foo")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(307)
|
.WithStatusCode(307)
|
||||||
.WithHeader("Location", "/bar"));
|
.WithHeader("Location", "/bar"));
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/bar")
|
.WithUrl("/bar")
|
||||||
.UsingGet())
|
.UsingGet())
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody("REDIRECT SUCCESSFUL"));
|
.WithBody("REDIRECT SUCCESSFUL"));
|
||||||
|
|
||||||
@@ -176,9 +178,9 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
|
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/*"))
|
.WithUrl("/*"))
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody(@"{ msg: ""Hello world!""}")
|
.WithBody(@"{ msg: ""Hello world!""}")
|
||||||
.AfterDelay(TimeSpan.FromMilliseconds(2000)));
|
.AfterDelay(TimeSpan.FromMilliseconds(2000)));
|
||||||
@@ -200,9 +202,9 @@ namespace WireMock.Net.Tests
|
|||||||
_server = FluentMockServer.Start();
|
_server = FluentMockServer.Start();
|
||||||
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
|
_server.AddRequestProcessingDelay(TimeSpan.FromMilliseconds(2000));
|
||||||
_server
|
_server
|
||||||
.Given(Requests
|
.Given(RequestBuilder
|
||||||
.WithUrl("/*"))
|
.WithUrl("/*"))
|
||||||
.RespondWith(Responses
|
.RespondWith(ResponseBuilder
|
||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithBody(@"{ msg: ""Hello world!""}"));
|
.WithBody(@"{ msg: ""Hello world!""}"));
|
||||||
|
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ namespace WireMock.Net.Tests
|
|||||||
// then
|
// then
|
||||||
Check.That(MapperServer.LastRequest).IsNotNull();
|
Check.That(MapperServer.LastRequest).IsNotNull();
|
||||||
Check.That(MapperServer.LastRequest.Headers).Not.IsNullOrEmpty();
|
Check.That(MapperServer.LastRequest.Headers).Not.IsNullOrEmpty();
|
||||||
Check.That(MapperServer.LastRequest.Headers.Contains(new KeyValuePair<string, string>("x-alex", "1706"))).IsTrue();
|
Check.That(MapperServer.LastRequest.Headers.Contains(new KeyValuePair<string, string>("X-Alex", "1706"))).IsTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -141,7 +141,7 @@ namespace WireMock.Net.Tests
|
|||||||
|
|
||||||
public static string UrlPrefix { get; private set; }
|
public static string UrlPrefix { get; private set; }
|
||||||
|
|
||||||
public static new MapperServer Start()
|
public new static MapperServer Start()
|
||||||
{
|
{
|
||||||
var port = Ports.FindFreeTcpPort();
|
var port = Ports.FindFreeTcpPort();
|
||||||
UrlPrefix = "http://localhost:" + port + "/";
|
UrlPrefix = "http://localhost:" + port + "/";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using WireMock.RequestBuilders;
|
||||||
|
|
||||||
[module:
|
[module:
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||||
@@ -21,7 +22,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url()
|
public void Should_specify_requests_matching_given_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo");
|
var spec = RequestBuilder.WithUrl("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||||
@@ -34,7 +35,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_prefix()
|
public void Should_specify_requests_matching_given_url_prefix()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo*");
|
var spec = RequestBuilder.WithUrl("/foo*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||||
@@ -47,7 +48,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_url()
|
public void Should_exclude_requests_not_matching_given_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo");
|
var spec = RequestBuilder.WithUrl("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
var request = new Request("/bar", string.Empty, "blabla", "whatever", new Dictionary<string, string>());
|
||||||
@@ -60,7 +61,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_path()
|
public void Should_specify_requests_matching_given_path()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithPath("/foo");
|
var spec = RequestBuilder.WithPath("/foo");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", "?param=1", "blabla", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo", "?param=1", "blabla", "whatever", new Dictionary<string, string>());
|
||||||
@@ -73,7 +74,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_method()
|
public void Should_specify_requests_matching_given_url_and_method()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingPut();
|
var spec = RequestBuilder.WithUrl("/foo").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
||||||
@@ -86,7 +87,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
public void Should_exclude_requests_matching_given_url_but_not_http_method()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingPut();
|
var spec = RequestBuilder.WithUrl("/foo").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo", string.Empty, "POST", "whatever", new Dictionary<string, string>());
|
||||||
@@ -99,7 +100,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
public void Should_exclude_requests_matching_given_http_method_but_not_url()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/bar").UsingPut();
|
var spec = RequestBuilder.WithUrl("/bar").UsingPut();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string>());
|
||||||
@@ -112,7 +113,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_url_and_headers()
|
public void Should_specify_requests_matching_given_url_and_headers()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
||||||
@@ -125,7 +126,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_headers()
|
public void Should_exclude_requests_not_matching_given_headers()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tatata");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tata" } });
|
||||||
@@ -134,14 +135,27 @@ namespace WireMock.Net.Tests
|
|||||||
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
|
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Should_exclude_requests_not_matching_given_headers_ignorecase()
|
||||||
|
{
|
||||||
|
// given
|
||||||
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "abc", false);
|
||||||
|
|
||||||
|
// when
|
||||||
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "ABC" } });
|
||||||
|
|
||||||
|
// then
|
||||||
|
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Should_specify_requests_matching_given_header_prefix()
|
public void Should_specify_requests_matching_given_header_prefix()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithHeader("X-toto", "tata*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "whatever", new Dictionary<string, string> { { "X-toto", "TaTaTa" } });
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
|
||||||
@@ -151,7 +165,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body()
|
public void Should_specify_requests_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody(".*Hello world!.*");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||||
@@ -164,7 +178,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_body_as_wildcard()
|
public void Should_specify_requests_matching_given_body_as_wildcard()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody("H*o wor?d!");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody("H.*o");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "Hello world!", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||||
@@ -177,7 +191,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_body()
|
public void Should_exclude_requests_not_matching_given_body()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
var spec = RequestBuilder.WithUrl("/foo").UsingAnyVerb().WithBody(" Hello world! ");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string> { { "X-toto", "tatata" } });
|
||||||
@@ -190,7 +204,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_specify_requests_matching_given_params()
|
public void Should_specify_requests_matching_given_params()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithPath("/foo").WithParam("bar", "1", "2");
|
var spec = RequestBuilder.WithPath("/foo").WithParam("bar", "1", "2");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
|
var request = new Request("/foo", "bar=1&bar=2", "Get", "Hello world!", new Dictionary<string, string>());
|
||||||
@@ -203,7 +217,7 @@ namespace WireMock.Net.Tests
|
|||||||
public void Should_exclude_requests_not_matching_given_params()
|
public void Should_exclude_requests_not_matching_given_params()
|
||||||
{
|
{
|
||||||
// given
|
// given
|
||||||
var spec = Requests.WithPath("/foo").WithParam("bar", "1");
|
var spec = RequestBuilder.WithPath("/foo").WithParam("bar", "1");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string>());
|
var request = new Request("/foo", string.Empty, "PUT", "XXXXXXXXXXX", new Dictionary<string, string>());
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using NFluent;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1600:ElementsMustBeDocumented",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
|
||||||
[module:
|
|
||||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
|
||||||
"SA1633:FileMustHaveHeader",
|
|
||||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
|
||||||
// ReSharper disable InconsistentNaming
|
|
||||||
namespace WireMock.Net.Tests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class WildcardPatternMatcherTests
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void Should_evaluate_patterns()
|
|
||||||
{
|
|
||||||
// Positive Tests
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", string.Empty)).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", " ")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "a")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*", "ab")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", "a")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", "abc")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?*", "abc")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abc")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "abc")).IsTrue();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "aXXXbc")).IsTrue();
|
|
||||||
|
|
||||||
// Negative Tests
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a", string.Empty)).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("a*", string.Empty)).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("?", string.Empty)).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*b*", "a")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("b*a", "ab")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("??", "a")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*?", string.Empty)).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("??*", "a")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc", "abX")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*abc*", "Xbc")).IsFalse();
|
|
||||||
Check.That(WildcardPatternMatcher.MatchWildcardString("*a*bc*", "ac")).IsFalse();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -66,7 +66,6 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RequestsTests.cs" />
|
<Compile Include="RequestsTests.cs" />
|
||||||
<Compile Include="RequestTests.cs" />
|
<Compile Include="RequestTests.cs" />
|
||||||
<Compile Include="WildcardPatternMatcherTests.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|||||||
Reference in New Issue
Block a user