Fix partialMappings

This commit is contained in:
Stef Heyenrath
2017-02-06 07:47:34 +01:00
parent 8ecf7e414a
commit 3ba29e580c
2 changed files with 7 additions and 4 deletions

View File

@@ -29,6 +29,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.Tests", "test\
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone", "src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj", "{668F689E-57B4-422E-8846-C0FF643CA999}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WireMock.Net.StandAlone", "src\WireMock.Net.StandAlone\WireMock.Net.StandAlone.csproj", "{668F689E-57B4-422E-8846-C0FF643CA999}"
ProjectSection(ProjectDependencies) = postProject
{D3804228-91F4-4502-9595-39584E5A01AD} = {D3804228-91F4-4502-9595-39584E5A01AD}
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@@ -335,13 +335,13 @@ namespace WireMock.Server
RequestMatchResult requestMatchResult = null; RequestMatchResult requestMatchResult = null;
try try
{ {
var possibleMatchingMappings = _mappings var mappings = _mappings
.Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) }) .Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) })
.ToList(); .ToList();
if (_allowPartialMapping) if (_allowPartialMapping)
{ {
var orderedMappings = possibleMatchingMappings var partialMappings = mappings
.Where(pm => .Where(pm =>
(pm.Mapping.Provider is DynamicResponseProvider && pm.MatchResult.IsPerfectMatch) || (pm.Mapping.Provider is DynamicResponseProvider && pm.MatchResult.IsPerfectMatch) ||
!(pm.Mapping.Provider is DynamicResponseProvider) !(pm.Mapping.Provider is DynamicResponseProvider)
@@ -350,14 +350,14 @@ namespace WireMock.Server
.ThenBy(m => m.Mapping.Priority) .ThenBy(m => m.Mapping.Priority)
.ToList(); .ToList();
var bestPartialMatch = orderedMappings.FirstOrDefault(); var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.MatchPercentage > 0.0);
targetMapping = bestPartialMatch?.Mapping; targetMapping = bestPartialMatch?.Mapping;
requestMatchResult = bestPartialMatch?.MatchResult; requestMatchResult = bestPartialMatch?.MatchResult;
} }
else else
{ {
var perfectMatch = possibleMatchingMappings var perfectMatch = mappings
.OrderBy(m => m.Mapping.Priority) .OrderBy(m => m.Mapping.Priority)
.FirstOrDefault(m => m.MatchResult.IsPerfectMatch); .FirstOrDefault(m => m.MatchResult.IsPerfectMatch);