Esempio n. 1
0
        public void EnsureTheThingHonorsPactWithConsumer()
        {
            // arrange
            const string serviceUri = "http://*****:*****@"C:\temp\pact\pactDir\pactconsumer-pactproducer.json")
                .Verify();
            }
        }
Esempio n. 2
0
        private void VerifyPactWithConsumer(JToken consumer, string pactUrl, string serviceUri)
        {
            //we need to instantiate one pact verifier for each consumer

            var config = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    _output
                }
            };

            PactUriOptions pactUriOptions = null;

            if (!string.IsNullOrEmpty(_configuration.PactBrokerUsername))
            {
                pactUriOptions = new PactUriOptions(_configuration.PactBrokerUsername, _configuration.PactBrokerPassword);
            }

            var pactUri      = new Uri(new Uri(_configuration.PactBrokerUri), pactUrl);
            var pactVerifier = new PactVerifier(config);

            pactVerifier
            .ProviderState($"{serviceUri}/provider-states")
            .ServiceProvider(_configuration.ProviderName, serviceUri)
            .HonoursPactWith(consumer.ToString())
            .PactUri(pactUri.AbsoluteUri, pactUriOptions)
            .Verify();
        }
Esempio n. 3
0
        public void EnsureProviderApiHonoursPactWithConsumer()
        {
            // Arrange
            config = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_outputHelper)
                },


                Verbose = true
            };
            config.CustomHeader = new KeyValuePair <string, string>("X-Clarksons-Security-Cloud", "UqkejnjkHNM5gPY4VKeLNeoNv2eLUvZL8Di1xDqjc/I1dvdcQO9EGeUg6wYR0+ta+218kbu5Z5GgodKF92WmuGyTZGZ600fAS0OPKZ2kXIiwwqVO+a2apqxIOYLLrJdOFGkw6h6pZ8NurSQdQYvavA==");


            //Act / Assert
            pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("fixture_api", _providerUri)
            .HonoursPactWith("EventAPIConsumer")
            .PactUri(@"http://104.214.219.231/pacts/provider/OperationServices/consumer/EventAPIConsumer/latest");
            pactVerifier.Verify();
        }
        public async Task HonourPactWithSpyLens()
        {
            var baseAddress = $"http://*****:*****@"c:\\git\\pacts\\spylens_frontend-spymaster_api.json")
            .Verify();
            await webHost.StopAsync();
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            var outputter = new CustomOutputter();
            var config    = new PactVerifierConfig();

            config.ReportOutputters.Add(outputter);
            IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { }, config);

            pactVerifier.ProviderState("Get user with id '1'");
            _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            _httpClient.BaseAddress = new System.Uri("http://*****:*****@"\Pact\{0}-{1}.json", ClientName, ProviderName))
            .Verify();


            // Assert
            outputter.Should().NotBeNull();
            outputter.Output.Should().NotBeNullOrWhiteSpace();
            outputter.Output.Should().Contain(string.Format("Verifying a Pact between {0} and {1}", ClientName, ProviderName));
            outputter.Output.Should().Contain("status code 200");
            System.Console.ReadLine();
        }
        public void EnsurePassengersApiHonoursPactWithFlightsApi()
        {
            //Arrange
            var config = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(output)
                },
                Verbose         = true,
                ProviderVersion = "0.0.1"
            };

            const string providerUrl = "http://localhost:5001";

            WebHost.CreateDefaultBuilder(new string[0])
            .UseStartup <TestStartup>()
            .UseUrls(providerUrl)
            .Build().Start();

            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier
            .ProviderState($"{providerUrl}/provider-states")
            .ServiceProvider("PassengersApi", providerUrl)
            .HonoursPactWith("FlightsApi")
            .PactUri("..\\..\\..\\..\\..\\PactExample.FlightsApi\\FlightsApiTests\\pacts\\flightsapi-passengersapi.json")
            .Verify();
        }
        public async Task HonourPactWithSpyLens()
        {
            var baseAddress = $"http://*****:*****@"http://localhost:8082/pacts/provider/SpyMaster%20Api/consumer/SpyLens%20JS%20Frontend/latest")
            .Verify();
            await webHost.StopAsync();
        }
