Fixed Issue #1

This commit is contained in:
Stef Heyenrath
2017-01-17 23:41:58 +01:00
parent eeaeeb2c61
commit c0872995b0
29 changed files with 493 additions and 396 deletions

View File

@@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using System.Net;
using WireMock.RequestBuilders;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -26,7 +27,7 @@ namespace WireMock
/// The listener request.
/// </param>
/// <returns>
/// The <see cref="Request"/>.
/// The <see cref="RequestBuilder"/>.
/// </returns>
public Request Map(HttpListenerRequest listenerRequest)
{

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
@@ -21,6 +22,6 @@ namespace WireMock
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
bool IsSatisfiedBy(Request request);
bool IsSatisfiedBy([NotNull] Request request);
}
}

View File

@@ -75,7 +75,7 @@ namespace WireMock
}
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();
Body = body?.Trim() ?? string.Empty;
}

View File

@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -22,19 +25,20 @@ namespace WireMock
public class RequestBodySpec : ISpecifyRequests
{
/// <summary>
/// The _body.
/// The bodyRegex.
/// </summary>
private readonly string _body;
private readonly Regex bodyRegex;
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// </summary>
/// <param name="body">
/// The body.
/// The body Regex pattern.
/// </param>
public RequestBodySpec(string body)
public RequestBodySpec([NotNull, RegexPattern] string body)
{
_body = body.Trim();
Check.NotNull(body, nameof(body));
bodyRegex = new Regex(body);
}
/// <summary>
@@ -48,7 +52,7 @@ namespace WireMock
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_body, request.Body.Trim());
return bodyRegex.IsMatch(request.Body);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -20,12 +20,12 @@ using System.Linq;
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
namespace WireMock.RequestBuilders
{
/// <summary>
/// The requests.
/// </summary>
public class Requests : CompositeRequestSpec, IVerbRequestBuilder, IHeadersRequestBuilder, IParamsRequestBuilder
public class RequestBuilder : CompositeRequestSpec, IVerbRequestBuilder, IHeadersRequestBuilder, IParamsRequestBuilder
{
/// <summary>
/// The _request specs.
@@ -33,12 +33,12 @@ namespace WireMock
private readonly IList<ISpecifyRequests> _requestSpecs;
/// <summary>
/// Initializes a new instance of the <see cref="Requests"/> class.
/// Initializes a new instance of the <see cref="RequestBuilder"/> class.
/// </summary>
/// <param name="requestSpecs">
/// The request specs.
/// </param>
private Requests(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
private RequestBuilder(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
{
_requestSpecs = requestSpecs;
}
@@ -55,7 +55,7 @@ namespace WireMock
public static IVerbRequestBuilder WithUrl(string url)
{
var specs = new List<ISpecifyRequests>();
var requests = new Requests(specs);
var requests = new RequestBuilder(specs);
specs.Add(new RequestUrlSpec(url));
return requests;
}
@@ -72,7 +72,7 @@ namespace WireMock
public static IVerbRequestBuilder WithPath(string path)
{
var specs = new List<ISpecifyRequests>();
var requests = new Requests(specs);
var requests = new RequestBuilder(specs);
specs.Add(new RequestPathSpec(path));
return requests;
}
@@ -188,17 +188,18 @@ namespace WireMock
/// The with header.
/// </summary>
/// <param name="name">
/// The name.
/// The name.
/// </param>
/// <param name="value">
/// The value.
/// The value.
/// </param>
/// <param name="ignoreCase">ignore Case</param>
/// <returns>
/// The <see cref="IHeadersRequestBuilder"/>.
/// </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;
}
}

View File

@@ -1,4 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -22,14 +24,14 @@ namespace WireMock
public class RequestHeaderSpec : ISpecifyRequests
{
/// <summary>
/// The _name.
/// The name.
/// </summary>
private readonly string _name;
private readonly string name;
/// <summary>
/// The _pattern.
/// The patternRegex.
/// </summary>
private readonly string _pattern;
private readonly Regex patternRegex;
/// <summary>
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
@@ -40,10 +42,11 @@ namespace WireMock
/// <param name="pattern">
/// The pattern.
/// </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();
_pattern = pattern.ToLower();
this.name = name;
patternRegex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);
}
/// <summary>
@@ -55,10 +58,10 @@ namespace WireMock
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
public bool IsSatisfiedBy([NotNull] Request request)
{
string headerValue = request.Headers[_name];
return WildcardPatternMatcher.MatchWildcardString(_pattern, headerValue);
string headerValue = request.Headers[name];
return patternRegex.IsMatch(headerValue);
}
}
}

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -57,7 +58,7 @@ namespace WireMock
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
public bool IsSatisfiedBy([NotNull] Request request)
{
return request.GetParameter(_key).Intersect(_values).Count() == _values.Count;
}

View File

@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -24,17 +27,18 @@ namespace WireMock
/// <summary>
/// The _path.
/// </summary>
private readonly string _path;
private readonly Regex _path;
/// <summary>
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
/// </summary>
/// <param name="path">
/// The path.
/// The path Regex pattern.
/// </param>
public RequestPathSpec(string path)
public RequestPathSpec([NotNull, RegexPattern] string path)
{
_path = path;
Check.NotNull(path, nameof(path));
_path = new Regex(path);
}
/// <summary>
@@ -46,9 +50,9 @@ namespace WireMock
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
public bool IsSatisfiedBy([NotNull] Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_path, request.Path);
return _path.IsMatch(request.Path);
}
}
}

View File

@@ -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);
}
}

View File

@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using System.Text.RegularExpressions;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -22,19 +25,20 @@ namespace WireMock
public class RequestUrlSpec : ISpecifyRequests
{
/// <summary>
/// The _url.
/// The urlRegex.
/// </summary>
private readonly string _url;
private readonly Regex urlRegex;
/// <summary>
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
/// </summary>
/// <param name="url">
/// The url.
/// The url Regex pattern.
/// </param>
public RequestUrlSpec(string url)
public RequestUrlSpec([NotNull, RegexPattern] string url)
{
_url = url;
Check.NotNull(url, nameof(url));
urlRegex = new Regex(url);
}
/// <summary>
@@ -48,7 +52,7 @@ namespace WireMock
/// </returns>
public bool IsSatisfiedBy(Request request)
{
return WildcardPatternMatcher.MatchWildcardString(_url, request.Url);
return urlRegex.IsMatch(request.Url);
}
}
}

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -46,7 +47,7 @@ namespace WireMock
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(Request request)
public bool IsSatisfiedBy([NotNull] Request request)
{
return request.Verb == _verb;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -16,12 +16,12 @@ using System.Threading.Tasks;
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
namespace WireMock.ResponseBuilders
{
/// <summary>
/// The responses.
/// </summary>
public class Responses : IHeadersResponseBuilder
public class ResponseBuilder : IHeadersResponseBuilder
{
/// <summary>
/// The _response.
@@ -34,12 +34,12 @@ namespace WireMock
private TimeSpan _delay = TimeSpan.Zero;
/// <summary>
/// Initializes a new instance of the <see cref="Responses"/> class.
/// Initializes a new instance of the <see cref="ResponseBuilder"/> class.
/// </summary>
/// <param name="response">
/// The response.
/// </param>
public Responses(Response response)
public ResponseBuilder(Response response)
{
_response = response;
}
@@ -74,7 +74,7 @@ namespace WireMock
public static IHeadersResponseBuilder WithStatusCode(int code)
{
var response = new Response { StatusCode = code };
return new Responses(response);
return new ResponseBuilder(response);
}
/// <summary>

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}
}
}