public HttpTransport(HttpClient httpClient, IPayloadFormat payloadFormat, ITransportMatchers matchers = null) { Format = new HttpTransportFormat(payloadFormat); Matchers = matchers ?? new HttpTransportMatchers(); this.httpClient = httpClient; this.payloadFormat = payloadFormat; }
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); }
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()); }
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); }
public CallbackTransport(ITransportFormat transportFormat, Func <object, Task <object> > callback, ITransportMatchers matchers = null) { Format = transportFormat; Matchers = matchers ?? new NoTransportMatchers(); this.callback = callback; }
public HttpMockServer(Pact pact, IPayloadFormat payloadFormat, ITransportMatchers transportMatchers) { this.pact = pact; this.payloadFormat = payloadFormat; this.transportMatchers = transportMatchers; }
public CallbacksMockServer(Pact pact, ITransportMatchers matchers = null) { this.pact = pact; this.matchers = matchers ?? new NoTransportMatchers(); }