diff --git a/WireMock.Net-Logo.png b/WireMock.Net-Logo.png new file mode 100644 index 00000000..7325bd13 Binary files /dev/null and b/WireMock.Net-Logo.png differ diff --git a/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs b/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs index 54682b5f..25cffda2 100644 --- a/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs +++ b/src/WireMock/Matchers/Request/RequestMessageCompositeMatcher.cs @@ -8,7 +8,13 @@ namespace WireMock.Matchers.Request /// public abstract class RequestMessageCompositeMatcher : IRequestMatcher { - private readonly IEnumerable _requestMatchers; + /// + /// Gets the request matchers. + /// + /// + /// The request matchers. + /// + public IEnumerable RequestMatchers { get; } /// /// Initializes a new instance of the class. @@ -17,9 +23,9 @@ namespace WireMock.Matchers.Request /// /// The request matchers. /// - public RequestMessageCompositeMatcher(IEnumerable requestMatchers) + protected RequestMessageCompositeMatcher(IEnumerable requestMatchers) { - _requestMatchers = requestMatchers; + RequestMatchers = requestMatchers; } /// @@ -31,7 +37,7 @@ namespace WireMock.Matchers.Request /// public bool IsMatch(RequestMessage requestMessage) { - return _requestMatchers.All(spec => spec.IsMatch(requestMessage)); + return RequestMatchers.All(spec => spec.IsMatch(requestMessage)); } } } \ No newline at end of file diff --git a/src/WireMock/RequestBuilders/IAndPathRequestBuilder.cs b/src/WireMock/RequestBuilders/IRequestBuilder.cs similarity index 100% rename from src/WireMock/RequestBuilders/IAndPathRequestBuilder.cs rename to src/WireMock/RequestBuilders/IRequestBuilder.cs diff --git a/src/WireMock/Route.cs b/src/WireMock/Route.cs index a830d995..474b2fab 100644 --- a/src/WireMock/Route.cs +++ b/src/WireMock/Route.cs @@ -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 { /// @@ -26,54 +11,44 @@ namespace WireMock /// /// The _request matcher. /// - private readonly IRequestMatcher _requestSpec; + public IRequestMatcher RequestMatcher { get; } /// /// The _provider. /// - private readonly IProvideResponses _provider; + public IProvideResponses Provider { get; } /// /// Initializes a new instance of the class. /// - /// - /// The request matcher. - /// - /// - /// The provider. - /// - public Route(IRequestMatcher requestSpec, IProvideResponses provider) + /// The request matcher. + /// The provider. + public Route(IRequestMatcher requestMatcher, IProvideResponses provider) { - _requestSpec = requestSpec; - _provider = provider; + RequestMatcher = requestMatcher; + Provider = provider; } /// /// The response to. /// - /// - /// The request. - /// - /// - /// The . - /// - public Task ResponseTo(RequestMessage requestMessage) + /// The request message. + /// The . + public async Task ResponseTo(RequestMessage requestMessage) { - return _provider.ProvideResponse(requestMessage); + return await Provider.ProvideResponse(requestMessage); } /// - /// The is request handled. + /// Determines whether the RequestMessage is handled. /// - /// - /// The request. - /// + /// The request message. /// - /// The . + /// true if RequestMessage is handled; otherwise, false. /// public bool IsRequestHandled(RequestMessage requestMessage) { - return _requestSpec.IsMatch(requestMessage); + return RequestMatcher.IsMatch(requestMessage); } } } \ No newline at end of file diff --git a/src/WireMock/Server/FluentMockServer.cs b/src/WireMock/Server/FluentMockServer.cs index 12dce9ed..bb4a379e 100644 --- a/src/WireMock/Server/FluentMockServer.cs +++ b/src/WireMock/Server/FluentMockServer.cs @@ -72,6 +72,20 @@ namespace WireMock.Server } } + /// + /// Gets the routes. + /// + public IEnumerable Routes + { + get + { + lock (((ICollection)_routes).SyncRoot) + { + return new ReadOnlyCollection(_routes); + } + } + } + /// /// Start this FluentMockServer. /// @@ -95,31 +109,6 @@ namespace WireMock.Server 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(); - } - - return new FluentMockServer(port, ssl); - } - /// /// Initializes a new instance of the class, and starts the server. /// @@ -195,15 +184,15 @@ namespace WireMock.Server /// /// The given. /// - /// + /// /// The request matcher. /// /// /// The . /// - public IRespondWithAProvider Given(IRequestMatcher requestSpec) + public IRespondWithAProvider Given(IRequestMatcher requestMatcher) { - return new RespondWithAProvider(RegisterRoute, requestSpec); + return new RespondWithAProvider(RegisterRoute, requestMatcher); } /// diff --git a/test/WireMock.Net.Tests/FluentMockServerTests.cs b/test/WireMock.Net.Tests/FluentMockServerTests.cs index d70336d4..8d2559ce 100644 --- a/test/WireMock.Net.Tests/FluentMockServerTests.cs +++ b/test/WireMock.Net.Tests/FluentMockServerTests.cs @@ -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() { diff --git a/test/WireMock.Net.Tests/RequestMessageTests.cs b/test/WireMock.Net.Tests/RequestMessageTests.cs index 3322eedc..9d8e0547 100644 --- a/test/WireMock.Net.Tests/RequestMessageTests.cs +++ b/test/WireMock.Net.Tests/RequestMessageTests.cs @@ -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]