mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
DELETE /__admin/mappings/{guid}
This commit is contained in:
@@ -37,6 +37,7 @@ namespace WireMock.Server
|
||||
// __admin/mappings/{guid}
|
||||
Given(Request.Create().WithPath(_guidPathMatcher).UsingGet()).RespondWith(new DynamicResponseProvider(MappingGet));
|
||||
Given(Request.Create().WithPath(_guidPathMatcher).UsingPut().WithHeader("Content-Type", "application/json")).RespondWith(new DynamicResponseProvider(MappingPut));
|
||||
Given(Request.Create().WithPath(_guidPathMatcher).UsingDelete()).RespondWith(new DynamicResponseProvider(MappingDelete));
|
||||
|
||||
|
||||
// __admin/requests
|
||||
@@ -77,6 +78,15 @@ namespace WireMock.Server
|
||||
return new ResponseMessage { Body = "Mapping updated" };
|
||||
}
|
||||
|
||||
private ResponseMessage MappingDelete(RequestMessage requestMessage)
|
||||
{
|
||||
Guid guid = Guid.Parse(requestMessage.Path.TrimStart(AdminMappings.ToCharArray()));
|
||||
|
||||
DeleteMapping(guid);
|
||||
|
||||
return new ResponseMessage { Body = "Mapping removed" };
|
||||
}
|
||||
|
||||
private ResponseMessage MappingsGet(RequestMessage requestMessage)
|
||||
{
|
||||
var result = new List<MappingModel>();
|
||||
|
||||
@@ -144,6 +144,22 @@ namespace WireMock.Server
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the mappings.
|
||||
/// </summary>
|
||||
public void DeleteMapping(Guid guid)
|
||||
{
|
||||
lock (((ICollection)_mappings).SyncRoot)
|
||||
{
|
||||
// Check a mapping exists with the same GUID, if so, remove it.
|
||||
var existingMapping = _mappings.FirstOrDefault(m => m.Guid == guid);
|
||||
if (existingMapping != null)
|
||||
{
|
||||
_mappings.Remove(existingMapping);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The search logs for.
|
||||
/// </summary>
|
||||
@@ -192,11 +208,7 @@ namespace WireMock.Server
|
||||
lock (((ICollection)_mappings).SyncRoot)
|
||||
{
|
||||
// Check a mapping exists with the same GUID, if so, remove it first.
|
||||
var existingMapping = _mappings.FirstOrDefault(m => m.Guid == mapping.Guid);
|
||||
if (existingMapping != null)
|
||||
{
|
||||
_mappings.Remove(existingMapping);
|
||||
}
|
||||
DeleteMapping(mapping.Guid);
|
||||
|
||||
_mappings.Add(mapping);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user