mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-18 07:13:46 +01:00
DELETE /__admin/requests
This commit is contained in:
@@ -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))
|
||||
);
|
||||
|
||||
@@ -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<PathModel>();
|
||||
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<RequestMessageUrlMatcher>();
|
||||
var pathMatchers = request.GetRequestMessageMatchers<RequestMessagePathMatcher>();
|
||||
var headerMatchers = request.GetRequestMessageMatchers<RequestMessageHeaderMatcher>();
|
||||
var cookieMatchers = request.GetRequestMessageMatchers<RequestMessageCookieMatcher>();
|
||||
var paramsMatchers = request.GetRequestMessageMatchers<RequestMessageParamMatcher>();
|
||||
@@ -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
|
||||
|
||||
@@ -124,13 +124,21 @@ namespace WireMock.Server
|
||||
/// The reset.
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
ResetLogEntries();
|
||||
|
||||
ResetMappings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the log entries.
|
||||
/// </summary>
|
||||
public void ResetLogEntries()
|
||||
{
|
||||
lock (((ICollection)_logEntries).SyncRoot)
|
||||
{
|
||||
_logEntries.Clear();
|
||||
}
|
||||
|
||||
ResetMappings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user