Esempio n. 8
0
        public void EnsureProviderApiHonoursPactWithConsumer()
        {
            // Arrange
            var config = new PactVerifierConfig
            {
                // NOTE: We default to using a ConsoleOutput,
                // however xUnit 2 does not capture the console output,
                // so a custom outputter is required.
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_outputHelper)
                },

                // Output verbose verification logs to the test output
                Verbose = true,
                PublishVerificationResults = true,
                ProviderVersion            = "2.4.1-f3842db9e603d7",
            };

            //Act / Assert
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("Provider", _providerUri)
            .HonoursPactWith("Consumer")
            .PactBroker("https://dius.pact.dius.com.au",
                        uriOptions: new PactUriOptions(System.Environment.GetEnvironmentVariable("PACT_BROKER_TOKEN")),
                        consumerVersionTags: new List <string> {
                "master"
            })
            .Verify();
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        public void EnsureEventApiHonoursPactWithConsumer()
        {
            //Arrange
            var outputter = new CustomOutputter();
            var config    = new PactVerifierConfig();

            config.ReportOutputters.Add(outputter);
            IPactVerifier pactVerifier = new PactVerifier(() => {}, () => {}, config);

            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);

            _server = TestServer.Create(app =>
            {
                app.Use(typeof(AuthorizationTokenReplacementMiddleware), app.CreateDataProtector(typeof(OAuthAuthorizationServerMiddleware).Namespace, "Access_Token", "v1"));
                var apiStartup = new Startup();
                apiStartup.Configuration(app);
            });

            //Act / Assert
            pactVerifier
            .ServiceProvider("Event API", _server.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", outputter.Output);
        }
Esempio n. 11
0
        public void EnsureProviderApiHonorsPactWithWebUi()
        {
            // Arrange
            var config = new PactVerifierConfig
            {
                // NOTE: We default to using a ConsoleOutput,
                // however xUnit 2 does not capture the console output,
                // so a custom outputter is required.
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_outputHelper)
                },

                // Output verbose verification logs to the test output
                Verbose = true
            };

            //Act / Assert
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("webapi", _providerUri)
            .HonoursPactWith("webapp")
            //TODO: common location (publish to pact broker)
            .PactUri(@"..\..\..\..\..\pacts\webapp-webapi.json")
            .Verify();
        }
Esempio n. 12
0
        public void EnsureCarApiHonoursPactWithConsumer()
        {
            //Arrange
            const string serviceUri = "http://localhost:9222";
            var          config     = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_output)
                }
            };

            using (WebApp.Start <TestStartup>(serviceUri))
            {
                //Act / Assert
                IPactVerifier pactVerifier = new PactVerifier(config);
                pactVerifier
                .ProviderState($"{serviceUri}/provider-states")
                .ServiceProvider("Car API", serviceUri)
                .HonoursPactWith("Car API Consumer")
                //.PactUri($"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}Consumer.Tests{Path.DirectorySeparatorChar}pacts{Path.DirectorySeparatorChar}car_api_consumer-car_api.json")
                .PactUri("http://localhost/pacts/provider/Car%20API/consumer/Car%20API%20Consumer/latest")
                .Verify();
            }
        }
Esempio n. 13
0
        public void EnsureEventApiHonoursPactWithConsumer()
        {
            if (!File.Exists(".\\pact\\bin\\pact-provider-verifier.bat"))
            {
                throw new Exception("Please run '.\\Build\\Download-Standalone-Core.ps1' from the project root to download the standalone provider verifier, then 'Clean' and 'Rebuild' the solution.");
            }

            //Arrange
            const string serviceUri = "http://localhost:9222";
            var          config     = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_output)
                }
            };

            using (WebApp.Start <TestStartup>(serviceUri))
            {
                //Act / Assert
                IPactVerifier pactVerifier = new PactVerifier(config);
                pactVerifier
                .ProviderState($"{serviceUri}/provider-states")
                .ServiceProvider("Event API", serviceUri)
                .HonoursPactWith("Event API Consumer")
                .PactUri("..\\..\\..\\Consumer.Tests\\pacts\\event_api_consumer-event_api.json")
                .Verify();
            }
        }
