private double IsMatch(RequestMessage requestMessage) { if (requestMessage.Headers == null) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } // Check if we want to use IgnoreCase to compare the Header-Name and Header-Value(s) var headers = !_ignoreCase ? requestMessage.Headers : new Dictionary <string, WireMockList <string> >(requestMessage.Headers, StringComparer.OrdinalIgnoreCase); if (Funcs != null) { return(MatchScores.ToScore(Funcs.Any(f => f(headers.ToDictionary(entry => entry.Key, entry => entry.Value.ToArray()))))); } if (Matchers == null) { return(MatchScores.Mismatch); } if (!headers.ContainsKey(Name)) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } WireMockList <string> list = headers[Name]; return(Matchers.Max(m => list.Max(value => m.IsMatch(value)))); // TODO : is this correct ? }
private double IsMatch(RequestMessage requestMessage) { if (requestMessage.Cookies == null) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } if (Funcs != null) { return(MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Cookies)))); } if (Matchers == null) { return(MatchScores.Mismatch); } if (!requestMessage.Cookies.ContainsKey(Name)) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } string value = requestMessage.Cookies[Name]; return(Matchers.Max(m => m.IsMatch(value))); }
private double IsMatch(RequestMessage requestMessage) { if (requestMessage.Headers == null) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } if (Funcs != null) { return(MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Headers.ToDictionary(entry => entry.Key, entry => entry.Value.ToArray()))))); } if (Matchers == null) { return(MatchScores.Mismatch); } if (!requestMessage.Headers.ContainsKey(Name)) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } WireMockList <string> list = requestMessage.Headers[Name]; return(Matchers.Max(m => list.Max(value => m.IsMatch(value)))); // TODO : is this correct ? }
private double IsMatch(RequestMessage requestMessage) { if (requestMessage.Cookies == null) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } // Check if we want to use IgnoreCase to compare the Cookie-Name and Cookie-Value var cookies = !_ignoreCase ? requestMessage.Cookies : new Dictionary <string, string>(requestMessage.Cookies, StringComparer.OrdinalIgnoreCase); if (Funcs != null) { return(MatchScores.ToScore(Funcs.Any(f => f(cookies)))); } if (Matchers == null) { return(MatchScores.Mismatch); } if (!cookies.ContainsKey(Name)) { return(MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch)); } string value = cookies[Name]; return(Matchers.Max(m => m.IsMatch(value))); }
/// <inheritdoc cref="IRequestMatcher.GetMatchingScore"/> public double GetMatchingScore(RequestMessage requestMessage, RequestMatchResult requestMatchResult) { double score = MatchBehaviourHelper.Convert(_matchBehaviour, IsMatch(requestMessage)); return(requestMatchResult.AddScore(GetType(), score)); }
public void MatchBehaviourHelper_Convert_AcceptOnMatch() { Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.0)).IsEqualTo(0.0); Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 0.5)).IsEqualTo(0.5); Check.That(MatchBehaviourHelper.Convert(MatchBehaviour.AcceptOnMatch, 1.0)).IsEqualTo(1.0); }