internal Interaction(JObject i, ITransport transport, System.Func <string, Task> ensureProviderState) { this.transport = transport; this.ensureProviderState = ensureProviderState; description = i["description"]?.ToString() ?? ""; providerState = i["providerState"]?.ToString() ?? ""; request = transport.Format.DeserializeRequest(i["request"]); response = transport.Format.DeserializeResponse(i["response"]); matchers = i["matchingRules"] is JObject rules?MatcherParser.Parse(rules) : new IMatcher[0]; matchers = transport.Matchers.ResponseMatchers.Concat(matchers).ToArray(); }
public void V2Specs(string name, bool isRequest, JObject testCase) { var shouldMatch = (bool)testCase["match"]; var actual = testCase["actual"]; var expected = testCase["expected"]; Assert.Null(actual["matchingRules"]); var rulesJsonProperty = expected["matchingRules"]; var rules = new IMatcher[0]; if (rulesJsonProperty != null) { rules = MatcherParser.Parse(rulesJsonProperty as JObject); ((JObject)expected).Remove("matchingRules"); } var transportMatchers = new PactV2CompliantHttpTransportMatchers(); if (isRequest) { rules = transportMatchers.RequestMatchers.Concat(rules).ToArray(); } else { rules = transportMatchers.ResponseMatchers.Concat(rules).ToArray(); } var context = new MatchingContext(rules, isRequest); var matchChecker = new MatchChecker(); matchChecker.Matches(expected, actual, context); if (shouldMatch) { Assert.True(context.Result.Matches, name + ": " + context.Result.FailureReasons); } else { Assert.False(context.Result.Matches, name + ": did match although it shouldn't"); } }