Esempio n. 14
0
        public void EnsureConsumerHonoursPactWithpPact1Consumer()
        {
            //Arrange
            var config = new PactVerifierConfig();

            config.ReportOutputters.Clear();
            config.ReportOutputters.Add(new ConsoleOutputter(_output));

            var pactVerifier = new PactVerifier(() => { }, () => { }, config);

            pactVerifier
            .ProviderState("No subject with id '8' exists")
            .ProviderState("Subject with id '1' exists")
            .ProviderState("Creating new product")
            ;
            //Act / Assert
            using (var testServer = TestServer.Create <TestStartup>()) {
                testServer.BaseAddress = new Uri("http://localhost");
                pactVerifier
                .ServiceProvider("Something API", testServer.HttpClient)
                .HonoursPactWith("customerservice")
                .PactUri($@"..\..\..\UnitTestProject\pacts\pact1consumer-pactproducer.json")
                .Verify();     //NOTE: Optionally you can control what interactions are verified by specifying a providerDescription and/or providerState
            }
        }
Esempio n. 15
0
        public void VerifyAllHealthCheckPacts()
        {
            // Arrange
            IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { });

            var pactDetails = new PactDetails()
            {
                Provider = new Pacticipant {
                    Name = PactConstants.PactProviderNames.SqsPocApi
                },
                Consumer = new Pacticipant {
                    Name = PactConstants.PactConsumerNames.Product
                }
            };
            var pactLocation = $"{ PactConstants.PactRootLocation }\\{ PactConstants.PactProviderNames.SqsPocApi }\\{ PactConstants.PactConsumerNames.Product }\\{ pactDetails.GeneratePactFileName() }";

            pactVerifier
            .ProviderState("The service is up and running and all dependencies are available")
            .ProviderState("The service is up and running and some dependencies are not available", SetupDependenciesNotAvailable);

            // Act & Assert
            using (var testServer = TestServer.Create <Startup>()) //NOTE: This is using the Microsoft.Owin.Testing to test host an owin app :)
            {
                pactVerifier = pactVerifier
                               .ServiceProvider(pactDetails.Provider.Name, testServer.HttpClient)
                               .HonoursPactWith(pactDetails.Consumer.Name)
                               .PactUri(pactLocation);

                pactVerifier.Verify("A request for the status");
            }
        }
Esempio n. 16
0
        public void DoTest()
        {
            var config = new PactVerifierConfig
            {
                // NOTE: We default to using a ConsoleOutput,
                // however xUnit 2 does not capture the console output,
                // so a custom outputter is required.
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_outputHelper)
                },

                // Output verbose verification logs to the test output
                Verbose = true
            };

            //Act / Assert
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("Provider", _providerUri)
            .HonoursPactWith("Consumer")
            .PactUri(@"..\..\..\..\..\pacts\consumer-provider.json")
            .Verify();
        }
