public void ShoudlNotBeAbleToAddInteractionThatIsNotDistinguishableFromExisting() { var interaction = new Interaction { Request = new Request { Path = "/test" } }; var differentInteraction = new Interaction { Request = new Request { Path = "/test" } }; var list = new MatchableInteractionList { new MatchableInteraction(interaction) }; try { list.AddUnique(new MatchableInteraction(differentInteraction)); } catch (PactException e) { Assert.AreEqual("Cannot add multiple interactions with the same provider states and requests. " + "The provider will not be able to distinguish between them.", e.Message); throw; } }
/// <summary> /// Sets up a mock provider service, generates a V3 contract between a consumer and provider, /// writes the contract to disk and optionally publishes to a Pact Broker using the supplied client. /// </summary> /// <param name="consumer">Name of consuming party of the contract.</param> /// <param name="provider">Name of the providing party of the contract.</param> /// <param name="mockProviderServiceBaseUri">URL where you will call the mock provider service to verify your consumer.</param> /// <param name="pactPublisher">If not supplied the contract will not be published.</param> /// <param name="pactDir">Directory where the generated pact file will be written to. Defaults to the current project directory.</param> public PactBuilder(string consumer, string provider, string mockProviderServiceBaseUri, PactPublisher pactPublisher = null, string pactDir = null) { if (mockProviderServiceBaseUri is null) { throw new System.ArgumentNullException(nameof(mockProviderServiceBaseUri)); } _pactDir = pactDir; _pactPublisher = pactPublisher; _cts = new CancellationTokenSource(); _consumer = consumer ?? throw new System.ArgumentNullException(nameof(consumer)); _provider = provider ?? throw new System.ArgumentNullException(nameof(provider)); _matchableInteractions = new MatchableInteractionList(); _matcher = new RequestResponseMatcher(_matchableInteractions); var host = WebHost.CreateDefaultBuilder() .UseKestrel() .UseUrls(mockProviderServiceBaseUri) .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(_matcher); }) .UseStartup <MockProviderServiceStartup>() .Build(); host.RunAsync(_cts.Token); }
public void ShoudlBeAbleToAddUniqueInteraction() { var interaction = new Interaction(); var differentInteraction = new Interaction { Request = new Request { Path = "/test" } }; var list = new MatchableInteractionList { new MatchableInteraction(interaction) }; list.AddUnique(new MatchableInteraction(differentInteraction)); Assert.AreEqual(2, list.Count); }
public void ShoudlBeAbleToAddInteractionWithSameRequestIfProviderStateIsDifferent() { var interaction = new Interaction(); var differentInteraction = new Interaction { ProviderStates = new List <ProviderState> { new ProviderState { Name = "some state" } } }; var list = new MatchableInteractionList { new MatchableInteraction(interaction) }; list.AddUnique(new MatchableInteraction(differentInteraction)); Assert.AreEqual(2, list.Count); }
internal PactBuilderBase(string consumer, string provider, string mockProviderServiceBaseUri, PactPublisher pactPublisher = null, string pactDir = null) { if (mockProviderServiceBaseUri is null) { throw new System.ArgumentNullException(nameof(mockProviderServiceBaseUri)); } _pactDir = pactDir; _pactPublisher = pactPublisher; _cts = new CancellationTokenSource(); _consumer = consumer ?? throw new System.ArgumentNullException(nameof(consumer)); _provider = provider ?? throw new System.ArgumentNullException(nameof(provider)); MatchableInteractions = new MatchableInteractionList(); _matcher = new RequestResponseMatcher(MatchableInteractions); ProviderWebHost.Run(mockProviderServiceBaseUri, _matcher, _cts); }
internal void ClearMatchableInteractions() { MatchableInteractions = new MatchableInteractionList(); }
public void ClearInteractions() { _matchableInteractions = new MatchableInteractionList(); }
public void ClearInteractions() { _interactions = new List <Interaction>(); _matchableInteractions = new MatchableInteractionList(); }