public void GetMatchingInteraction_WithInteractionsNull_ThrowsArgumentException() { var context = new NancyContext(); context.Items[PactMockInteractionsKey] = null; Assert.Throws<ArgumentException>(() => context.GetMatchingInteraction(HttpVerb.Get, "/events")); }
public void GetMatchingInteraction_WithNoMatchingInteraction_ThrowsArgumentException() { var interactions = new List<ProviderServiceInteraction> { new ProviderServiceInteraction { Request = new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/hello" }, Response = new ProviderServiceResponse()} }; var context = new NancyContext(); context.SetMockInteraction(interactions); Assert.Throws<ArgumentException>(() => context.GetMatchingInteraction(HttpVerb.Get, "/events")); }
public void GetMatchingInteraction_WithOneMatchingInteraction_ReturnsInteraction() { var interactions = new List<ProviderServiceInteraction> { new ProviderServiceInteraction { Request = new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/events" }, Response = new ProviderServiceResponse()}, new ProviderServiceInteraction { Request = new ProviderServiceRequest { Method = HttpVerb.Post, Path = "/events" }, Response = new ProviderServiceResponse()}, }; var context = new NancyContext(); context.SetMockInteraction(interactions); var result = context.GetMatchingInteraction(HttpVerb.Get, "/events"); Assert.Equal(interactions.First(), result); }
private Response HandlePactRequest(NancyContext context) { var actualRequest = _requestMapper.Convert(context.Request); var matchingInteraction = context.GetMatchingInteraction(actualRequest.Method, actualRequest.Path); matchingInteraction.IncrementUsage(); _requestComparer.Compare(matchingInteraction.Request, actualRequest); return _responseMapper.Convert(matchingInteraction.Response); }
public void GetMatchingInteraction_WithNoInteractions_ThrowsInvalidOperationException() { var context = new NancyContext(); Assert.Throws<InvalidOperationException>(() => context.GetMatchingInteraction(HttpVerb.Get, "/events")); }