Esempio n. 17
0
        public void EnsureProductApiHonoursPactWithConsumer()
        {
            //Arrange
            const string serviceUri = "http://localhost:13607";
            var          config     = new PactVerifierConfig
            {
                Outputters = new List <IOutput>
                {
                    new CustomOutput(_output)
                }
            };
            var webHostBuilder = new WebHostBuilder()
                                 .UseStartup <TestStartup>();

            using (var server = new TestServer(webHostBuilder))
            {
                //var response = server.CreateRequest($"{serviceUri}/product/productlist")
                //    .SendAsync("GET");

                //Act / Assert
                IPactVerifier pactVerifier = new PactVerifier(config);
                pactVerifier
                .ProviderState($"{serviceUri}/echo/status")
                .ServiceProvider("Product API", serviceUri)
                .HonoursPactWith("Product API Consumer")
                .PactUri($"..//consumer - driven - test//Provider//FlixOne.BookStore.ProductService.Test//pacts//product_api_consumer-product_api")
                //.PactUri($"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}FlixOne.BookStore.ProductService.Test{Path.DirectorySeparatorChar}pacts{Path.DirectorySeparatorChar}product_api_consumer.json")
                .Verify();
            }
        }
        public void EnsureProviderApiHonoursPactWithConsumer()
        {
            // Arrange
            var config = new PactVerifierConfig
            {
                // NOTE: We default to using a ConsoleOutput,
                // however xUnit 2 does not capture the console output,
                // so a custom outputter is required.
                Outputters = new List <IOutput>
                {
                    new XUnitOutput(_outputHelper)
                },

                // Output verbose verification logs to the test output
                Verbose = true
            };

            //Act / Assert
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/")
            .ServiceProvider("Provider", _providerUri)
            .HonoursPactWith("Consumer")
            .PactUri(@"..\..\..\..\..\pacts\consumer-provider.json")
            .Verify(description: "A invalid GET request for Date Validation with empty string date parameter"
                    , providerState: String.Empty);
        }
Esempio n. 19
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();
            }
        }
