diff --git a/examples/WireMock.Net.ConsoleApplication/Program.cs b/examples/WireMock.Net.ConsoleApplication/Program.cs index 7fb10107..e3cbc7fe 100644 --- a/examples/WireMock.Net.ConsoleApplication/Program.cs +++ b/examples/WireMock.Net.ConsoleApplication/Program.cs @@ -33,7 +33,7 @@ namespace WireMock.Net.ConsoleApplication .WithStatusCode(200) .WithHeader("Content-Type", "application/json") .WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}") - .WithBody(@"{""msg"": ""Hello world, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}""") + .WithBody(@"{""msg"": ""Hello world, {{request.path}}, bykey={{request.query.start}}, bykey={{request.query.stop}}, byidx0={{request.query.stop.[0]}}, byidx1={{request.query.stop.[1]}}"" }") .WithTransformer() .WithDelay(TimeSpan.FromMilliseconds(100)) ); diff --git a/src/WireMock.Net/Server/FluentMockServer.Admin.cs b/src/WireMock.Net/Server/FluentMockServer.Admin.cs index a00e470d..ebf71076 100644 --- a/src/WireMock.Net/Server/FluentMockServer.Admin.cs +++ b/src/WireMock.Net/Server/FluentMockServer.Admin.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using WireMock.Admin.Mappings; using WireMock.Admin.Requests; using WireMock.Matchers; @@ -42,6 +43,7 @@ namespace WireMock.Server // __admin/requests Given(Request.Create().WithPath(AdminRequests).UsingGet()).RespondWith(new DynamicResponseProvider(RequestsGet)); + Given(Request.Create().WithPath(AdminRequests).UsingDelete()).RespondWith(new DynamicResponseProvider(RequestsDelete)); } private ResponseMessage MappingGet(RequestMessage requestMessage) @@ -136,10 +138,12 @@ namespace WireMock.Server if (path != null) requestBuilder = requestBuilder.WithPath(path); else - requestBuilder = requestBuilder.WithPath("/*"); - //PathModel urlModel = mappingModel.Request.Path as PathModel; - //if (urlModel?.Matchers != null) - // builder = builder.WithPath(urlModel.Matchers.Select(Map).ToArray()); + { + JToken pathToken = (JToken) mappingModel.Request.Path; + PathModel pathModel = pathToken.ToObject(); + if (pathModel?.Matchers != null) + requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(Map).ToArray()); + } if (mappingModel.Request.Methods != null) requestBuilder = requestBuilder.UsingVerb(mappingModel.Request.Methods); @@ -175,10 +179,10 @@ namespace WireMock.Server var bodyMatcher = Map(mappingModel.Request.Body.Matcher); requestBuilder = requestBuilder.WithBody(bodyMatcher); } + return requestBuilder; } - private IResponseBuilder InitResponseBuilder(MappingModel mappingModel) { IResponseBuilder responseBuilder = Response.Create(); @@ -235,12 +239,19 @@ namespace WireMock.Server return ToJson(result); } + private ResponseMessage RequestsDelete(RequestMessage requestMessage) + { + ResetLogEntries(); + + return new ResponseMessage { Body = "Requests deleted" }; + } + private MappingModel ToMappingModel(Mapping mapping) { var request = (Request)mapping.RequestMatcher; var response = (Response)mapping.Provider; - var urlMatchers = request.GetRequestMessageMatchers(); + var pathMatchers = request.GetRequestMessageMatchers(); var headerMatchers = request.GetRequestMessageMatchers(); var cookieMatchers = request.GetRequestMessageMatchers(); var paramsMatchers = request.GetRequestMessageMatchers(); @@ -254,7 +265,7 @@ namespace WireMock.Server { Path = new PathModel { - Matchers = urlMatchers != null ? Map(urlMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) : null + Matchers = pathMatchers != null ? Map(pathMatchers.Where(m => m.Matchers != null).SelectMany(m => m.Matchers)) : null }, Methods = methodMatcher != null ? methodMatcher.Methods : new[] { "any" }, Headers = headerMatchers?.Select(hm => new HeaderModel diff --git a/src/WireMock.Net/Server/FluentMockServer.cs b/src/WireMock.Net/Server/FluentMockServer.cs index b7c94ac1..7a7cbf04 100644 --- a/src/WireMock.Net/Server/FluentMockServer.cs +++ b/src/WireMock.Net/Server/FluentMockServer.cs @@ -124,13 +124,21 @@ namespace WireMock.Server /// The reset. /// public void Reset() + { + ResetLogEntries(); + + ResetMappings(); + } + + /// + /// Resets the log entries. + /// + public void ResetLogEntries() { lock (((ICollection)_logEntries).SyncRoot) { _logEntries.Clear(); } - - ResetMappings(); } ///