diff --git a/examples/WireMock.Net.ConsoleApplication/Program.cs b/examples/WireMock.Net.ConsoleApplication/Program.cs
index 0f1513fa..e60cb32a 100644
--- a/examples/WireMock.Net.ConsoleApplication/Program.cs
+++ b/examples/WireMock.Net.ConsoleApplication/Program.cs
@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
+using WireMock.Server;
namespace WireMock.Net.ConsoleApplication
diff --git a/src/WireMock/CompositeRequestSpec.cs b/src/WireMock/CompositeRequestSpec.cs
deleted file mode 100644
index d11b1614..00000000
--- a/src/WireMock/CompositeRequestSpec.cs
+++ /dev/null
@@ -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
-{
- ///
- /// The composite request spec.
- ///
- public class CompositeRequestSpec : ISpecifyRequests
- {
- ///
- /// The _request specs.
- ///
- private readonly IEnumerable _requestSpecs;
-
- ///
- /// Initializes a new instance of the class.
- /// The constructor.
- ///
- ///
- /// The request specs.
- ///
- public CompositeRequestSpec(IEnumerable requestSpecs)
- {
- _requestSpecs = requestSpecs;
- }
-
- ///
- /// The is satisfied by.
- ///
- ///
- /// The request.
- ///
- ///
- /// The .
- ///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
- {
- return _requestSpecs.All(spec => spec.IsSatisfiedBy(requestMessage));
- }
- }
-}
diff --git a/src/WireMock/Http/TinyHttpServer.cs b/src/WireMock/Http/TinyHttpServer.cs
index 38b1fa26..263147df 100644
--- a/src/WireMock/Http/TinyHttpServer.cs
+++ b/src/WireMock/Http/TinyHttpServer.cs
@@ -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
{
///
@@ -25,21 +10,20 @@ namespace WireMock.Http
///
public class TinyHttpServer
{
- ///
- /// The _http handler.
- ///
private readonly Action _httpHandler;
- ///
- /// The _listener.
- ///
private readonly HttpListener _listener;
- ///
- /// The cancellation token source.
- ///
private CancellationTokenSource _cts;
+ ///
+ /// Gets a value indicating whether this server is started.
+ ///
+ ///
+ /// true if this server is started; otherwise, false.
+ ///
+ public bool IsStarted { get; private set; }
+
///
/// Initializes a new instance of the class.
///
@@ -59,11 +43,13 @@ namespace WireMock.Http
}
///
- /// The start.
+ /// Start the server.
///
public void Start()
{
_listener.Start();
+ IsStarted = true;
+
_cts = new CancellationTokenSource();
Task.Run(
async () =>
@@ -81,11 +67,11 @@ namespace WireMock.Http
}
///
- /// The stop.
+ /// Stop the server.
///
public void Stop()
{
_cts.Cancel();
}
}
-}
+}
\ No newline at end of file
diff --git a/src/WireMock/ISpecifyRequests.cs b/src/WireMock/ISpecifyRequests.cs
deleted file mode 100644
index c62c92f8..00000000
--- a/src/WireMock/ISpecifyRequests.cs
+++ /dev/null
@@ -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
-{
- ///
- /// The SpecifyRequests interface.
- ///
- public interface ISpecifyRequests
- {
- ///
- /// The is satisfied by.
- ///
- ///
- /// The request.
- ///
- ///
- /// The .
- ///
- bool IsSatisfiedBy([NotNull] RequestMessage requestMessage);
- }
-}
diff --git a/src/WireMock/Matchers/Request/IRequestMatcher.cs b/src/WireMock/Matchers/Request/IRequestMatcher.cs
new file mode 100644
index 00000000..6e1d632e
--- /dev/null
+++ b/src/WireMock/Matchers/Request/IRequestMatcher.cs
@@ -0,0 +1,19 @@
+using JetBrains.Annotations;
+
+namespace WireMock.Matchers.Request
+{
+ ///
+ /// The RequestMatcher interface.
+ ///
+ public interface IRequestMatcher
+ {
+ ///
+ /// Determines whether the specified RequestMessage is match.
+ ///
+ /// The RequestMessage.
+ ///
+ /// true if the specified RequestMessage is match; otherwise, false.
+ ///
+ bool IsMatch([NotNull] RequestMessage requestMessage);
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock/RequestBodySpec.cs b/src/WireMock/Matchers/Request/RequestMessageBodyMatcher.cs
similarity index 73%
rename from src/WireMock/RequestBodySpec.cs
rename to src/WireMock/Matchers/Request/RequestMessageBodyMatcher.cs
index 55286060..13994414 100644
--- a/src/WireMock/RequestBodySpec.cs
+++ b/src/WireMock/Matchers/Request/RequestMessageBodyMatcher.cs
@@ -1,14 +1,13 @@
using System;
using JetBrains.Annotations;
-using WireMock.Matchers;
using WireMock.Validation;
-namespace WireMock
+namespace WireMock.Matchers.Request
{
///
- /// The request body spec.
+ /// The request body matcher.
///
- public class RequestBodySpec : ISpecifyRequests
+ public class RequestMessageBodyMatcher : IRequestMatcher
{
///
/// The bodyRegex.
@@ -31,75 +30,73 @@ namespace WireMock
private readonly Func _bodyDataFunc;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The body Regex pattern.
///
- public RequestBodySpec([NotNull, RegexPattern] string body)
+ public RequestMessageBodyMatcher([NotNull, RegexPattern] string body)
{
Check.NotNull(body, nameof(body));
_matcher = new RegexMatcher(body);
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The body Regex pattern.
///
- public RequestBodySpec([NotNull] byte[] body)
+ public RequestMessageBodyMatcher([NotNull] byte[] body)
{
Check.NotNull(body, nameof(body));
_bodyData = body;
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The body func.
///
- public RequestBodySpec([NotNull] Func func)
+ public RequestMessageBodyMatcher([NotNull] Func func)
{
Check.NotNull(func, nameof(func));
_bodyFunc = func;
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The body func.
///
- public RequestBodySpec([NotNull] Func func)
+ public RequestMessageBodyMatcher([NotNull] Func func)
{
Check.NotNull(func, nameof(func));
_bodyDataFunc = func;
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The body matcher.
///
- public RequestBodySpec([NotNull] IMatcher matcher)
+ public RequestMessageBodyMatcher([NotNull] IMatcher matcher)
{
Check.NotNull(matcher, nameof(matcher));
_matcher = matcher;
}
///
- /// The is satisfied by.
+ /// Determines whether the specified RequestMessage is match.
///
- ///
- /// The request.
- ///
+ /// The RequestMessage.
///
- /// The .
+ /// true if the specified RequestMessage is match; otherwise, false.
///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
+ public bool IsMatch(RequestMessage requestMessage)
{
if (_matcher != null)
return _matcher.IsMatch(requestMessage.BodyAsString);
diff --git a/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs b/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs
new file mode 100644
index 00000000..a7d574f5
--- /dev/null
+++ b/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace WireMock.Matchers.Request
+{
+ ///
+ /// The composite request matcher.
+ ///
+ public class RequestMessageCompositeMatcher : IRequestMatcher
+ {
+ private readonly IEnumerable _requestMatchers;
+
+ ///
+ /// Initializes a new instance of the class.
+ /// The constructor.
+ ///
+ ///
+ /// The request matchers.
+ ///
+ public RequestMessageCompositeMatcher(IEnumerable requestMatchers)
+ {
+ _requestMatchers = requestMatchers;
+ }
+
+ ///
+ /// Determines whether the specified RequestMessage is match.
+ ///
+ /// The RequestMessage.
+ ///
+ /// true if the specified RequestMessage is match; otherwise, false.
+ ///
+ public bool IsMatch(RequestMessage requestMessage)
+ {
+ return _requestMatchers.All(spec => spec.IsMatch(requestMessage));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock/Matchers/Request/RequestMessageHeaderMatcher.cs b/src/WireMock/Matchers/Request/RequestMessageHeaderMatcher.cs
new file mode 100644
index 00000000..de865397
--- /dev/null
+++ b/src/WireMock/Matchers/Request/RequestMessageHeaderMatcher.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using JetBrains.Annotations;
+using WireMock.Validation;
+
+namespace WireMock.Matchers.Request
+{
+ ///
+ /// The request header matcher.
+ ///
+ public class RequestMessageHeaderMatcher : IRequestMatcher
+ {
+ ///
+ /// The name.
+ ///
+ private readonly string _name;
+
+ ///
+ /// The patternRegex.
+ ///
+ private readonly Regex _patternRegex;
+
+ ///
+ /// The header function
+ ///
+ private readonly Func, bool> _headerFunc;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The name.
+ ///
+ ///
+ /// The pattern.
+ ///
+ /// The ignoreCase.
+ public RequestMessageHeaderMatcher([NotNull] string name, [NotNull, RegexPattern] string pattern, bool ignoreCase = true)
+ {
+ _name = name;
+ _patternRegex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The func.
+ ///
+ public RequestMessageHeaderMatcher([NotNull] Func, bool> func)
+ {
+ Check.NotNull(func, nameof(func));
+ _headerFunc = func;
+ }
+
+ ///
+ /// Determines whether the specified RequestMessage is match.
+ ///
+ /// The RequestMessage.
+ ///
+ /// true if the specified RequestMessage is match; otherwise, false.
+ ///
+ public bool IsMatch(RequestMessage requestMessage)
+ {
+ if (_patternRegex == null)
+ return _headerFunc(requestMessage.Headers);
+
+ string headerValue = requestMessage.Headers[_name];
+ return _patternRegex.IsMatch(headerValue);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock/RequestParamSpec.cs b/src/WireMock/Matchers/Request/RequestMessageParamMatcher.cs
similarity index 55%
rename from src/WireMock/RequestParamSpec.cs
rename to src/WireMock/Matchers/Request/RequestMessageParamMatcher.cs
index e1bc2100..4a8049ca 100644
--- a/src/WireMock/RequestParamSpec.cs
+++ b/src/WireMock/Matchers/Request/RequestMessageParamMatcher.cs
@@ -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
{
///
- /// The request parameters spec.
+ /// The request parameters matcher.
///
- public class RequestParamSpec : ISpecifyRequests
+ public class RequestMessageParamMatcher : IRequestMatcher
{
///
/// The _key.
@@ -38,7 +24,7 @@ namespace WireMock
private readonly Func>, bool> _func;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The key.
@@ -46,7 +32,7 @@ namespace WireMock
///
/// The values.
///
- public RequestParamSpec([NotNull] string key, [NotNull] IEnumerable values)
+ public RequestMessageParamMatcher([NotNull] string key, [NotNull] IEnumerable values)
{
Check.NotNull(key, nameof(key));
Check.NotNull(values, nameof(values));
@@ -56,27 +42,25 @@ namespace WireMock
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The func.
///
- public RequestParamSpec([NotNull] Func>, bool> func)
+ public RequestMessageParamMatcher([NotNull] Func>, bool> func)
{
Check.NotNull(func, nameof(func));
_func = func;
}
///
- /// The is satisfied by.
+ /// Determines whether the specified RequestMessage is match.
///
- ///
- /// The request.
- ///
+ /// The RequestMessage.
///
- /// The .
+ /// true if the specified RequestMessage is match; otherwise, false.
///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
+ public bool IsMatch(RequestMessage requestMessage)
{
if (_func != null)
{
diff --git a/src/WireMock/RequestPathSpec.cs b/src/WireMock/Matchers/Request/RequestMessagePathMatcher.cs
similarity index 65%
rename from src/WireMock/RequestPathSpec.cs
rename to src/WireMock/Matchers/Request/RequestMessagePathMatcher.cs
index 85cb3b13..10596848 100644
--- a/src/WireMock/RequestPathSpec.cs
+++ b/src/WireMock/Matchers/Request/RequestMessagePathMatcher.cs
@@ -3,12 +3,12 @@ using System.Text.RegularExpressions;
using JetBrains.Annotations;
using WireMock.Validation;
-namespace WireMock
+namespace WireMock.Matchers.Request
{
///
- /// The request path spec.
+ /// The request path matcher.
///
- public class RequestPathSpec : ISpecifyRequests
+ public class RequestMessagePathMatcher : IRequestMatcher
{
///
/// The pathRegex.
@@ -21,39 +21,37 @@ namespace WireMock
private readonly Func _pathFunc;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The path Regex pattern.
///
- public RequestPathSpec([NotNull, RegexPattern] string path)
+ public RequestMessagePathMatcher([NotNull, RegexPattern] string path)
{
Check.NotNull(path, nameof(path));
_pathRegex = new Regex(path);
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The url func.
///
- public RequestPathSpec([NotNull] Func func)
+ public RequestMessagePathMatcher([NotNull] Func func)
{
Check.NotNull(func, nameof(func));
_pathFunc = func;
}
///
- /// The is satisfied by.
+ /// Determines whether the specified RequestMessage is match.
///
- ///
- /// The request.
- ///
+ /// The RequestMessage.
///
- /// The .
+ /// true if the specified RequestMessage is match; otherwise, false.
///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
+ public bool IsMatch(RequestMessage requestMessage)
{
return _pathRegex?.IsMatch(requestMessage.Path) ?? _pathFunc(requestMessage.Path);
}
diff --git a/src/WireMock/Matchers/Request/RequestMessageUrlMatcher.cs b/src/WireMock/Matchers/Request/RequestMessageUrlMatcher.cs
new file mode 100644
index 00000000..88fb315a
--- /dev/null
+++ b/src/WireMock/Matchers/Request/RequestMessageUrlMatcher.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Text.RegularExpressions;
+using JetBrains.Annotations;
+using WireMock.Validation;
+
+namespace WireMock.Matchers.Request
+{
+ ///
+ /// The request url matcher.
+ ///
+ public class RequestMessageUrlMatcher : IRequestMatcher
+ {
+ ///
+ /// The urlRegex.
+ ///
+ private readonly Regex _urlRegex;
+
+ ///
+ /// The url function
+ ///
+ private readonly Func _urlFunc;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The url Regex pattern.
+ ///
+ public RequestMessageUrlMatcher([NotNull, RegexPattern] string url)
+ {
+ Check.NotNull(url, nameof(url));
+ _urlRegex = new Regex(url);
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The url func.
+ ///
+ public RequestMessageUrlMatcher(Func func)
+ {
+ Check.NotNull(func, nameof(func));
+ _urlFunc = func;
+ }
+
+ ///
+ /// Determines whether the specified RequestMessage is match.
+ ///
+ /// The RequestMessage.
+ ///
+ /// true if the specified RequestMessage is match; otherwise, false.
+ ///
+ public bool IsMatch(RequestMessage requestMessage)
+ {
+ return _urlRegex?.IsMatch(requestMessage.Url) ?? _urlFunc(requestMessage.Url);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock/RequestVerbSpec.cs b/src/WireMock/Matchers/Request/RequestMessageVerbMatcher.cs
similarity index 56%
rename from src/WireMock/RequestVerbSpec.cs
rename to src/WireMock/Matchers/Request/RequestMessageVerbMatcher.cs
index e1aec14c..826f8617 100644
--- a/src/WireMock/RequestVerbSpec.cs
+++ b/src/WireMock/Matchers/Request/RequestMessageVerbMatcher.cs
@@ -1,12 +1,12 @@
using JetBrains.Annotations;
using WireMock.Validation;
-namespace WireMock
+namespace WireMock.Matchers.Request
{
///
- /// The request verb spec.
+ /// The request verb matcher.
///
- internal class RequestVerbSpec : ISpecifyRequests
+ internal class RequestMessageVerbMatcher : IRequestMatcher
{
///
/// The _verb.
@@ -14,27 +14,25 @@ namespace WireMock
private readonly string _verb;
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The verb.
///
- public RequestVerbSpec([NotNull] string verb)
+ public RequestMessageVerbMatcher([NotNull] string verb)
{
Check.NotNull(verb, nameof(verb));
_verb = verb.ToLower();
}
///
- /// The is satisfied by.
+ /// Determines whether the specified RequestMessage is match.
///
- ///
- /// The request.
- ///
+ /// The RequestMessage.
///
- /// The .
+ /// true if the specified RequestMessage is match; otherwise, false.
///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
+ public bool IsMatch(RequestMessage requestMessage)
{
return requestMessage.Verb == _verb;
}
diff --git a/src/WireMock/RequestBuilders/IBodyRequestBuilder.cs b/src/WireMock/RequestBuilders/IBodyRequestBuilder.cs
index 26210715..d2c018ee 100644
--- a/src/WireMock/RequestBuilders/IBodyRequestBuilder.cs
+++ b/src/WireMock/RequestBuilders/IBodyRequestBuilder.cs
@@ -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.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithBody([NotNull] IMatcher matcher);
+ IRequestMatcher WithBody([NotNull] IMatcher matcher);
///
/// The with body.
@@ -27,9 +28,9 @@ namespace WireMock.RequestBuilders
/// The body.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithBody(string body);
+ IRequestMatcher WithBody(string body);
///
/// The with body byte[].
@@ -38,9 +39,9 @@ namespace WireMock.RequestBuilders
/// The body as byte[].
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithBody(byte[] body);
+ IRequestMatcher WithBody(byte[] body);
///
/// The with body string func.
@@ -49,9 +50,9 @@ namespace WireMock.RequestBuilders
/// The body string function.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithBody(Func body);
+ IRequestMatcher WithBody(Func body);
///
/// The with body byte[] func.
@@ -60,8 +61,8 @@ namespace WireMock.RequestBuilders
/// The body byte[] function.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithBody(Func body);
+ IRequestMatcher WithBody(Func body);
}
}
\ No newline at end of file
diff --git a/src/WireMock/RequestBuilders/IHeadersRequestBuilder.cs b/src/WireMock/RequestBuilders/IHeadersRequestBuilder.cs
index 2de9e2e5..aa89763f 100644
--- a/src/WireMock/RequestBuilders/IHeadersRequestBuilder.cs
+++ b/src/WireMock/RequestBuilders/IHeadersRequestBuilder.cs
@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
+using WireMock.Matchers.Request;
namespace WireMock.RequestBuilders
{
///
/// The HeadersRequestBuilder interface.
///
- public interface IHeadersRequestBuilder : IBodyRequestBuilder, ISpecifyRequests, IParamsRequestBuilder
+ public interface IHeadersRequestBuilder : IBodyRequestBuilder, IRequestMatcher, IParamsRequestBuilder
{
///
/// The with header.
diff --git a/src/WireMock/RequestBuilders/IParamsRequestBuilder.cs b/src/WireMock/RequestBuilders/IParamsRequestBuilder.cs
index 40a8f684..243fe89b 100644
--- a/src/WireMock/RequestBuilders/IParamsRequestBuilder.cs
+++ b/src/WireMock/RequestBuilders/IParamsRequestBuilder.cs
@@ -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.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithParam([NotNull] string key, params string[] values);
+ IRequestMatcher WithParam([NotNull] string key, params string[] values);
///
/// The with parameters.
@@ -30,8 +31,8 @@ namespace WireMock.RequestBuilders
/// The func.
///
///
- /// The .
+ /// The .
///
- ISpecifyRequests WithParam([NotNull] Func>, bool> func);
+ IRequestMatcher WithParam([NotNull] Func>, bool> func);
}
}
\ No newline at end of file
diff --git a/src/WireMock/RequestBuilders/IVerbRequestBuilder.cs b/src/WireMock/RequestBuilders/IVerbRequestBuilder.cs
index 26a6ddf5..2af18923 100644
--- a/src/WireMock/RequestBuilders/IVerbRequestBuilder.cs
+++ b/src/WireMock/RequestBuilders/IVerbRequestBuilder.cs
@@ -3,7 +3,7 @@
///
/// The VerbRequestBuilder interface.
///
- public interface IVerbRequestBuilder : ISpecifyRequests, IHeadersRequestBuilder
+ public interface IVerbRequestBuilder : IHeadersRequestBuilder
{
///
/// The using get.
diff --git a/src/WireMock/RequestBuilders/Request.cs b/src/WireMock/RequestBuilders/Request.cs
index 4078d58a..f541d046 100644
--- a/src/WireMock/RequestBuilders/Request.cs
+++ b/src/WireMock/RequestBuilders/Request.cs
@@ -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
///
/// The requests.
///
- public class Request : CompositeRequestSpec, IVerbRequestBuilder
+ public class Request : RequestMessageCompositeMatcher, IVerbRequestBuilder
{
///
- /// The _request specs.
+ /// The _request matchers.
///
- private readonly IList _requestSpecs;
+ private readonly IList _requestMatchers;
///
/// Initializes a new instance of the class.
///
- ///
- /// The request specs.
+ ///
+ /// The request matchers.
///
- private Request(IList requestSpecs) : base(requestSpecs)
+ private Request(IList requestMatchers) : base(requestMatchers)
{
- _requestSpecs = requestSpecs;
+ _requestMatchers = requestMatchers;
}
///
@@ -57,7 +58,7 @@ namespace WireMock.RequestBuilders
///
public static IVerbRequestBuilder WithUrl(string url)
{
- var specs = new List { new RequestUrlSpec(url) };
+ var specs = new List { new RequestMessageUrlMatcher(url) };
return new Request(specs);
}
@@ -73,7 +74,7 @@ namespace WireMock.RequestBuilders
///
public static IVerbRequestBuilder WithUrl(Func func)
{
- var specs = new List { new RequestUrlSpec(func) };
+ var specs = new List { new RequestMessageUrlMatcher(func) };
return new Request(specs);
}
@@ -89,7 +90,7 @@ namespace WireMock.RequestBuilders
///
public static IVerbRequestBuilder WithPath(string path)
{
- var specs = new List { new RequestPathSpec(path) };
+ var specs = new List { new RequestMessagePathMatcher(path) };
return new Request(specs);
}
@@ -105,7 +106,7 @@ namespace WireMock.RequestBuilders
///
public static IVerbRequestBuilder WithPath([NotNull] Func func)
{
- var specs = new List { new RequestPathSpec(func) };
+ var specs = new List { new RequestMessagePathMatcher(func) };
return new Request(specs);
}
@@ -118,7 +119,7 @@ namespace WireMock.RequestBuilders
///
public IHeadersRequestBuilder UsingGet()
{
- _requestSpecs.Add(new RequestVerbSpec("get"));
+ _requestMatchers.Add(new RequestMessageVerbMatcher("get"));
return this;
}
@@ -130,7 +131,7 @@ namespace WireMock.RequestBuilders
///
public IHeadersRequestBuilder UsingPost()
{
- _requestSpecs.Add(new RequestVerbSpec("post"));
+ _requestMatchers.Add(new RequestMessageVerbMatcher("post"));
return this;
}
@@ -142,7 +143,7 @@ namespace WireMock.RequestBuilders
///
public IHeadersRequestBuilder UsingPut()
{
- _requestSpecs.Add(new RequestVerbSpec("put"));
+ _requestMatchers.Add(new RequestMessageVerbMatcher("put"));
return this;
}
@@ -154,7 +155,7 @@ namespace WireMock.RequestBuilders
///
public IHeadersRequestBuilder UsingDelete()
{
- _requestSpecs.Add(new RequestVerbSpec("delete"));
+ _requestMatchers.Add(new RequestMessageVerbMatcher("delete"));
return this;
}
@@ -166,7 +167,7 @@ namespace WireMock.RequestBuilders
///
public IHeadersRequestBuilder UsingHead()
{
- _requestSpecs.Add(new RequestVerbSpec("head"));
+ _requestMatchers.Add(new RequestMessageVerbMatcher("head"));
return this;
}
@@ -192,7 +193,7 @@ namespace WireMock.RequestBuilders
///
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.
///
///
- /// The .
+ /// The .
///
- 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[].
///
///
- /// The .
+ /// The .
///
- 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.
///
///
- /// The .
+ /// The .
///
- public ISpecifyRequests WithBody(Func func)
+ public IRequestMatcher WithBody(Func func)
{
- _requestSpecs.Add(new RequestBodySpec(func));
+ _requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
@@ -248,11 +249,11 @@ namespace WireMock.RequestBuilders
/// The body function.
///
///
- /// The .
+ /// The .
///
- public ISpecifyRequests WithBody(Func func)
+ public IRequestMatcher WithBody(Func func)
{
- _requestSpecs.Add(new RequestBodySpec(func));
+ _requestMatchers.Add(new RequestMessageBodyMatcher(func));
return this;
}
@@ -261,11 +262,11 @@ namespace WireMock.RequestBuilders
///
/// The matcher.
///
- /// The .
+ /// The .
///
- 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.
///
///
- /// The .
+ /// The .
///
- 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.
///
///
- /// The .
+ /// The .
///
- public ISpecifyRequests WithParam(Func>, bool> func)
+ public IRequestMatcher WithParam(Func>, bool> func)
{
- _requestSpecs.Add(new RequestParamSpec(func));
+ _requestMatchers.Add(new RequestMessageParamMatcher(func));
return this;
}
@@ -317,7 +318,7 @@ namespace WireMock.RequestBuilders
///
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
///
public IHeadersRequestBuilder WithHeader(Func, bool> func)
{
- _requestSpecs.Add(new RequestHeaderSpec(func));
+ _requestMatchers.Add(new RequestMessageHeaderMatcher(func));
return this;
}
}
diff --git a/src/WireMock/RequestHeaderSpec.cs b/src/WireMock/RequestHeaderSpec.cs
deleted file mode 100644
index b8bf9e47..00000000
--- a/src/WireMock/RequestHeaderSpec.cs
+++ /dev/null
@@ -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
-{
- ///
- /// The request header spec.
- ///
- public class RequestHeaderSpec : ISpecifyRequests
- {
- ///
- /// The name.
- ///
- private readonly string name;
-
- ///
- /// The patternRegex.
- ///
- private readonly Regex patternRegex;
-
- ///
- /// The header function
- ///
- private readonly Func, bool> headerFunc;
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The name.
- ///
- ///
- /// The pattern.
- ///
- /// The ignoreCase.
- 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);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The func.
- ///
- public RequestHeaderSpec([NotNull] Func, bool> func)
- {
- Check.NotNull(func, nameof(func));
- headerFunc = func;
- }
-
- ///
- /// The is satisfied by.
- ///
- ///
- /// The request.
- ///
- ///
- /// The .
- ///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
- {
- if (patternRegex == null)
- return headerFunc(requestMessage.Headers);
-
- string headerValue = requestMessage.Headers[name];
- return patternRegex.IsMatch(headerValue);
- }
- }
-}
\ No newline at end of file
diff --git a/src/WireMock/RequestMessage.cs b/src/WireMock/RequestMessage.cs
index 3e6ab0a2..60fba7dc 100644
--- a/src/WireMock/RequestMessage.cs
+++ b/src/WireMock/RequestMessage.cs
@@ -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
{
///
diff --git a/src/WireMock/RequestUrlSpec.cs b/src/WireMock/RequestUrlSpec.cs
deleted file mode 100644
index 06f8d981..00000000
--- a/src/WireMock/RequestUrlSpec.cs
+++ /dev/null
@@ -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
-{
- ///
- /// The request url spec.
- ///
- public class RequestUrlSpec : ISpecifyRequests
- {
- ///
- /// The urlRegex.
- ///
- private readonly Regex urlRegex;
-
- ///
- /// The url function
- ///
- private readonly Func urlFunc;
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The url Regex pattern.
- ///
- public RequestUrlSpec([NotNull, RegexPattern] string url)
- {
- Check.NotNull(url, nameof(url));
- urlRegex = new Regex(url);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The url func.
- ///
- public RequestUrlSpec(Func func)
- {
- Check.NotNull(func, nameof(func));
- urlFunc = func;
- }
-
- ///
- /// The is satisfied by.
- ///
- ///
- /// The request.
- ///
- ///
- /// The .
- ///
- public bool IsSatisfiedBy(RequestMessage requestMessage)
- {
- return urlRegex?.IsMatch(requestMessage.Url) ?? urlFunc(requestMessage.Url);
- }
- }
-}
\ No newline at end of file
diff --git a/src/WireMock/ResponseMessage.cs b/src/WireMock/ResponseMessage.cs
index 6989745b..150a48b0 100644
--- a/src/WireMock/ResponseMessage.cs
+++ b/src/WireMock/ResponseMessage.cs
@@ -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
{
///
diff --git a/src/WireMock/Route.cs b/src/WireMock/Route.cs
index 40b57ffe..a830d995 100644
--- a/src/WireMock/Route.cs
+++ b/src/WireMock/Route.cs
@@ -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
{
///
- /// The _request spec.
+ /// The _request matcher.
///
- private readonly ISpecifyRequests _requestSpec;
+ private readonly IRequestMatcher _requestSpec;
///
/// The _provider.
@@ -36,12 +37,12 @@ namespace WireMock
/// Initializes a new instance of the class.
///
///
- /// The request spec.
+ /// The request matcher.
///
///
/// The provider.
///
- public Route(ISpecifyRequests requestSpec, IProvideResponses provider)
+ public Route(IRequestMatcher requestSpec, IProvideResponses provider)
{
_requestSpec = requestSpec;
_provider = provider;
@@ -72,7 +73,7 @@ namespace WireMock
///
public bool IsRequestHandled(RequestMessage requestMessage)
{
- return _requestSpec.IsSatisfiedBy(requestMessage);
+ return _requestSpec.IsMatch(requestMessage);
}
}
}
\ No newline at end of file
diff --git a/src/WireMock/RouteRegistrationCallback.cs b/src/WireMock/RouteRegistrationCallback.cs
index 738ea206..bc10b3a8 100644
--- a/src/WireMock/RouteRegistrationCallback.cs
+++ b/src/WireMock/RouteRegistrationCallback.cs
@@ -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
{
///
/// The registration callback.
@@ -14,4 +7,4 @@ namespace WireMock
/// The route.
///
public delegate void RegistrationCallback(Route route);
-}
+}
\ No newline at end of file
diff --git a/src/WireMock/FluentMockServer.cs b/src/WireMock/Server/FluentMockServer.cs
similarity index 69%
rename from src/WireMock/FluentMockServer.cs
rename to src/WireMock/Server/FluentMockServer.cs
index 6de0c666..12dce9ed 100644
--- a/src/WireMock/FluentMockServer.cs
+++ b/src/WireMock/Server/FluentMockServer.cs
@@ -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
{
///
/// The fluent mock server.
@@ -65,37 +53,6 @@ namespace WireMock
///
private TimeSpan _requestProcessingDelay = TimeSpan.Zero;
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The port.
- ///
- ///
- /// The SSL support.
- ///
- private FluentMockServer(int port, bool ssl)
- {
- string protocol = ssl ? "https" : "http";
- _httpServer = new TinyHttpServer(protocol + "://localhost:" + port + "/", HandleRequest);
- Port = port;
- _httpServer.Start();
- }
-
- ///
- /// The RespondWithAProvider interface.
- ///
- public interface IRespondWithAProvider
- {
- ///
- /// The respond with.
- ///
- ///
- /// The provider.
- ///
- void RespondWith(IProvideResponses provider);
- }
-
///
/// Gets the port.
///
@@ -116,7 +73,7 @@ namespace WireMock
}
///
- /// The start.
+ /// Start this FluentMockServer.
///
///
/// The port.
@@ -127,8 +84,34 @@ namespace WireMock
///
/// The .
///
+ [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);
+ }
+
+ ///
+ /// Create this FluentMockServer.
+ ///
+ ///
+ /// The port.
+ ///
+ ///
+ /// The SSL support.
+ ///
+ ///
+ /// The .
+ ///
+ [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);
}
+ ///
+ /// Initializes a new instance of the class, and starts the server.
+ ///
+ ///
+ /// The port.
+ ///
+ ///
+ /// The SSL support.
+ ///
+ private FluentMockServer(int port, bool ssl)
+ {
+ string protocol = ssl ? "https" : "http";
+ _httpServer = new TinyHttpServer(protocol + "://localhost:" + port + "/", HandleRequest);
+ Port = port;
+ _httpServer.Start();
+ }
+
+ ///
+ /// Stop this server.
+ ///
+ public void Stop()
+ {
+ _httpServer.Stop();
+ }
+
///
/// The reset.
///
@@ -157,16 +165,16 @@ namespace WireMock
/// The search logs for.
///
///
- /// The spec.
+ /// The matcher.
///
///
/// The .
///
- public IEnumerable SearchLogsFor(ISpecifyRequests spec)
+ public IEnumerable SearchLogsFor(IRequestMatcher spec)
{
lock (((ICollection)_requestLogs).SyncRoot)
{
- return _requestLogs.Where(spec.IsSatisfiedBy);
+ return _requestLogs.Where(spec.IsMatch);
}
}
@@ -184,24 +192,16 @@ namespace WireMock
}
}
- ///
- /// The stop.
- ///
- public void Stop()
- {
- _httpServer.Stop();
- }
-
///
/// The given.
///
///
- /// The request spec.
+ /// The request matcher.
///
///
/// The .
///
- 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();
}
}
-
- ///
- /// The respond with a provider.
- ///
- private class RespondWithAProvider : IRespondWithAProvider
- {
- ///
- /// The _registration callback.
- ///
- private readonly RegistrationCallback _registrationCallback;
-
- ///
- /// The _request spec.
- ///
- private readonly ISpecifyRequests _requestSpec;
-
- ///
- /// Initializes a new instance of the class.
- ///
- ///
- /// The registration callback.
- ///
- ///
- /// The request spec.
- ///
- public RespondWithAProvider(RegistrationCallback registrationCallback, ISpecifyRequests requestSpec)
- {
- _registrationCallback = registrationCallback;
- _requestSpec = requestSpec;
- }
-
- ///
- /// The respond with.
- ///
- ///
- /// The provider.
- ///
- public void RespondWith(IProvideResponses provider)
- {
- _registrationCallback(new Route(_requestSpec, provider));
- }
- }
}
}
diff --git a/src/WireMock/Server/IRespondWithAProvider.cs b/src/WireMock/Server/IRespondWithAProvider.cs
new file mode 100644
index 00000000..2c575f72
--- /dev/null
+++ b/src/WireMock/Server/IRespondWithAProvider.cs
@@ -0,0 +1,16 @@
+namespace WireMock.Server
+{
+ ///
+ /// IRespondWithAProvider
+ ///
+ public interface IRespondWithAProvider
+ {
+ ///
+ /// The respond with.
+ ///
+ ///
+ /// The provider.
+ ///
+ void RespondWith(IProvideResponses provider);
+ }
+}
\ No newline at end of file
diff --git a/src/WireMock/Server/RespondWithAProvider.cs b/src/WireMock/Server/RespondWithAProvider.cs
new file mode 100644
index 00000000..0ea517f2
--- /dev/null
+++ b/src/WireMock/Server/RespondWithAProvider.cs
@@ -0,0 +1,46 @@
+using WireMock.Matchers.Request;
+
+namespace WireMock.Server
+{
+ ///
+ /// The respond with a provider.
+ ///
+ internal class RespondWithAProvider : IRespondWithAProvider
+ {
+ ///
+ /// The _registration callback.
+ ///
+ private readonly RegistrationCallback _registrationCallback;
+
+ ///
+ /// The _request matcher.
+ ///
+ private readonly IRequestMatcher _requestSpec;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ /// The registration callback.
+ ///
+ ///
+ /// The request matcher.
+ ///
+ public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestSpec)
+ {
+ _registrationCallback = registrationCallback;
+ _requestSpec = requestSpec;
+ }
+
+ ///
+ /// The respond with.
+ ///
+ ///
+ /// The provider.
+ ///
+ public void RespondWith(IProvideResponses provider)
+ {
+ _registrationCallback(new Route(_requestSpec, provider));
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/WireMock.Net.Tests/FluentMockServerTests.cs b/test/WireMock.Net.Tests/FluentMockServerTests.cs
index 85a7df26..2289f523 100644
--- a/test/WireMock.Net.Tests/FluentMockServerTests.cs
+++ b/test/WireMock.Net.Tests/FluentMockServerTests.cs
@@ -9,6 +9,7 @@ using NFluent;
using NUnit.Framework;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
+using WireMock.Server;
[module:
SuppressMessage("StyleCop.CSharp.ReadabilityRules",
diff --git a/test/WireMock.Net.Tests/RequestTests.cs b/test/WireMock.Net.Tests/RequestTests.cs
index ed361f97..2fee6684 100644
--- a/test/WireMock.Net.Tests/RequestTests.cs
+++ b/test/WireMock.Net.Tests/RequestTests.cs
@@ -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 { { "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 { { "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 { { "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 { { "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 { { "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 { { "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 { { "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();
}
}
}