This commit is contained in:
Stef Heyenrath
2017-02-05 10:25:19 +01:00
parent 44f00cb9fa
commit 8231b25805
10 changed files with 152 additions and 73 deletions

View File

@@ -331,6 +331,7 @@ namespace WireMock.Server
var request = _requestMapper.Map(ctx.Request);
ResponseMessage response = null;
Mapping targetMapping = null;
RequestMatchResult requestMatchResult = null;
try
{
@@ -338,15 +339,19 @@ namespace WireMock.Server
.Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) })
.ToList();
Mapping targetMapping;
if (_allowPartialMapping)
{
var orderedMappings = possibleMatchingMappings
.OrderBy(m => m.Mapping.Priority)
.ThenBy(m => m.MatchResult)
.Where(pm =>
(pm.Mapping.Provider is DynamicResponseProvider && pm.MatchResult.IsPerfectMatch) ||
!(pm.Mapping.Provider is DynamicResponseProvider)
)
.OrderBy(m => m.MatchResult)
.ThenBy(m => m.Mapping.Priority)
.ToList();
var bestPartialMatch = orderedMappings.FirstOrDefault();
targetMapping = bestPartialMatch?.Mapping;
requestMatchResult = bestPartialMatch?.MatchResult;
}
@@ -388,6 +393,7 @@ namespace WireMock.Server
Guid = Guid.NewGuid(),
RequestMessage = request,
ResponseMessage = response,
MappingGuid = targetMapping?.Guid,
RequestMatchResult = requestMatchResult
};