public void EnsureEventApiHonoursPactWithConsumer()
        {
            string output = string.Empty;

            //Arrange
            IPactVerifier pactVerifier = new PactVerifier(() => {}, () => {}, new PactVerifierConfig
            {
                Reporters = new List<Action<string>>
                {
                    x => output += x
                }
            });

            pactVerifier
                .ProviderState(
                    "there are events with ids '45D80D13-D5A2-48D7-8353-CBB4C0EAABF5', '83F9262F-28F1-4703-AB1A-8CFD9E8249C9' and '3E83A96B-2A0C-49B1-9959-26DF23F83AEB'",
                    setUp: InsertEventsIntoDatabase)
                .ProviderState("there is an event with id '83f9262f-28f1-4703-ab1a-8cfd9e8249c9'",
                    setUp: InsertEventIntoDatabase)
                .ProviderState("there is one event with type 'DetailsView'",
                    setUp: EnsureOneDetailsViewEventExists);

            //Act / Assert
            using (var testServer = TestServer.Create<Startup>())
            {
                pactVerifier
                   .ServiceProvider("Event API", testServer.HttpClient)
                   .HonoursPactWith("Consumer")
                   .PactUri("../../../Consumer.Tests/pacts/consumer-event_api.json")
                   .Verify();
            }

            // Verify that verifaction log is also sent to additional reporters defined in the config
            Assert.Contains("Verifying a Pact between Consumer and Event API", output);
        }
        public void EnsureHobbitApiHonoursPactWithConsumer()
        {
            IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { });

            pactVerifier
                .ProviderState("There are hobbits");

            using (var client = new HttpClient { BaseAddress = _serviceUrl })
            {
                pactVerifier
                    .ServiceProvider("Hobbit API", client)
                    .HonoursPactWith("Consumer")
                    .PactUri("../../pacts/consumer-hobbit_api.json")
                    .Verify();
            }
        }
예제 #3
0
        public void EnsureCustomerApiHonoursPactWithConsumer()
        {
            IPactVerifier pactVerifier = new PactVerifier(SetUp(), TearDown());
            pactVerifier.ProviderState("There is a customer with ID tester", setUp: AddTesterIfItDoesntExist);
            pactVerifier.ProviderState("Version is 1.2.3.4", setUp: SetVersion);

            using (var testServer = TestServer.Create<Startup>())
            {
                pactVerifier = pactVerifier
                    .ServiceProvider("Customer API", testServer.HttpClient)
                    .HonoursPactWith("Consumer")
                    .PactUri("../../../BinaryMash.PactDemo.Consumer.Tests/pacts/consumer-customer_api.json");

                pactVerifier.Verify();
            }
        }
예제 #4
0
        public void EnsureEventApiHonoursPactWithConsumer()
        {
            //Arrange
            IPactVerifier pactVerifier = new PactVerifier(() => {}, () => {});

            pactVerifier
                .ProviderState(
                    "there are events with ids '45D80D13-D5A2-48D7-8353-CBB4C0EAABF5', '83F9262F-28F1-4703-AB1A-8CFD9E8249C9' and '3E83A96B-2A0C-49B1-9959-26DF23F83AEB'",
                    setUp: InsertEventsIntoDatabase)
                .ProviderState("there is an event with id '83f9262f-28f1-4703-ab1a-8cfd9e8249c9'",
                    setUp: InsertEventIntoDatabase)
                .ProviderState("there is one event with type 'DetailsView'",
                    setUp: EnsureOneDetailsViewEventExists);

            //Act / Assert
            using (var testServer = TestServer.Create<Startup>())
            {
                pactVerifier
                   .ServiceProvider("Event API", testServer.HttpClient)
                   .HonoursPactWith("Consumer")
                   .PactUri("../../../Consumer.Tests/pacts/consumer-event_api.json")
                   .Verify();
            }
        }
예제 #5
0
        public void EnsureApiHonoursPactWithClient()
        {
            var pactVerifier = new PactVerifier(() =>
            {
                this.DeleteDatabase("BrokerDb");
            }, () =>
            {
                this.DeleteDatabase("BrokerDb");
            });

            pactVerifier
                .ProviderState("there is a name specified")
                .ProviderState("there is no name specified");

            Exception exception = null;

            try
            {
                using (var testServer = TestServer.Create(app =>
                {
                    var config = new HttpConfiguration();

                    WebApiConfig.Register(config);
                    AutofacConfig.Register(config, builder =>
                    {

                    });

                    app.UseWebApi(config);
                }))
                {
                    pactVerifier
                        .ServiceProvider("Broker.Api", testServer.HttpClient)
                        .HonoursPactWith("Broker.Client")
                        .PactUri("https://pact.mikesoft.com.au/pact/provider/Broker.Api/consumer/Broker.Client/version/latest").Verify();
                }
            }
            catch (Exception e)
            {
                exception = e;
            }

            exception.Should().BeNull();
        }
        public void EnsureSomethingApiHonoursPactWithConsumer()
        {
            var stringBuilder = new StringBuilder();
            Console.SetOut(new StringWriter(stringBuilder));

            var pactVerifier = new PactVerifier(() =>
            {
                this.sampleRepository.ClearProducts();
                this.sampleRepository.GetProductCount().Should().Be(0);
            }, () =>
            {

            });

            pactVerifier
                .ProviderState("there is a valid product",
                    tearDown: () =>
                    {
                        this.sampleRepository.GetProductCount().Should().Be(1);
                        this.sampleRepository.GetProducts().Any(x => x.ID == 4).Should().Be(true);
                    })
                .ProviderState("there is a valid product id",
                    setUp: () =>
                    {
                        this.sampleRepository.AddProduct(new Product { ID = 1, Name = "One" });
                    })
                .ProviderState("there is a valid product to be deleted",
                    setUp: () =>
                    {
                        this.sampleRepository.AddProduct(new Product { ID = 5, Name = "Five" });
                    },
                    tearDown: () =>
                    {
                        this.sampleRepository.GetProductCount().Should().Be(0);
                    })
                .ProviderState("there is an invalid product id")
                .ProviderState("there is no name specified")
                .ProviderState("there is a name specified");

            Exception exception = null;

            try
            {
                using (var testServer = TestServer.Create(app =>
                {
                    var startup = new Startup();
                    startup.Configuration(app, SetupContainer);
                }))
                {
                    pactVerifier
                        .ServiceProvider("SampleProject.Provider", testServer.HttpClient)
                        .HonoursPactWith("SampleProject.Consumer")
                        .PactUri("../../../SampleProject.ConsumerPacts/pacts/sampleproject.consumer-sampleproject.provider.json")
                        .Verify();
                }
            }
            catch (Exception e)
            {
                exception = e;
            }

            File.WriteAllText(@"SampleProject.ProviderPacts.ProviderToConsumerPactTests.txt", stringBuilder.ToString());

            exception.Should().BeNull();
        }