mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-22 17:19:00 +01:00
Change FindRequestByMappingGuidAsync to return a collection of entries (#1046)
This commit is contained in:
@@ -201,12 +201,12 @@ public interface IWireMockAdminApi
|
||||
Task<IList<LogEntryModel>> FindRequestsAsync([Body] RequestModel model, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Find a request based on the Mapping Guid.
|
||||
/// Find requests based on the Mapping Guid.
|
||||
/// </summary>
|
||||
/// <param name="mappingGuid">The Mapping Guid</param>
|
||||
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||
[Get("requests/find")]
|
||||
Task<LogEntryModel?> FindRequestByMappingGuidAsync([Query] Guid mappingGuid, CancellationToken cancellationToken = default);
|
||||
Task<IList<LogEntryModel>> FindRequestsByMappingGuidAsync([Query] Guid mappingGuid, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Get all scenarios
|
||||
@@ -304,4 +304,4 @@ public interface IWireMockAdminApi
|
||||
/// <param name="cancellationToken">The optional cancellationToken.</param>
|
||||
[Post("openapi/save")]
|
||||
Task<StatusModel> OpenApiSaveAsync([Body] string text, CancellationToken cancellationToken = default);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public partial class WireMockServer
|
||||
|
||||
// __admin/requests/find
|
||||
Given(Request.Create().WithPath(AdminRequests + "/find").UsingPost()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFind));
|
||||
Given(Request.Create().WithPath(AdminRequests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestFindByMappingGuid));
|
||||
Given(Request.Create().WithPath(AdminRequests + "/find").UsingGet().WithParam("mappingGuid", new NotNullOrEmptyMatcher())).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(RequestsFindByMappingGuid));
|
||||
|
||||
// __admin/scenarios
|
||||
Given(Request.Create().WithPath(AdminScenarios).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosGet));
|
||||
@@ -602,21 +602,17 @@ public partial class WireMockServer
|
||||
return ToJson(result);
|
||||
}
|
||||
|
||||
private IResponseMessage RequestFindByMappingGuid(IRequestMessage requestMessage)
|
||||
private IResponseMessage RequestsFindByMappingGuid(IRequestMessage requestMessage)
|
||||
{
|
||||
if (requestMessage.Query != null &&
|
||||
requestMessage.Query.TryGetValue("mappingGuid", out var value) &&
|
||||
Guid.TryParse(value.ToString(), out var mappingGuid)
|
||||
)
|
||||
{
|
||||
var logEntry = LogEntries.SingleOrDefault(le => !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid);
|
||||
if (logEntry != null)
|
||||
{
|
||||
var logEntryMapper = new LogEntryMapper(_options);
|
||||
return ToJson(logEntryMapper.Map(logEntry));
|
||||
}
|
||||
|
||||
return ResponseMessageBuilder.Create(HttpStatusCode.OK);
|
||||
var logEntries = LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid);
|
||||
var logEntryMapper = new LogEntryMapper(_options);
|
||||
var result = logEntries.Select(logEntryMapper.Map);
|
||||
return ToJson(result);
|
||||
}
|
||||
|
||||
return ResponseMessageBuilder.Create(HttpStatusCode.BadRequest);
|
||||
@@ -833,4 +829,4 @@ public partial class WireMockServer
|
||||
var singleResult = ((JObject)value).ToObject<T>();
|
||||
return new[] { singleResult! };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user