mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
get_routes (#12)
This commit is contained in:
BIN
WireMock.Net-Logo.png
Normal file
BIN
WireMock.Net-Logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -8,7 +8,13 @@ namespace WireMock.Matchers.Request
|
||||
/// </summary>
|
||||
public abstract class RequestMessageCompositeMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly IEnumerable<IRequestMatcher> _requestMatchers;
|
||||
/// <summary>
|
||||
/// Gets the request matchers.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The request matchers.
|
||||
/// </value>
|
||||
public IEnumerable<IRequestMatcher> RequestMatchers { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RequestMessageCompositeMatcher"/> class.
|
||||
@@ -17,9 +23,9 @@ namespace WireMock.Matchers.Request
|
||||
/// <param name="requestMatchers">
|
||||
/// The <see cref="IEnumerable<IRequestMatcher>"/> request matchers.
|
||||
/// </param>
|
||||
public RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers)
|
||||
protected RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers)
|
||||
{
|
||||
_requestMatchers = requestMatchers;
|
||||
RequestMatchers = requestMatchers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -31,7 +37,7 @@ namespace WireMock.Matchers.Request
|
||||
/// </returns>
|
||||
public bool IsMatch(RequestMessage requestMessage)
|
||||
{
|
||||
return _requestMatchers.All(spec => spec.IsMatch(requestMessage));
|
||||
return RequestMatchers.All(spec => spec.IsMatch(requestMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using WireMock.Matchers.Request;
|
||||
|
||||
[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>
|
||||
@@ -26,54 +11,44 @@ namespace WireMock
|
||||
/// <summary>
|
||||
/// The _request matcher.
|
||||
/// </summary>
|
||||
private readonly IRequestMatcher _requestSpec;
|
||||
public IRequestMatcher RequestMatcher { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The _provider.
|
||||
/// </summary>
|
||||
private readonly IProvideResponses _provider;
|
||||
public IProvideResponses Provider { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Route"/> class.
|
||||
/// </summary>
|
||||
/// <param name="requestSpec">
|
||||
/// The request matcher.
|
||||
/// </param>
|
||||
/// <param name="provider">
|
||||
/// The provider.
|
||||
/// </param>
|
||||
public Route(IRequestMatcher requestSpec, IProvideResponses provider)
|
||||
/// <param name="requestMatcher">The request matcher.</param>
|
||||
/// <param name="provider">The provider.</param>
|
||||
public Route(IRequestMatcher requestMatcher, IProvideResponses provider)
|
||||
{
|
||||
_requestSpec = requestSpec;
|
||||
_provider = provider;
|
||||
RequestMatcher = requestMatcher;
|
||||
Provider = provider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The response to.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">
|
||||
/// The request.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="Task"/>.
|
||||
/// </returns>
|
||||
public Task<ResponseMessage> ResponseTo(RequestMessage requestMessage)
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <returns>The <see cref="Task"/>.</returns>
|
||||
public async Task<ResponseMessage> ResponseTo(RequestMessage requestMessage)
|
||||
{
|
||||
return _provider.ProvideResponse(requestMessage);
|
||||
return await Provider.ProvideResponse(requestMessage);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The is request handled.
|
||||
/// Determines whether the RequestMessage is handled.
|
||||
/// </summary>
|
||||
/// <param name="requestMessage">
|
||||
/// The request.
|
||||
/// </param>
|
||||
/// <param name="requestMessage">The request message.</param>
|
||||
/// <returns>
|
||||
/// The <see cref="bool"/>.
|
||||
/// <c>true</c> if RequestMessage is handled; otherwise, <c>false</c>.
|
||||
/// </returns>
|
||||
public bool IsRequestHandled(RequestMessage requestMessage)
|
||||
{
|
||||
return _requestSpec.IsMatch(requestMessage);
|
||||
return RequestMatcher.IsMatch(requestMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,20 @@ namespace WireMock.Server
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the routes.
|
||||
/// </summary>
|
||||
public IEnumerable<Route> Routes
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (((ICollection)_routes).SyncRoot)
|
||||
{
|
||||
return new ReadOnlyCollection<Route>(_routes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start this FluentMockServer.
|
||||
/// </summary>
|
||||
@@ -95,31 +109,6 @@ namespace WireMock.Server
|
||||
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();
|
||||
}
|
||||
|
||||
return new FluentMockServer(port, ssl);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FluentMockServer"/> class, and starts the server.
|
||||
/// </summary>
|
||||
@@ -195,15 +184,15 @@ namespace WireMock.Server
|
||||
/// <summary>
|
||||
/// The given.
|
||||
/// </summary>
|
||||
/// <param name="requestSpec">
|
||||
/// <param name="requestMatcher">
|
||||
/// The request matcher.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The <see cref="IRespondWithAProvider"/>.
|
||||
/// </returns>
|
||||
public IRespondWithAProvider Given(IRequestMatcher requestSpec)
|
||||
public IRespondWithAProvider Given(IRequestMatcher requestMatcher)
|
||||
{
|
||||
return new RespondWithAProvider(RegisterRoute, requestSpec);
|
||||
return new RespondWithAProvider(RegisterRoute, requestMatcher);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
@@ -11,24 +10,6 @@ using WireMock.RequestBuilders;
|
||||
using WireMock.ResponseBuilders;
|
||||
using WireMock.Server;
|
||||
|
||||
[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",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||
// ReSharper disable ArrangeThisQualifier
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
@@ -37,6 +18,24 @@ namespace WireMock.Net.Tests
|
||||
{
|
||||
private FluentMockServer _server;
|
||||
|
||||
[Test]
|
||||
public void FluentMockServer_get_routes()
|
||||
{
|
||||
_server = FluentMockServer.Start();
|
||||
|
||||
_server.Given(Request.Create().WithUrl("/foo1").UsingGet())
|
||||
.RespondWith(Response.Create().WithStatusCode(201).WithBody("1"));
|
||||
|
||||
_server.Given(Request.Create().WithUrl("/foo2").UsingGet())
|
||||
.RespondWith(Response.Create().WithStatusCode(202).WithBody("2"));
|
||||
|
||||
var routes = _server.Routes;
|
||||
|
||||
Check.That(routes).HasSize(2);
|
||||
Check.That(routes.First().RequestMatcher).IsNotNull();
|
||||
Check.That(routes.First().Provider).IsNotNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Should_respond_to_request()
|
||||
{
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using NFluent;
|
||||
using NUnit.Framework;
|
||||
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1600:ElementsMustBeDocumented",
|
||||
Justification = "Reviewed. Suppression is OK here, as it's a tests class.")]
|
||||
[module:
|
||||
SuppressMessage("StyleCop.CSharp.DocumentationRules",
|
||||
"SA1633:FileMustHaveHeader",
|
||||
Justification = "Reviewed. Suppression is OK here, as unknown copyright and company.")]
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace WireMock.Net.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
Reference in New Issue
Block a user