public bool IsMatch(Dictionary <string, MatchingRule> ruleset, Dictionary <string, object> expected, Dictionary <string, object> actual, PactLogBuilder log) { var finder = new RuleFinder(); var match = true; foreach (var expectedKey in expected.Keys) { if (!actual.ContainsKey(expectedKey)) { match = false; log.NotFound(expectedKey); } else { var expectedValue = expected[expectedKey]; var actualValue = actual[expectedKey]; var rule = finder.FindRule(expectedKey, ruleset); if (!IsMatch(rule, expectedValue, actualValue)) { match = false; log.Unmatched(expectedValue, actualValue, rule); } } } return(match); }
private bool Compare(PactResponse expectations, HttpResponseMessage actual, PactLogBuilder log) { var success = true; if (expectations.Status != 0) { if ((int)actual.StatusCode != expectations.Status) { log.Unmatched(expectations.Status, actual.StatusCode); success = false; } } var ruleSet = expectations.MatchingRules ?? new Dictionary <string, MatchingRule>(); success &= VerifyHeaders(ruleSet, expectations.Headers, actual.Headers, log); success &= VerifyBodies(ruleSet, expectations.Body, actual.Content, log); return(success); }