예제 #1
0
        /// <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);
        }
예제 #2
0
 public MockProviderServiceStartup(IRequestResponseMatcher matcher)
 {
     _matcher = matcher;
 }