mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 11:21:51 +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>
|
/// </summary>
|
||||||
public abstract class RequestMessageCompositeMatcher : IRequestMatcher
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RequestMessageCompositeMatcher"/> class.
|
/// Initializes a new instance of the <see cref="RequestMessageCompositeMatcher"/> class.
|
||||||
@@ -17,9 +23,9 @@ namespace WireMock.Matchers.Request
|
|||||||
/// <param name="requestMatchers">
|
/// <param name="requestMatchers">
|
||||||
/// The <see cref="IEnumerable<IRequestMatcher>"/> request matchers.
|
/// The <see cref="IEnumerable<IRequestMatcher>"/> request matchers.
|
||||||
/// </param>
|
/// </param>
|
||||||
public RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers)
|
protected RequestMessageCompositeMatcher(IEnumerable<IRequestMatcher> requestMatchers)
|
||||||
{
|
{
|
||||||
_requestMatchers = requestMatchers;
|
RequestMatchers = requestMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -31,7 +37,7 @@ namespace WireMock.Matchers.Request
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsMatch(RequestMessage requestMessage)
|
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;
|
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
|
namespace WireMock
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -26,54 +11,44 @@ namespace WireMock
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _request matcher.
|
/// The _request matcher.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IRequestMatcher _requestSpec;
|
public IRequestMatcher RequestMatcher { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _provider.
|
/// The _provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IProvideResponses _provider;
|
public IProvideResponses Provider { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Route"/> class.
|
/// Initializes a new instance of the <see cref="Route"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestSpec">
|
/// <param name="requestMatcher">The request matcher.</param>
|
||||||
/// The request matcher.
|
/// <param name="provider">The provider.</param>
|
||||||
/// </param>
|
public Route(IRequestMatcher requestMatcher, IProvideResponses provider)
|
||||||
/// <param name="provider">
|
|
||||||
/// The provider.
|
|
||||||
/// </param>
|
|
||||||
public Route(IRequestMatcher requestSpec, IProvideResponses provider)
|
|
||||||
{
|
{
|
||||||
_requestSpec = requestSpec;
|
RequestMatcher = requestMatcher;
|
||||||
_provider = provider;
|
Provider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The response to.
|
/// The response to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestMessage">
|
/// <param name="requestMessage">The request message.</param>
|
||||||
/// The request.
|
/// <returns>The <see cref="Task"/>.</returns>
|
||||||
/// </param>
|
public async Task<ResponseMessage> ResponseTo(RequestMessage requestMessage)
|
||||||
/// <returns>
|
|
||||||
/// The <see cref="Task"/>.
|
|
||||||
/// </returns>
|
|
||||||
public Task<ResponseMessage> ResponseTo(RequestMessage requestMessage)
|
|
||||||
{
|
{
|
||||||
return _provider.ProvideResponse(requestMessage);
|
return await Provider.ProvideResponse(requestMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The is request handled.
|
/// Determines whether the RequestMessage is handled.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestMessage">
|
/// <param name="requestMessage">The request message.</param>
|
||||||
/// The request.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="bool"/>.
|
/// <c>true</c> if RequestMessage is handled; otherwise, <c>false</c>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsRequestHandled(RequestMessage requestMessage)
|
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>
|
/// <summary>
|
||||||
/// Start this FluentMockServer.
|
/// Start this FluentMockServer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -95,31 +109,6 @@ namespace WireMock.Server
|
|||||||
return new FluentMockServer(port, ssl);
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="FluentMockServer"/> class, and starts the server.
|
/// Initializes a new instance of the <see cref="FluentMockServer"/> class, and starts the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -195,15 +184,15 @@ namespace WireMock.Server
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The given.
|
/// The given.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="requestSpec">
|
/// <param name="requestMatcher">
|
||||||
/// The request matcher.
|
/// The request matcher.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// The <see cref="IRespondWithAProvider"/>.
|
/// The <see cref="IRespondWithAProvider"/>.
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public IRespondWithAProvider Given(IRequestMatcher requestSpec)
|
public IRespondWithAProvider Given(IRequestMatcher requestMatcher)
|
||||||
{
|
{
|
||||||
return new RespondWithAProvider(RegisterRoute, requestSpec);
|
return new RespondWithAProvider(RegisterRoute, requestMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -11,24 +10,6 @@ using WireMock.RequestBuilders;
|
|||||||
using WireMock.ResponseBuilders;
|
using WireMock.ResponseBuilders;
|
||||||
using WireMock.Server;
|
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
|
namespace WireMock.Net.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
@@ -37,6 +18,24 @@ namespace WireMock.Net.Tests
|
|||||||
{
|
{
|
||||||
private FluentMockServer _server;
|
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]
|
[Test]
|
||||||
public async Task Should_respond_to_request()
|
public async Task Should_respond_to_request()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using NFluent;
|
using NFluent;
|
||||||
using NUnit.Framework;
|
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
|
namespace WireMock.Net.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
|||||||
Reference in New Issue
Block a user