Move some classes and restructure.

This commit is contained in:
Stef Heyenrath
2017-01-20 12:07:29 +01:00
parent 847745c256
commit e2552f03b9
28 changed files with 471 additions and 583 deletions

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
namespace WireMock.Net.ConsoleApplication

View File

@@ -1,57 +0,0 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The composite request spec.
/// </summary>
public class CompositeRequestSpec : ISpecifyRequests
{
/// <summary>
/// The _request specs.
/// </summary>
private readonly IEnumerable<ISpecifyRequests> _requestSpecs;
/// <summary>
/// Initializes a new instance of the <see cref="CompositeRequestSpec"/> class.
/// The constructor.
/// </summary>
/// <param name="requestSpecs">
/// The <see cref="IEnumerable&lt;ISpecifyRequests&gt;"/> request specs.
/// </param>
public CompositeRequestSpec(IEnumerable<ISpecifyRequests> requestSpecs)
{
_requestSpecs = requestSpecs;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
{
return _requestSpecs.All(spec => spec.IsSatisfiedBy(requestMessage));
}
}
}

View File

@@ -1,23 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock.Http
{
/// <summary>
@@ -25,21 +10,20 @@ namespace WireMock.Http
/// </summary>
public class TinyHttpServer
{
/// <summary>
/// The _http handler.
/// </summary>
private readonly Action<HttpListenerContext> _httpHandler;
/// <summary>
/// The _listener.
/// </summary>
private readonly HttpListener _listener;
/// <summary>
/// The cancellation token source.
/// </summary>
private CancellationTokenSource _cts;
/// <summary>
/// Gets a value indicating whether this server is started.
/// </summary>
/// <value>
/// <c>true</c> if this server is started; otherwise, <c>false</c>.
/// </value>
public bool IsStarted { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="TinyHttpServer"/> class.
/// </summary>
@@ -59,11 +43,13 @@ namespace WireMock.Http
}
/// <summary>
/// The start.
/// Start the server.
/// </summary>
public void Start()
{
_listener.Start();
IsStarted = true;
_cts = new CancellationTokenSource();
Task.Run(
async () =>
@@ -81,11 +67,11 @@ namespace WireMock.Http
}
/// <summary>
/// The stop.
/// Stop the server.
/// </summary>
public void Stop()
{
_cts.Cancel();
}
}
}
}

View File

@@ -1,27 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
{
/// <summary>
/// The SpecifyRequests interface.
/// </summary>
public interface ISpecifyRequests
{
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
bool IsSatisfiedBy([NotNull] RequestMessage requestMessage);
}
}

View File

@@ -0,0 +1,19 @@
using JetBrains.Annotations;
namespace WireMock.Matchers.Request
{
/// <summary>
/// The RequestMatcher interface.
/// </summary>
public interface IRequestMatcher
{
/// <summary>
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
bool IsMatch([NotNull] RequestMessage requestMessage);
}
}

View File