Esempio n. 20
0
        public void VerifyPactsWithMySelf()
        {
            //Act / Assert
            IPactVerifier pactVerifier = new PactVerifier(_config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("Self sample API", _providerUri)
            .HonoursPactWith("ServiceName")
            .PactUri("http://localhost:9292/pacts/provider/Self%20sample%20API/consumer/ServiceName/latest")
            .Verify();
        }
Esempio n. 21
0
        //This verifies the pact and .Verify() publishes the results back to the broker (specified in .PactUri())
        private void VerifyPactFor(string consumerName, PactVerifierConfig config, PactUriOptions options)
        {
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier
            .ProviderState($"{ProviderUri}/provider-states")
            .ServiceProvider(ProviderName, ProviderUri)
            .HonoursPactWith(consumerName)
            .PactUri($"{CreatePactUri(consumerName, ProviderName)}", options)
            .Verify();
        }
Esempio n. 22
0
        public void PactVerify()
        {
            const string  providerBaseUri = "http://localhost:5000";
            IPactVerifier pactVerifier    = new PactVerifier(new PactVerifierConfig());

            pactVerifier
            .ProviderState($"{providerBaseUri}{Constants.ProviderStateEndpoint}")
            .ServiceProvider("TodoApi", providerBaseUri)
            .HonoursPactWith("todo-web")
            .PactUri("/Users/psilpsakulsu/workspace/todo-web/pact/pacts/todo-web-todoapi.json")
            .Verify();
        }
Esempio n. 23
0
        public void EnsureProviderApiHonoursPactWithConsumer()
        {
            // Arrange
            PactVerifierConfig config = ConfigureCustomOutput();

            //Assert Pacts
            IPactVerifier pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{_pactServiceUri}/provider-states")
            .ServiceProvider("Provider", _pactServiceUri)
            .HonoursPactWith("Consumer")
            .PactUri(@"..\..\..\..\..\..\pacts\consumer-provider.json")
            .Verify();
        }
Esempio n. 24
0
        public void EnsurePricingApiHonoursPactWithEnergyProfile()
        {
            const string consumerServiceName = "sqa-conference-service";

            var pactUrl = string.Format(PactUrlTemplate, consumerServiceName);

            IPactVerifier pactVerifier = new PactVerifier(PactVerifierConfig);

            pactVerifier
            .ProviderState($"{PactMiddlewareServiceUrl}/provider-states")
            .ServiceProvider(ProviderName, ProviderUrl)
            .HonoursPactWith(consumerServiceName)
            .PactUri($"{PactBrokerUrl}{pactUrl}")
            .Verify(providerState: "There are speakers details available for speakers with id 1, 2 and 3");
        }
Esempio n. 25
0
 public async Task ExpectGetToReturnNonExistantPropertyGivesErrorMessage()
 {
     const string ServiceUri   = "http://localhost:9222";
     var          fetcher      = new FilePactFetcher("TestPacts/Test6.json");
     var          pactVerifier = new PactVerifier((condition, message) => Assert.False(condition, message), fetcher);
     await pactVerifier
     .ProviderState($"{ServiceUri}/provider-states")
     .ServiceProvider("theProvider", ServiceUri)
     .HonoursPactWith("theConsumer")
     .Verify(0, () =>
             new HttpClient(new FakeHandler(HttpStatusCode.OK))
     {
         BaseAddress = new System.Uri(ServiceUri)
     }
             );
 }
Esempio n. 26
0
 public async Task CompareEmptyWithNull()
 {
     const string ServiceUri   = "http://localhost:9222";
     var          fetcher      = new FilePactFetcher("TestPacts/Test3.json");
     var          pactVerifier = new PactVerifier((condition, message) => Assert.True(condition, message), fetcher);
     await pactVerifier
     .ProviderState($"{ServiceUri}/provider-states")
     .ServiceProvider("theProvider", ServiceUri)
     .HonoursPactWith("theConsumer")
     .Verify(0, () =>
             new HttpClient(new FakeHandler())
     {
         BaseAddress = new System.Uri(ServiceUri)
     }
             );
 }
Esempio n. 27
0
        public void EnsurePactDemoProviderHobnoursPactWithPactDemoConsumer()
        {
            var config = new PactVerifierConfig
            {
                Verbose = true
            };

            Console.WriteLine($"Current: {Environment.CurrentDirectory}");
            var pactVerifier = new PactVerifier(config);

            pactVerifier.ProviderState($"{pactServiceUri}/provider-states")
            .ServiceProvider("PactDemo.Provider", $"{providerServiceUri}")
            .HonoursPactWith("PactDemo.Consumer")
            .PactUri(@"..\..\..\..\..\pacts\pactdemo.consumer-pactdemo.provider.json")
            .Verify();
        }
        public void EnsureShipmentServiceHonorsPactWithOrderServiceConsumer()
        {
            string pactFileName       = "ordersservice-shipmentservice.json";
            string shipmentServiceUri = TestEnvironment.ShipmentServiceUri.ToString();

            using (ShipmentServiceTestServer.Create())
            {
                IPactVerifier pactVerifier = new PactVerifier(GetPactVerifierConfig());
                pactVerifier
                .ProviderState($"{shipmentServiceUri.TrimEnd('/')}{ShipmentServiceProviderStateMiddleware.ProviderStateRelativeUri}")
                .ServiceProvider("ShipmentService", shipmentServiceUri)
                .HonoursPactWith("OrdersService")
                .PactUri($"..\\..\\Pacts\\{pactFileName}")
                .Verify()
                ;
            }
        }
        public void EnsureTribbleApiHonoursGetTribbles()
        {
            //Arrange
            IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { }, _verifierConfig);

            pactVerifier.ProviderState("There is more than one tribble");
            var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "./pacts/consumer-tribble_api.json");

            using (var testServer = TestServer.Create <Startup>())
            {
                pactVerifier
                .ServiceProvider("Tribble API", testServer.HttpClient)
                .HonoursPactWith("Consumer")
                .PactUri(path)
                .Verify(null, "There is more than one tribble");
            }
        }
Esempio n. 30
0
        public void EnsureCardApiHonorsPactWithConsumer()
        {
            var           config       = new PactVerifierConfig();
            IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { }, config);

            pactVerifier
            .ProviderState("When card exists", setUp: DataSetup, tearDown: DataTearDown);

            using (var testServer = TestServer.Create <Startup>())
            {
                pactVerifier
                .ServiceProvider("Card Api", testServer.HttpClient)
                .HonoursPactWith("Consumer")
                .PactUri(@"D:\pacts\consumer-cards_api.json")
                .Verify();
            }
        }