Beispiel #1
0
        public void Handle_WithNancyContext_ConvertIsCalledOnThProviderServiceRequestMapper()
        {
            var expectedRequest = new ProviderServiceRequest
            {
                Method = HttpVerb.Get,
                Path   = "/"
            };
            var expectedResponse = new ProviderServiceResponse();
            var nancyContext     = new NancyContext
            {
                Request = new Request("GET", "/", "HTTP")
            };
            var handler = GetSubject();

            _mockRequestMapper.Convert(nancyContext.Request).Returns(expectedRequest);

            var interaction = new ProviderServiceInteraction {
                Request = expectedRequest, Response = expectedResponse
            };

            _mockProviderRepository.GetMatchingTestScopedInteraction(expectedRequest)
            .Returns(interaction);

            handler.Handle(nancyContext);

            _mockRequestMapper.Received(1).Convert(nancyContext.Request);
        }
        private Response HandlePactRequest(NancyContext context)
        {
            var actualRequest       = _requestMapper.Convert(context.Request);
            var actualRequestMethod = actualRequest.Method.ToString().ToUpperInvariant();
            var actualRequestPath   = actualRequest.Path;

            _log.InfoFormat("Received request {0} {1}", actualRequestMethod, actualRequestPath);
            _log.Debug(JsonConvert.SerializeObject(actualRequest, JsonConfig.PactFileSerializerSettings));

            ProviderServiceInteraction matchingInteraction;

            try
            {
                matchingInteraction = _mockProviderRepository.GetMatchingTestScopedInteraction(actualRequest);
                _mockProviderRepository.AddHandledRequest(new HandledRequest(actualRequest, matchingInteraction));

                _log.InfoFormat("Found matching response for {0} {1}", actualRequestMethod, actualRequestPath);
                _log.Debug(JsonConvert.SerializeObject(matchingInteraction.Response, JsonConfig.PactFileSerializerSettings));
            }
            catch (Exception)
            {
                _log.ErrorFormat("No matching interaction found for {0} {1}", actualRequestMethod, actualRequestPath);
                _mockProviderRepository.AddHandledRequest(new HandledRequest(actualRequest, null));
                throw;
            }

            return(_responseMapper.Convert(matchingInteraction.Response));
        }
        private Response HandlePactRequest(NancyContext context)
        {
            var actualRequest = _requestMapper.Convert(context.Request);

            var matchingInteraction = _mockProviderRepository.GetMatchingTestScopedInteraction(actualRequest);

            _mockProviderRepository.AddHandledRequest(new HandledRequest(actualRequest, matchingInteraction));

            return(_responseMapper.Convert(matchingInteraction.Response));
        }