mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 01:08:49 +02:00
DELETE /__admin/requests
This commit is contained in:
@@ -33,7 +33,7 @@ namespace WireMock.Net.ConsoleApplication
|
|||||||
.WithStatusCode(200)
|
.WithStatusCode(200)
|
||||||
.WithHeader("Content-Type", "application/json")
|
.WithHeader("Content-Type", "application/json")
|
||||||
.WithHeader("Transformed-Postman-Token", "token is {{request.headers.Postman-Token}}")
|
.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()
|
.WithTransformer()
|
||||||
.WithDelay(TimeSpan.FromMilliseconds(100))
|
.WithDelay(TimeSpan.FromMilliseconds(100))
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using WireMock.Admin.Mappings;
|
using WireMock.Admin.Mappings;
|
||||||
using WireMock.Admin.Requests;
|
using WireMock.Admin.Requests;
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
@@ -42,6 +43,7 @@ namespace WireMock.Server
|
|||||||
|
|
||||||
// __admin/requests
|
// __admin/requests
|
||||||
Given(Request.Create().WithPath(AdminRequests).UsingGet()).RespondWith(new DynamicResponseProvider(RequestsGet));
|
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)
|
private ResponseMessage MappingGet(RequestMessage requestMessage)
|
||||||
@@ -136,10 +138,12 @@ namespace WireMock.Server
|
|||||||
if (path != null)
|
if (path != null)
|
||||||
requestBuilder = requestBuilder.WithPath(path);
|
requestBuilder = requestBuilder.WithPath(path);
|
||||||
else
|
else
|
||||||
requestBuilder = requestBuilder.WithPath("/*");
|
{
|
||||||
//PathModel urlModel = mappingModel.Request.Path as PathModel;
|
JToken pathToken = (JToken) mappingModel.Request.Path;
|
||||||
//if (urlModel?.Matchers != null)
|
PathModel pathModel = pathToken.ToObject<PathModel>();
|
||||||
// builder = builder.WithPath(urlModel.Matchers.Select(Map).ToArray());
|
if (pathModel?.Matchers != null)
|
||||||
|
requestBuilder = requestBuilder.WithPath(pathModel.Matchers.Select(Map).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
if (mappingModel.Request.Methods != null)
|
if (mappingModel.Request.Methods != null)
|
||||||
requestBuilder = requestBuilder.UsingVerb(mappingModel.Request.Methods);
|
requestBuilder = requestBuilder.UsingVerb(mappingModel.Request.Methods);
|
||||||
@@ -175,10 +179,10 @@ namespace WireMock.Server
|
|||||||
var bodyMatcher = Map(mappingModel.Request.Body.Matcher);
|
var bodyMatcher = Map(mappingModel.Request.Body.Matcher);
|
||||||
requestBuilder = requestBuilder.WithBody(bodyMatcher);
|
requestBuilder = requestBuilder.WithBody(bodyMatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
return requestBuilder;
|
return requestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private IResponseBuilder InitResponseBuilder(MappingModel mappingModel)
|
private IResponseBuilder InitResponseBuilder(MappingModel mappingModel)
|
||||||
{
|
{
|
||||||
IResponseBuilder responseBuilder = Response.Create();
|
IResponseBuilder responseBuilder = Response.Create();
|
||||||
@@ -235,12 +239,19 @@ namespace WireMock.Server
|
|||||||
return ToJson(result);
|
return ToJson(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ResponseMessage RequestsDelete(RequestMessage requestMessage)
|
||||||
|
{
|
||||||
|
ResetLogEntries();
|
||||||
|
|
||||||
|
return new ResponseMessage { Body = "Requests deleted" };
|
||||||
|
}
|
||||||
|
|
||||||
private MappingModel ToMappingModel(Mapping mapping)
|
private MappingModel ToMappingModel(Mapping mapping)
|
||||||
{
|
{
|
||||||
var request = (Request)mapping.RequestMatcher;
|
var request = (Request)mapping.RequestMatcher;
|
||||||
var response = (Response)mapping.Provider;
|
var response = (Response)mapping.Provider;
|
||||||
|
|
||||||
var urlMatchers = request.GetRequestMessageMatchers<RequestMessageUrlMatcher>();
|
var pathMatchers = request.GetRequestMessageMatchers<RequestMessagePathMatcher>();
|
||||||
var headerMatchers = request.GetRequestMessageMatchers<RequestMessageHeaderMatcher>();
|
var headerMatchers = request.GetRequestMessageMatchers<RequestMessageHeaderMatcher>();
|
||||||
var cookieMatchers = request.GetRequestMessageMatchers<RequestMessageCookieMatcher>();
|
var cookieMatchers = request.GetRequestMessageMatchers<RequestMessageCookieMatcher>();
|
||||||
var paramsMatchers = request.GetRequestMessageMatchers<RequestMessageParamMatcher>();
|
var paramsMatchers = request.GetRequestMessageMatchers<RequestMessageParamMatcher>();
|
||||||
@@ -254,7 +265,7 @@ namespace WireMock.Server
|
|||||||
{
|
{
|
||||||
Path = new PathModel
|
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" },
|
Methods = methodMatcher != null ? methodMatcher.Methods : new[] { "any" },
|
||||||
Headers = headerMatchers?.Select(hm => new HeaderModel
|
Headers = headerMatchers?.Select(hm => new HeaderModel
|
||||||
|
|||||||
@@ -124,13 +124,21 @@ namespace WireMock.Server
|
|||||||
/// The reset.
|
/// The reset.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Reset()
|
public void Reset()
|
||||||
|
{
|
||||||
|
ResetLogEntries();
|
||||||
|
|
||||||
|
ResetMappings();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets the log entries.
|
||||||
|
/// </summary>
|
||||||
|
public void ResetLogEntries()
|
||||||
{
|
{
|
||||||
lock (((ICollection)_logEntries).SyncRoot)
|
lock (((ICollection)_logEntries).SyncRoot)
|
||||||
{
|
{
|
||||||
_logEntries.Clear();
|
_logEntries.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetMappings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user