Example #1
0
 public HttpTransport(HttpClient httpClient, IPayloadFormat payloadFormat, ITransportMatchers matchers = null)
 {
     Format             = new HttpTransportFormat(payloadFormat);
     Matchers           = matchers ?? new HttpTransportMatchers();
     this.httpClient    = httpClient;
     this.payloadFormat = payloadFormat;
 }
Example #2
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);
        }
Example #3
0
        public Interaction GetMatchingInteraction(object request, ITransportMatchers transportMatchers)
        {
            var matchingInteractions = interactions.Where(i => i.Matches(request, transportMatchers)).ToArray();

            if (matchingInteractions.Length == 0)
            {
                throw new Exception("No matching interaction was found");
            }

            if (matchingInteractions.Length > 1)
            {
                throw new Exception("More than 1 matching interactions where found");
            }

            return(matchingInteractions.Single());
        }
Example #4
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);
        }
Example #5
0
 public CallbackTransport(ITransportFormat transportFormat, Func <object, Task <object> > callback, ITransportMatchers matchers = null)
 {
     Format        = transportFormat;
     Matchers      = matchers ?? new NoTransportMatchers();
     this.callback = callback;
 }
Example #6
0
 public HttpMockServer(Pact pact, IPayloadFormat payloadFormat, ITransportMatchers transportMatchers)
 {
     this.pact              = pact;
     this.payloadFormat     = payloadFormat;
     this.transportMatchers = transportMatchers;
 }
Example #7
0
 public CallbacksMockServer(Pact pact, ITransportMatchers matchers = null)
 {
     this.pact     = pact;
     this.matchers = matchers ?? new NoTransportMatchers();
 }