@@ -1,14 +1,13 @@
using System;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Validation;
namespace WireMock
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request body spec.
/// The request body matcher.
/// </summary>
public class RequestBodySpec : ISpecifyRequests
public class RequestMessageBodyMatcher : IRequestMatcher
{
/// <summary>
/// The bodyRegex.
@@ -31,75 +30,73 @@ namespace WireMock
private readonly Func<byte[], bool> _bodyDataFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="body">
/// The body Regex pattern.
/// </param>
public RequestBodySpec([NotNull, RegexPattern] string body)
public RequestMessageBodyMatcher([NotNull, RegexPattern] string body)
{
Check.NotNull(body, nameof(body));
_matcher = new RegexMatcher(body);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="body">
/// The body Regex pattern.
/// </param>
public RequestBodySpec([NotNull] byte[] body)
public RequestMessageBodyMatcher([NotNull] byte[] body)
{
Check.NotNull(body, nameof(body));
_bodyData = body;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="func">
/// The body func.
/// </param>
public RequestBodySpec([NotNull] Func<string, bool> func)
public RequestMessageBodyMatcher([NotNull] Func<string, bool> func)
{
Check.NotNull(func, nameof(func));
_bodyFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="func">
/// The body func.
/// </param>
public RequestBodySpec([NotNull] Func<byte[], bool> func)
public RequestMessageBodyMatcher([NotNull] Func<byte[], bool> func)
{
Check.NotNull(func, nameof(func));
_bodyDataFunc = func;
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestBodySpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageBodyMatcher"/> class.
/// </summary>
/// <param name="matcher">
/// The body matcher.
/// </param>
public RequestBodySpec([NotNull] IMatcher matcher)
public RequestMessageBodyMatcher([NotNull] IMatcher matcher)
{
Check.NotNull(matcher, nameof(matcher));
_matcher = matcher;
}
/// <summary>
/// The is satisfied by.
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// The <see cref="bool"/>.
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
public bool IsMatch(RequestMessage requestMessage)
{
if (_matcher != null)
return _matcher.IsMatch(requestMessage.BodyAsString);

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
using System.Linq;
namespace WireMock.Matchers.Request
{
/// <summary>
/// The composite request matcher.
/// </summary>
public class RequestMessageCompositeMatcher : IRequestMatcher
{
private readonly IEnumerable<IRequestMatcher> _requestMatchers;
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageCompositeMatcher"/> class.
/// The constructor.
/// </summary>
/// <param name="requestMatchers">
/// The <see cref="IEnumerable&lt;IRequestMatcher&gt;"/> request matchers.
/// </param>
public RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers)
{
_requestMatchers = requestMatchers;
}
/// <summary>
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsMatch(RequestMessage requestMessage)
{
return _requestMatchers.All(spec => spec.IsMatch(requestMessage));
}
}
}

View File

@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request header matcher.
/// </summary>
public class RequestMessageHeaderMatcher : IRequestMatcher
{
/// <summary>
/// The name.
/// </summary>
private readonly string _name;
/// <summary>
/// The patternRegex.
/// </summary>
private readonly Regex _patternRegex;
/// <summary>
/// The header function
/// </summary>
private readonly Func<IDictionary<string, string>, bool> _headerFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="pattern">
/// The pattern.
/// </param>
/// <param name="ignoreCase">The ignoreCase.</param>
public RequestMessageHeaderMatcher([NotNull] string name, [NotNull, RegexPattern] string pattern, bool ignoreCase = true)
{
_name = name;
_patternRegex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageHeaderMatcher"/> class.
/// </summary>
/// <param name="func">
/// The func.
/// </param>
public RequestMessageHeaderMatcher([NotNull] Func<IDictionary<string, string>, bool> func)
{
Check.NotNull(func, nameof(func));
_headerFunc = func;
}
/// <summary>
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsMatch(RequestMessage requestMessage)
{
if (_patternRegex == null)
return _headerFunc(requestMessage.Headers);
string headerValue = requestMessage.Headers[_name];
return _patternRegex.IsMatch(headerValue);
}
}
}

View File

@@ -1,29 +1,15 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request parameters spec.
/// The request parameters matcher.
/// </summary>
public class RequestParamSpec : ISpecifyRequests
public class RequestMessageParamMatcher : IRequestMatcher
{
/// <summary>
/// The _key.
@@ -38,7 +24,7 @@ namespace WireMock
private readonly Func<IDictionary<string, List<string>>, bool> _func;
/// <summary>
/// Initializes a new instance of the <see cref="RequestParamSpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
/// <param name="key">
/// The key.
@@ -46,7 +32,7 @@ namespace WireMock
/// <param name="values">
/// The values.
/// </param>
public RequestParamSpec([NotNull] string key, [NotNull] IEnumerable<string> values)
public RequestMessageParamMatcher([NotNull] string key, [NotNull] IEnumerable<string> values)
{
Check.NotNull(key, nameof(key));
Check.NotNull(values, nameof(values));
@@ -56,27 +42,25 @@ namespace WireMock
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestParamSpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageParamMatcher"/> class.
/// </summary>
/// <param name="func">
/// The func.
/// </param>
public RequestParamSpec([NotNull] Func<IDictionary<string, List<string>>, bool> func)
public RequestMessageParamMatcher([NotNull] Func<IDictionary<string, List<string>>, bool> func)
{
Check.NotNull(func, nameof(func));
_func = func;
}
/// <summary>
/// The is satisfied by.
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// The <see cref="bool"/>.
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
public bool IsMatch(RequestMessage requestMessage)
{
if (_func != null)
{

View File

@@ -3,12 +3,12 @@ using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request path spec.
/// The request path matcher.
/// </summary>
public class RequestPathSpec : ISpecifyRequests
public class RequestMessagePathMatcher : IRequestMatcher
{
/// <summary>
/// The pathRegex.
@@ -21,39 +21,37 @@ namespace WireMock
private readonly Func<string, bool> _pathFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
/// </summary>
/// <param name="path">
/// The path Regex pattern.
/// </param>
public RequestPathSpec([NotNull, RegexPattern] string path)
public RequestMessagePathMatcher([NotNull, RegexPattern] string path)
{
Check.NotNull(path, nameof(path));
_pathRegex = new Regex(path);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestPathSpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessagePathMatcher"/> class.
/// </summary>
/// <param name="func">
/// The url func.
/// </param>
public RequestPathSpec([NotNull] Func<string, bool> func)
public RequestMessagePathMatcher([NotNull] Func<string, bool> func)
{
Check.NotNull(func, nameof(func));
_pathFunc = func;
}
/// <summary>
/// The is satisfied by.
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// The <see cref="bool"/>.
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
public bool IsMatch(RequestMessage requestMessage)
{
return _pathRegex?.IsMatch(requestMessage.Path) ?? _pathFunc(requestMessage.Path);
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request url matcher.
/// </summary>
public class RequestMessageUrlMatcher : IRequestMatcher
{
/// <summary>
/// The urlRegex.
/// </summary>
private readonly Regex _urlRegex;
/// <summary>
/// The url function
/// </summary>
private readonly Func<string, bool> _urlFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
/// </summary>
/// <param name="url">
/// The url Regex pattern.
/// </param>
public RequestMessageUrlMatcher([NotNull, RegexPattern] string url)
{
Check.NotNull(url, nameof(url));
_urlRegex = new Regex(url);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestMessageUrlMatcher"/> class.
/// </summary>
/// <param name="func">
/// The url func.
/// </param>
public RequestMessageUrlMatcher(Func<string, bool> func)
{
Check.NotNull(func, nameof(func));
_urlFunc = func;
}
/// <summary>
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsMatch(RequestMessage requestMessage)
{
return _urlRegex?.IsMatch(requestMessage.Url) ?? _urlFunc(requestMessage.Url);
}
}
}

View File

@@ -1,12 +1,12 @@
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock
namespace WireMock.Matchers.Request
{
/// <summary>
/// The request verb spec.
/// The request verb matcher.
/// </summary>
internal class RequestVerbSpec : ISpecifyRequests
internal class RequestMessageVerbMatcher : IRequestMatcher
{
/// <summary>
/// The _verb.
@@ -14,27 +14,25 @@ namespace WireMock
private readonly string _verb;
/// <summary>
/// Initializes a new instance of the <see cref="RequestVerbSpec"/> class.
/// Initializes a new instance of the <see cref="RequestMessageVerbMatcher"/> class.
/// </summary>
/// <param name="verb">
/// The verb.
/// </param>
public RequestVerbSpec([NotNull] string verb)
public RequestMessageVerbMatcher([NotNull] string verb)
{
Check.NotNull(verb, nameof(verb));
_verb = verb.ToLower();
}
/// <summary>
/// The is satisfied by.
/// Determines whether the specified RequestMessage is match.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <param name="requestMessage">The RequestMessage.</param>
/// <returns>
/// The <see cref="bool"/>.
/// <c>true</c> if the specified RequestMessage is match; otherwise, <c>false</c>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
public bool IsMatch(RequestMessage requestMessage)
{
return requestMessage.Verb == _verb;
}

View File

@@ -1,6 +1,7 @@
using System;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
@@ -16,9 +17,9 @@ namespace WireMock.RequestBuilders
/// The matcher.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithBody([NotNull] IMatcher matcher);
IRequestMatcher WithBody([NotNull] IMatcher matcher);
/// <summary>
/// The with body.
@@ -27,9 +28,9 @@ namespace WireMock.RequestBuilders
/// The body.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithBody(string body);
IRequestMatcher WithBody(string body);
/// <summary>
/// The with body byte[].
@@ -38,9 +39,9 @@ namespace WireMock.RequestBuilders
/// The body as byte[].
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithBody(byte[] body);
IRequestMatcher WithBody(byte[] body);
/// <summary>
/// The with body string func.
@@ -49,9 +50,9 @@ namespace WireMock.RequestBuilders
/// The body string function.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithBody(Func<string, bool> body);
IRequestMatcher WithBody(Func<string, bool> body);
/// <summary>
/// The with body byte[] func.
@@ -60,8 +61,8 @@ namespace WireMock.RequestBuilders
/// The body byte[] function.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithBody(Func<byte[], bool> body);
IRequestMatcher WithBody(Func<byte[], bool> body);
}
}

View File

@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
/// <summary>
/// The HeadersRequestBuilder interface.
/// </summary>
public interface IHeadersRequestBuilder : IBodyRequestBuilder, ISpecifyRequests, IParamsRequestBuilder
public interface IHeadersRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
{
/// <summary>
/// The with header.

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
@@ -19,9 +20,9 @@ namespace WireMock.RequestBuilders
/// The values.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithParam([NotNull] string key, params string[] values);
IRequestMatcher WithParam([NotNull] string key, params string[] values);
/// <summary>
/// The with parameters.
@@ -30,8 +31,8 @@ namespace WireMock.RequestBuilders
/// The func.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
ISpecifyRequests WithParam([NotNull] Func<IDictionary<string, List<string>>, bool> func);
IRequestMatcher WithParam([NotNull] Func<IDictionary<string, List<string>>, bool> func);
}
}

View File

@@ -3,7 +3,7 @@
/// <summary>
/// The VerbRequestBuilder interface.
/// </summary>
public interface IVerbRequestBuilder : ISpecifyRequests, IHeadersRequestBuilder
public interface IVerbRequestBuilder : IHeadersRequestBuilder
{
/// <summary>
/// The using get.

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Matchers;
using WireMock.Matchers.Request;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -28,22 +29,22 @@ namespace WireMock.RequestBuilders
/// <summary>
/// The requests.
/// </summary>
public class Request : CompositeRequestSpec, IVerbRequestBuilder
public class Request : RequestMessageCompositeMatcher, IVerbRequestBuilder
{
/// <summary>
/// The _request specs.
/// The _request matchers.
/// </summary>
private readonly IList<ISpecifyRequests> _requestSpecs;
private readonly IList<IRequestMatcher> _requestMatchers;
/// <summary>
/// Initializes a new instance of the <see cref="Request"/> class.
/// </summary>
/// <param name="requestSpecs">
/// The request specs.
/// <param name="requestMatchers">
/// The request matchers.
/// </param>
private Request(IList<ISpecifyRequests> requestSpecs) : base(requestSpecs)
private Request(IList<IRequestMatcher> requestMatchers) : base(requestMatchers)
{
_requestSpecs = requestSpecs;
_requestMatchers = requestMatchers;
}
/// <summary>
@@ -57,7 +58,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public static IVerbRequestBuilder WithUrl(string url)
{
var specs = new List<ISpecifyRequests> { new RequestUrlSpec(url) };
var specs = new List<IRequestMatcher> { new RequestMessageUrlMatcher(url) };
return new Request(specs);
}
@@ -73,7 +74,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public static IVerbRequestBuilder WithUrl(Func<string, bool> func)
{
var specs = new List<ISpecifyRequests> { new RequestUrlSpec(func) };
var specs = new List<IRequestMatcher> { new RequestMessageUrlMatcher(func) };
return new Request(specs);
}
@@ -89,7 +90,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public static IVerbRequestBuilder WithPath(string path)
{
var specs = new List<ISpecifyRequests> { new RequestPathSpec(path) };
var specs = new List<IRequestMatcher> { new RequestMessagePathMatcher(path) };
return new Request(specs);
}
@@ -105,7 +106,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public static IVerbRequestBuilder WithPath([NotNull] Func<string, bool> func)
{
var specs = new List<ISpecifyRequests> { new RequestPathSpec(func) };
var specs = new List<IRequestMatcher> { new RequestMessagePathMatcher(func) };
return new Request(specs);
}
@@ -118,7 +119,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingGet()
{
_requestSpecs.Add(new RequestVerbSpec("get"));
_requestMatchers.Add(new RequestMessageVerbMatcher("get"));
return this;
}
@@ -130,7 +131,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingPost()
{
_requestSpecs.Add(new RequestVerbSpec("post"));
_requestMatchers.Add(new RequestMessageVerbMatcher("post"));
return this;
}
@@ -142,7 +143,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingPut()
{
_requestSpecs.Add(new RequestVerbSpec("put"));
_requestMatchers.Add(new RequestMessageVerbMatcher("put"));
return this;
}
@@ -154,7 +155,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingDelete()
{
_requestSpecs.Add(new RequestVerbSpec("delete"));
_requestMatchers.Add(new RequestMessageVerbMatcher("delete"));
return this;
}
@@ -166,7 +167,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingHead()
{
_requestSpecs.Add(new RequestVerbSpec("head"));
_requestMatchers.Add(new RequestMessageVerbMatcher("head"));
return this;
}
@@ -192,7 +193,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder UsingVerb(string verb)
{
_requestSpecs.Add(new RequestVerbSpec(verb));
_requestMatchers.Add(new RequestMessageVerbMatcher(verb));
return this;
}
@@ -203,11 +204,11 @@ namespace WireMock.RequestBuilders
/// The body.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithBody(string body)
public IRequestMatcher WithBody(string body)
{
_requestSpecs.Add(new RequestBodySpec(body));
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
return this;
}
@@ -218,11 +219,11 @@ namespace WireMock.RequestBuilders
/// The body as byte[].
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithBody(byte[] body)
public IRequestMatcher WithBody(byte[] body)
{
_requestSpecs.Add(new RequestBodySpec(body));
_requestMatchers.Add(new RequestMessageBodyMatcher(body));
return this;
}
@@ -233,11 +234,11 @@ namespace WireMock.RequestBuilders
/// The body function.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithBody(Func<string, bool> func)
public IRequestMatcher WithBody(Func<string, bool> func)
{
_requestSpecs.Add(new RequestBodySpec(func));
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
@@ -248,11 +249,11 @@ namespace WireMock.RequestBuilders
/// The body function.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithBody(Func<byte[], bool> func)
public IRequestMatcher WithBody(Func<byte[], bool> func)
{
_requestSpecs.Add(new RequestBodySpec(func));
_requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
@@ -261,11 +262,11 @@ namespace WireMock.RequestBuilders
/// </summary>
/// <param name="matcher">The matcher.</param>
/// <returns>
/// The <see cref="ISpecifyRequests" />.
/// The <see cref="IRequestMatcher" />.
/// </returns>
public ISpecifyRequests WithBody(IMatcher matcher)
public IRequestMatcher WithBody(IMatcher matcher)
{
_requestSpecs.Add(new RequestBodySpec(matcher));
_requestMatchers.Add(new RequestMessageBodyMatcher(matcher));
return this;
}
@@ -279,11 +280,11 @@ namespace WireMock.RequestBuilders
/// The values.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithParam(string key, params string[] values)
public IRequestMatcher WithParam(string key, params string[] values)
{
_requestSpecs.Add(new RequestParamSpec(key, values.ToList()));
_requestMatchers.Add(new RequestMessageParamMatcher(key, values.ToList()));
return this;
}
@@ -294,11 +295,11 @@ namespace WireMock.RequestBuilders
/// The func.
/// </param>
/// <returns>
/// The <see cref="ISpecifyRequests"/>.
/// The <see cref="IRequestMatcher"/>.
/// </returns>
public ISpecifyRequests WithParam(Func<IDictionary<string, List<string>>, bool> func)
public IRequestMatcher WithParam(Func<IDictionary<string, List<string>>, bool> func)
{
_requestSpecs.Add(new RequestParamSpec(func));
_requestMatchers.Add(new RequestMessageParamMatcher(func));
return this;
}
@@ -317,7 +318,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder WithHeader(string name, string value, bool ignoreCase = true)
{
_requestSpecs.Add(new RequestHeaderSpec(name, value, ignoreCase));
_requestMatchers.Add(new RequestMessageHeaderMatcher(name, value, ignoreCase));
return this;
}
@@ -332,7 +333,7 @@ namespace WireMock.RequestBuilders
/// </returns>
public IHeadersRequestBuilder WithHeader(Func<IDictionary<string, string>, bool> func)
{
_requestSpecs.Add(new RequestHeaderSpec(func));
_requestMatchers.Add(new RequestMessageHeaderMatcher(func));
return this;
}
}

View File

@@ -1,90 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request header spec.
/// </summary>
public class RequestHeaderSpec : ISpecifyRequests
{
/// <summary>
/// The name.
/// </summary>
private readonly string name;
/// <summary>
/// The patternRegex.
/// </summary>
private readonly Regex patternRegex;
/// <summary>
/// The header function
/// </summary>
private readonly Func<IDictionary<string, string>, bool> headerFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
/// </summary>
/// <param name="name">
/// The name.
/// </param>
/// <param name="pattern">
/// The pattern.
/// </param>
/// <param name="ignoreCase">The ignoreCase.</param>
public RequestHeaderSpec([NotNull] string name, [NotNull, RegexPattern] string pattern, bool ignoreCase = true)
{
this.name = name;
patternRegex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestHeaderSpec"/> class.
/// </summary>
/// <param name="func">
/// The func.
/// </param>
public RequestHeaderSpec([NotNull] Func<IDictionary<string, string>, bool> func)
{
Check.NotNull(func, nameof(func));
headerFunc = func;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
{
if (patternRegex == null)
return headerFunc(requestMessage.Headers);
string headerValue = requestMessage.Headers[name];
return patternRegex.IsMatch(headerValue);
}
}
}

View File

@@ -1,27 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using JetBrains.Annotations;
using WireMock.Extensions;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[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>

View File

@@ -1,76 +0,0 @@
using System;
using System.Diagnostics.CodeAnalysis;
using JetBrains.Annotations;
using System.Text.RegularExpressions;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>
/// The request url spec.
/// </summary>
public class RequestUrlSpec : ISpecifyRequests
{
/// <summary>
/// The urlRegex.
/// </summary>
private readonly Regex urlRegex;
/// <summary>
/// The url function
/// </summary>
private readonly Func<string, bool> urlFunc;
/// <summary>
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
/// </summary>
/// <param name="url">
/// The url Regex pattern.
/// </param>
public RequestUrlSpec([NotNull, RegexPattern] string url)
{
Check.NotNull(url, nameof(url));
urlRegex = new Regex(url);
}
/// <summary>
/// Initializes a new instance of the <see cref="RequestUrlSpec"/> class.
/// </summary>
/// <param name="func">
/// The url func.
/// </param>
public RequestUrlSpec(Func<string, bool> func)
{
Check.NotNull(func, nameof(func));
urlFunc = func;
}
/// <summary>
/// The is satisfied by.
/// </summary>
/// <param name="requestMessage">
/// The request.
/// </param>
/// <returns>
/// The <see cref="bool"/>.
/// </returns>
public bool IsSatisfiedBy(RequestMessage requestMessage)
{
return urlRegex?.IsMatch(requestMessage.Url) ?? urlFunc(requestMessage.Url);
}
}
}

View File

@@ -1,21 +1,5 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
{
/// <summary>

View File

@@ -1,5 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using WireMock.Matchers.Request;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
@@ -23,9 +24,9 @@ namespace WireMock
public class Route
{
/// <summary>
/// The _request spec.
/// The _request matcher.
/// </summary>
private readonly ISpecifyRequests _requestSpec;
private readonly IRequestMatcher _requestSpec;
/// <summary>
/// The _provider.
@@ -36,12 +37,12 @@ namespace WireMock
/// Initializes a new instance of the <see cref="Route"/> class.
/// </summary>
/// <param name="requestSpec">
/// The request spec.
/// The request matcher.
/// </param>
/// <param name="provider">
/// The provider.
/// </param>
public Route(ISpecifyRequests requestSpec, IProvideResponses provider)
public Route(IRequestMatcher requestSpec, IProvideResponses provider)
{
_requestSpec = requestSpec;
_provider = provider;
@@ -72,7 +73,7 @@ namespace WireMock
/// </returns>
public bool IsRequestHandled(RequestMessage requestMessage)
{
return _requestSpec.IsSatisfiedBy(requestMessage);
return _requestSpec.IsMatch(requestMessage);
}
}
}

View File

@@ -1,11 +1,4 @@
using System.Diagnostics.CodeAnalysis;
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
namespace WireMock
namespace WireMock
{
/// <summary>
/// The registration callback.
@@ -14,4 +7,4 @@ namespace WireMock
/// The route.
/// </param>
public delegate void RegistrationCallback(Route route);
}
}

View File

@@ -1,29 +1,17 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using JetBrains.Annotations;
using WireMock.Http;
using WireMock.Matchers.Request;
using WireMock.Validation;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
"SA1101:PrefixLocalCallsWithThis",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.NamingRules",
"SA1309:FieldNamesMustNotBeginWithUnderscore",
Justification = "Reviewed. Suppression is OK here, as it conflicts with internal naming rules.")]
[module:
SuppressMessage("StyleCop.CSharp.DocumentationRules",
"SA1633:FileMustHaveHeader",
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
// ReSharper disable ArrangeThisQualifier
// ReSharper disable InconsistentNaming
namespace WireMock
namespace WireMock.Server
{
/// <summary>
/// The fluent mock server.
@@ -65,37 +53,6 @@ namespace WireMock
/// </summary>
private TimeSpan _requestProcessingDelay = TimeSpan.Zero;
/// <summary>
/// Initializes a new instance of the <see cref="FluentMockServer"/> class.
/// </summary>
/// <param name="port">
/// The port.
/// </param>
/// <param name="ssl">
/// The SSL support.
/// </param>
private FluentMockServer(int port, bool ssl)
{
string protocol = ssl ? "https" : "http";
_httpServer = new TinyHttpServer(protocol + "://localhost:" + port + "/", HandleRequest);
Port = port;
_httpServer.Start();
}
/// <summary>
/// The RespondWithAProvider interface.
/// </summary>
public interface IRespondWithAProvider
{
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
void RespondWith(IProvideResponses provider);
}
/// <summary>
/// Gets the port.
/// </summary>
@@ -116,7 +73,7 @@ namespace WireMock
}
/// <summary>
/// The start.
/// Start this FluentMockServer.
/// </summary>
/// <param name="port">
/// The port.
@@ -127,8 +84,34 @@ namespace WireMock
/// <returns>
/// The <see cref="FluentMockServer"/>.
/// </returns>
[PublicAPI]
public static FluentMockServer Start(int port = 0, bool ssl = false)
{
Check.Condition(port, p => p >= 0, nameof(port));
if (port == 0)
port = Ports.FindFreeTcpPort();
return new FluentMockServer(port, ssl);
}
/// <summary>
/// Create this FluentMockServer.
/// </summary>
/// <param name="port">
/// The port.
/// </param>
/// <param name="ssl">
/// The SSL support.
/// </param>
/// <returns>
/// The <see cref="FluentMockServer"/>.
/// </returns>
[PublicAPI]
public static FluentMockServer Create(int port = 0, bool ssl = false)
{
Check.Condition(port, p => p > 0, nameof(port));
if (port == 0)
{
port = Ports.FindFreeTcpPort();
@@ -137,6 +120,31 @@ namespace WireMock
return new FluentMockServer(port, ssl);
}
/// <summary>
/// Initializes a new instance of the <see cref="FluentMockServer"/> class, and starts the server.
/// </summary>
/// <param name="port">
/// The port.
/// </param>
/// <param name="ssl">
/// The SSL support.
/// </param>
private FluentMockServer(int port, bool ssl)
{
string protocol = ssl ? "https" : "http";
_httpServer = new TinyHttpServer(protocol + "://localhost:" + port + "/", HandleRequest);
Port = port;
_httpServer.Start();
}
/// <summary>
/// Stop this server.
/// </summary>
public void Stop()
{
_httpServer.Stop();
}
/// <summary>
/// The reset.
/// </summary>
@@ -157,16 +165,16 @@ namespace WireMock
/// The search logs for.
/// </summary>
/// <param name="spec">
/// The spec.
/// The matcher.
/// </param>
/// <returns>
/// The <see cref="IEnumerable"/>.
/// </returns>
public IEnumerable<RequestMessage> SearchLogsFor(ISpecifyRequests spec)
public IEnumerable<RequestMessage> SearchLogsFor(IRequestMatcher spec)
{
lock (((ICollection)_requestLogs).SyncRoot)
{
return _requestLogs.Where(spec.IsSatisfiedBy);
return _requestLogs.Where(spec.IsMatch);
}
}
@@ -184,24 +192,16 @@ namespace WireMock
}
}
/// <summary>
/// The stop.
/// </summary>
public void Stop()
{
_httpServer.Stop();
}
/// <summary>
/// The given.
/// </summary>
/// <param name="requestSpec">
/// The request spec.
/// The request matcher.
/// </param>
/// <returns>
/// The <see cref="IRespondWithAProvider"/>.
/// </returns>
public IRespondWithAProvider Given(ISpecifyRequests requestSpec)
public IRespondWithAProvider Given(IRequestMatcher requestSpec)
{
return new RespondWithAProvider(RegisterRoute, requestSpec);
}
@@ -249,6 +249,7 @@ namespace WireMock
var request = _requestMapper.Map(ctx.Request);
LogRequest(request);
try
{
var targetRoute = _routes.FirstOrDefault(route => route.IsRequestHandled(request));
@@ -277,47 +278,5 @@ namespace WireMock
ctx.Response.Close();
}
}
/// <summary>
/// The respond with a provider.
/// </summary>
private class RespondWithAProvider : IRespondWithAProvider
{
/// <summary>
/// The _registration callback.
/// </summary>
private readonly RegistrationCallback _registrationCallback;
/// <summary>
/// The _request spec.
/// </summary>
private readonly ISpecifyRequests _requestSpec;
/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
/// <param name="registrationCallback">
/// The registration callback.
/// </param>
/// <param name="requestSpec">
/// The request spec.
/// </param>
public RespondWithAProvider(RegistrationCallback registrationCallback, ISpecifyRequests requestSpec)
{
_registrationCallback = registrationCallback;
_requestSpec = requestSpec;
}
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
public void RespondWith(IProvideResponses provider)
{
_registrationCallback(new Route(_requestSpec, provider));
}
}
}
}

View File

@@ -0,0 +1,16 @@
namespace WireMock.Server
{
/// <summary>
/// IRespondWithAProvider
/// </summary>
public interface IRespondWithAProvider
{
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
void RespondWith(IProvideResponses provider);
}
}

View File

@@ -0,0 +1,46 @@
using WireMock.Matchers.Request;
namespace WireMock.Server
{
/// <summary>
/// The respond with a provider.
/// </summary>
internal class RespondWithAProvider : IRespondWithAProvider
{
/// <summary>
/// The _registration callback.
/// </summary>
private readonly RegistrationCallback _registrationCallback;
/// <summary>
/// The _request matcher.
/// </summary>
private readonly IRequestMatcher _requestSpec;
/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
/// <param name="registrationCallback">
/// The registration callback.
/// </param>
/// <param name="requestSpec">
/// The request matcher.
/// </param>
public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestSpec)
{
_registrationCallback = registrationCallback;
_requestSpec = requestSpec;
}
/// <summary>
/// The respond with.
/// </summary>
/// <param name="provider">
/// The provider.
/// </param>
public void RespondWith(IProvideResponses provider)
{
_registrationCallback(new Route(_requestSpec, provider));
}
}
}

View File

@@ -9,6 +9,7 @@ using NFluent;
using NUnit.Framework;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",

View File

@@ -23,7 +23,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -38,7 +38,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo/bar"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -53,7 +53,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/bar"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -68,7 +68,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "blabla", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -83,7 +83,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -98,7 +98,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "POST", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -113,7 +113,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "GET", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -128,7 +128,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "Delete", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -143,7 +143,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -158,7 +158,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "HEAD", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -173,7 +173,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -188,7 +188,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -203,7 +203,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -218,7 +218,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "ABC" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -233,7 +233,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "TaTaTa" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -248,7 +248,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -263,7 +263,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -278,7 +278,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -298,7 +298,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -318,7 +318,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, xmlBodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -333,7 +333,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -348,7 +348,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -363,7 +363,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo"), "PUT", body, bodyAsString, new Dictionary<string, string> { { "X-toto", "tatata" } });
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
[Test]
@@ -378,14 +378,14 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
public void Should_specify_requests_matching_given_params_func()
{
// given
var spec = Request.WithPath("/foo").WithParam(p => p.ContainsKey("bar") && (p["bar"].Contains("1") || p["bar"].Contains("2")));
var spec = Request.WithPath("/foo").UsingAnyVerb().WithParam(p => p.ContainsKey("bar"));
// when
string bodyAsString = "Hello world!";
@@ -393,7 +393,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/foo?bar=1&bar=2"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsTrue();
Check.That(spec.IsMatch(request)).IsTrue();
}
[Test]
@@ -408,7 +408,7 @@ namespace WireMock.Net.Tests
var request = new RequestMessage(new Uri("http://localhost/test=7"), "PUT", body, bodyAsString);
// then
Check.That(spec.IsSatisfiedBy(request)).IsFalse();
Check.That(spec.IsMatch(request)).IsFalse();
}
}
}