-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FindRequestByMappingGuidAsync #1043
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ private void InitAdmin() | |
|
||
// __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)); | ||
|
||
// __admin/scenarios | ||
Given(Request.Create().WithPath(AdminScenarios).UsingGet()).AtPriority(WireMockConstants.AdminPriority).RespondWith(new DynamicResponseProvider(ScenariosGet)); | ||
|
@@ -436,7 +437,7 @@ private IResponseMessage MappingsPost(IRequestMessage requestMessage) | |
var mappingModels = DeserializeRequestMessageToArray<MappingModel>(requestMessage); | ||
if (mappingModels.Length == 1) | ||
{ | ||
Guid? guid = ConvertMappingAndRegisterAsRespondProvider(mappingModels[0]); | ||
var guid = ConvertMappingAndRegisterAsRespondProvider(mappingModels[0]); | ||
return ResponseMessageBuilder.Create(201, "Mapping added", guid); | ||
} | ||
|
||
|
@@ -535,7 +536,7 @@ private IResponseMessage RequestGet(IRequestMessage requestMessage) | |
{ | ||
if (TryParseGuidFromRequestMessage(requestMessage, out var guid)) | ||
{ | ||
var entry = LogEntries.FirstOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid); | ||
var entry = LogEntries.SingleOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid); | ||
if (entry is { }) | ||
{ | ||
var model = new LogEntryMapper(_options).Map(entry); | ||
|
@@ -600,6 +601,26 @@ private IResponseMessage RequestsFind(IRequestMessage requestMessage) | |
|
||
return ToJson(result); | ||
} | ||
|
||
private IResponseMessage RequestFindByMappingGuid(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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There could be more than one matching request, and in this case |
||
if (logEntry != null) | ||
{ | ||
var logEntryMapper = new LogEntryMapper(_options); | ||
return ToJson(logEntryMapper.Map(logEntry)); | ||
} | ||
|
||
return ResponseMessageBuilder.Create(HttpStatusCode.OK); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning 200 with an empty response is probably not what the client would expect. If the status code is 200, the client will expect the body to contain a But anyway, I think this endpoint should return a collection (which will be empty if no match is found) |
||
} | ||
|
||
return ResponseMessageBuilder.Create(HttpStatusCode.BadRequest); | ||
} | ||
#endregion Requests/find | ||
|
||
#region Scenarios | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should probably be
FindRequestsByMappingGuidAsync
, and return a collection