예제 #1
0
        internal bool Matches(object request, ITransportMatchers transportMatchers)
        {
            var context = new MatchingContext(transportMatchers.RequestMatchers.Concat(requestMatchers).ToArray(), true);
            var checker = new MatchChecker();

            checker.Matches(this.request, request, context);
            return(context.Result.Matches);
        }
예제 #2
0
        public async Task <InteractionVerificationResult> Honour()
        {
            if (!string.IsNullOrEmpty(providerState))
            {
                await ensureProviderState(providerState);
            }

            var actualResponse = await transport.Respond(request);

            var context = new MatchingContext(matchers, false);
            var checker = new MatchChecker();

            var roundTrippedResponse = transport.Format.DeserializeResponse(transport.Format.SerializeResponse(actualResponse));

            checker.Matches(response, roundTrippedResponse, context);

            return(new InteractionVerificationResult(description, context.Result.Matches, context.Result.FailureReasons));
        }
예제 #3
0
        public object Respond(object request, ITransportMatchers transportMatchers)
        {
            var response = responseFactory(request);

            var expectedResponse = responseFactory(this.request);

            var context = new MatchingContext(transportMatchers.ResponseMatchers.Concat(responseMatchers).ToArray(), false);
            var checker = new MatchChecker();

            checker.Matches(expectedResponse, response, context);
            if (!context.Result.Matches)
            {
                throw new Exception("Invalid interaction setup - the generated response does not match the expected format: " + context.Result.FailureReasons);
            }

            CallCount++;

            return(response);
        }
예제 #4
0
        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");
            }
        }