public void Verify_WithProviderStateSet_CallsProviderServiceValidatorWithProviderState() { var httpClient = new HttpClient(); var mockFileSystem = Substitute.For<IFileSystem>(); var mockPactProviderServiceValidator = Substitute.For<IProviderServiceValidator>(); mockFileSystem.File.ReadAllText(Arg.Any<string>()).Returns("{}"); var pactVerifier = new PactVerifier(mockFileSystem, client => mockPactProviderServiceValidator); pactVerifier.ProviderStatesFor("My client") .ProviderState("My Provider State") .ProviderState("My Provider State 2"); pactVerifier.ServiceProvider("Event API", httpClient) .HonoursPactWith("My client") .PactUri("/test.json"); pactVerifier.Verify(); mockPactProviderServiceValidator.Received(1).Validate( Arg.Any<ProviderServicePactFile>(), pactVerifier.ProviderStates); }
public void Verify_WithDescriptionAndProviderState_CallsProviderServiceValidatorWith1FilteredInteractions() { var description = "My Description"; var providerState = "My Provider State"; var pactUri = "../../../Consumer.Tests/pacts/my_client-event_api.json"; var pactFileJson = "{ \"provider\": { \"name\": \"Event API\" }, \"consumer\": { \"name\": \"My client\" }, \"interactions\": [{ \"description\": \"My Description\", \"provider_state\": \"My Provider State\" }, { \"description\": \"My Description 2\", \"provider_state\": \"My Provider State\" }, { \"description\": \"My Description\", \"provider_state\": \"My Provider State 2\" }], \"metadata\": { \"pactSpecificationVersion\": \"1.0.0\" } }"; var httpClient = new HttpClient(); var mockFileSystem = Substitute.For <IFileSystem>(); var mockPactProviderServiceValidator = Substitute.For <IProviderServiceValidator>(); mockFileSystem.File.ReadAllText(pactUri).Returns(pactFileJson); var pactVerifier = new PactVerifier(mockFileSystem, client => mockPactProviderServiceValidator); pactVerifier.ProviderStatesFor("My client") .ProviderState("My Provider State") .ProviderState("My Provider State 2"); pactVerifier.ServiceProvider("Event API", httpClient) .HonoursPactWith("My client") .PactUri(pactUri); pactVerifier.Verify(providerDescription: description, providerState: providerState); mockPactProviderServiceValidator.Received(1).Validate( Arg.Is <ProviderServicePactFile>(x => x.Interactions.Count() == 1 && x.Interactions.All(i => i.ProviderState.Equals(providerState) && i.Description.Equals(description))), Arg.Any <ProviderStates>()); }
public void EnsureEventApiHonoursPactWithConsumer() { var config = new PactVerifierConfig { PublishVerificationResults = true, ProviderVersion = "1.0.1", Outputters = new List <IOutput> { new XUnitOutput(_output) } }; Program.CreateWebHostBuilder(Array.Empty <string>()) .UseUrls("http://localhost:9000") .Build() .Start(); //Act / Assert IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("PaymentsApi", "http://localhost:9000") .HonoursPactWith("BookingsApi") .PactUri("http://localhost:9292/pacts/provider/PaymentsApi/consumer/BookingsApi/latest") .Verify(); }
public void EnsureDinkumCoinApiHonoursPactWithConsumer() { //Arrange const string baseUrl = "http://localhost:9011"; var fixture = new TestServerFixture(); var config = new PactVerifierConfig { Outputters = new List <IOutput> { new XUnitOutput(_output) }, Verbose = true }; using (IWebHost webHost = fixture.CreateWebHost(baseUrl)) { webHost.Start(); IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier // .ProviderState($"{serviceUri}/provider-states") .ServiceProvider("dinkum-coin-api", baseUrl) .HonoursPactWith("dinkum-coin-web") .PactUri($"pacts/dinkum-coin-web-dinkum-coin-api.json") .Verify(); } }
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"); } }
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); }
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 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 EnsureUserApiHonoursPactWithBilling() { // 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($"{PactUri}/provider-states"); pactVerifier .ServiceProvider(ProviderName, ProviderUri) .HonoursPactWith(Consumer) .PactUri($@"C:\Users\chandan.vasishta\source\repos\User.Solution\Pacts\{Consumer}-{ProviderName}.json") ////or //.PactUri("http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest") //You can specify a http or https uri ////or //.PactUri("http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest", new PactUriOptions("someuser", "somepassword")) //You can also specify http/https basic auth details ////or //.PactUri("http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest", new PactUriOptions("sometoken")) //Or a bearer token ////or (if you're using the Pact Broker, you can use the various different features, including pending pacts) //.PactBroker("http://pact-broker", uriOptions: new PactUriOptions("sometoken"), enablePending: true, consumerVersionTags: new List<string> { "master" }, providerVersionTags: new List<string> { "master" }, consumerVersionSelectors: new List<VersionTagSelector> { new VersionTagSelector("master", false, true) }) .Verify(); }
/// <summary> /// Function to be used within a test to execute a call to the pact broker to verify the API /// </summary> /// <param name="outputters"></param> public void RunPactBrokerTest(IList <IOutput> outputters = null) { if (outputters is null) { outputters = new List <IOutput>(); } if (!outputters.Any(x => x.GetType() == typeof(ConsoleOutput))) { outputters.Add(new ConsoleOutput()); } var pactVerifierConfig = new PactVerifierConfig { Outputters = outputters }; var user = Configuration.GetValue <string>(Constants.ENV_VAR_PACT_BROKER_USER); var pwd = Configuration.GetValue <string>(Constants.ENV_VAR_PACT_BROKER_USER_PASSWORD); var pactUriOptions = new PactUriOptions().SetBasicAuthentication(user, pwd); var name = Configuration.GetValue <string>(Constants.ENV_VAR_PACT_BROKER_PROVIDER_NAME); var path = Configuration.GetValue <string>(Constants.ENV_VAR_PACT_BROKER_PATH); IPactVerifier pactVerifier = new PactVerifier(pactVerifierConfig); pactVerifier .ServiceProvider(name, ServerUri) .PactBroker(path, pactUriOptions) .ProviderState(ServerUri + Constants.PROVIDER_STATES_ROUTE) .Verify(); }
public async Task HonoursPactWithConsumer() { // Arrange const string serviceUri = "http://localhost:9222"; var config = new PactVerifierConfig { ProviderVersion = "1.2.3", PublishVerificationResults = true, Outputters = new List <IOutput> { new XUnitOutput(_output) }, Verbose = true }; await using (await WebApp.Start <BarApp>(serviceUri)) { var pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("Bar", serviceUri) .HonoursPactWith("Foo") .PactUri( "https://test.pact.dius.com.au/pacts/provider/Bar/consumer/Foo/latest", new PactUriOptions("dXfltyFMgNOFZAxr8io9wJ37iUpY42M", "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")) .Verify(); } }
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 } }
public void Verify_WithProviderStateSet_CallsProviderServiceValidatorWithProviderState() { var httpClient = new HttpClient(); var mockFileSystem = Substitute.For <IFileSystem>(); var mockPactProviderServiceValidator = Substitute.For <IProviderServiceValidator>(); mockFileSystem.File.ReadAllText(Arg.Any <string>()).Returns("{}"); var pactVerifier = new PactVerifier(mockFileSystem, client => mockPactProviderServiceValidator); pactVerifier.ProviderStatesFor("My client") .ProviderState("My Provider State") .ProviderState("My Provider State 2"); pactVerifier.ServiceProvider("Event API", httpClient) .HonoursPactWith("My client") .PactUri("/test.json"); pactVerifier.Verify(); mockPactProviderServiceValidator.Received(1).Validate( Arg.Any <ProviderServicePactFile>(), pactVerifier.ProviderStates); }
public void EnsureSomethingApiHonoursPactWithConsumer() { //Arrange var config = new PactVerifierConfig { Outputters = new List <IOutput> //NOTE: We default to using a ConsoleOutput, however xUnit 2 does not capture the console output, so a custom outputter is required. { new XUnitOutput(_output) }, // CustomHeaders = new Dictionary<string, string> // { // {"Authorization", "Basic VGVzdA=="} // }, //This allows the user to set request headers that will be sent with every request the verifier sends to the provider Verbose = true, //Output verbose verification logs to the test output }; //await _host.StartAsync(); try { // using (WebApp.Start<TestStartup>(serviceUri)) // { //Act / Assert IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier //.ProviderState($"{StateServiceUri}/provider-states") .ServiceProvider("Forecast API", "http://localhost:5000") .HonoursPactWith("Consumer") // .PactUri("..\\..\\..\\Consumer.Tests\\pacts\\consumer-something_api.json") .PactUri( "/home/rramos/git/PactDemo/PactDemo.Consumer.NUnitTests.Contract/bin/Debug/pacts/consumer-forecast_api.json") //or // .PactUri( // "http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest") //You can specify a http or https uri // //or // .PactUri("http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest", // new PactUriOptions("someuser", // "somepassword")) //You can also specify http/https basic auth details // //or // .PactUri("http://pact-broker/pacts/provider/Something%20Api/consumer/Consumer/latest", // new PactUriOptions("sometoken")) //Or a bearer token // //or (if you're using the Pact Broker, you can use the various different features, including pending pacts) // .PactBroker("http://pact-broker", uriOptions: new PactUriOptions("sometoken"), enablePending: true, // consumerVersionTags: new List<string> {"master"}, // providerVersionTags: new List<string> {"master"}, // consumerVersionSelectors: new List<VersionTagSelector> // {new VersionTagSelector("master", false, true)}) .Verify(); } finally { //await _host.StopAsync(); //_host.Dispose(); } }
private void VerifyContractWithConsumer(string consumerName) { IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("Helloworld", SERVER_URI) .HonoursPactWith(consumerName) .PactUri($"http://localhost/pacts/provider/HelloWorld/consumer/{ consumerName }/latest") .Verify(); }
public void ApiCompliantWithPact() { var pactVerifierConfig = new PactVerifierConfig(); var pactVerifier = new PactVerifier(pactVerifierConfig); pactVerifier .ServiceProvider("Weather API", "http://localhost:5000") .HonoursPactWith("Weather API Client") .PactUri("../../../../pacts/weather_api_client-weather_api.json") .Verify(); }
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(); } }
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(); } }
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"); } }
public void EnsureSomethingApiHonoursPactWithConsumer() { //Arrange IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { }); pactVerifier .ProviderState("There is a something with id 'tester'", setUp: AddTesterIfItDoesntExist); //NOTE: We also have tearDown //Act / Assert using (var testServer = TestServer.Create <Startup>()) { pactVerifier .ServiceProvider("TeamB Producer / Something API", testServer.HttpClient) .HonoursPactWith("Consumer") .PactUri("../../../TeamA.Consumer.Tests/pacts/teama.consumer-teamb.producer.json") .Verify(); } }
public async Task EnsureWordCountServiceApiHonoursPactWithConsumer() { //Arrange var outputter = new CustomOutputter(); var config = new PactVerifierConfig(); config.ReportOutputters.Add(outputter); IPactVerifier pactVerifier = new PactVerifier(() => { }, () => { }, config); pactVerifier .ProviderState( "there is a count of 1 for words beginning with 'A'", setUp: IncrementWordCountForLetterA); var configuration = new HttpConfiguration(); _server = TestServer.Create(app => { var apiStartup = new Startup(); apiStartup.Configuration(app, configuration); }); //var result = await _server.HttpClient.PutAsync("AddWord/AardVark", null); using (var client = new HttpClient(_server.Handler)) { // requires routing setup in Startup //var response = await client.PutAsync("http://localhost/api/default/AddWord/Ardvark", null); var response = await client.GetAsync("http://localhost/api/default/Count"); var result = await response.Content.ReadAsAsync <string>(); } //Act / Assert pactVerifier .ServiceProvider("WordCountServiceApi", _server.HttpClient) .HonoursPactWith("WordCountWebService") .PactUri("../../../../WordCount.WebService.Tests/bin/pacts/wordcountwebservice-wordcountserviceapi.json") .Verify(); // Verify that verifaction log is also sent to additional reporters defined in the config Assert.Contains("Verifying a Pact between WordCountWebService and WordCountService API", outputter.Output); }
public void EnsureProviderApiHonoursPactWithConsumer() { // Arrange var config = new PactVerifierConfig { Outputters = new List <IOutput> { new ConsoleOutput() }, Verbose = true }; // Act / Assert IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier.ServiceProvider("ExampleApi", _providerUri) .HonoursPactWith("ExampleSite") .PactUri(@"pathtopactfile\examplesite-exampleapi.json") .Verify(); }
public void TestProvider() { var config = new PactVerifierConfig { Outputters = new List <IOutput> { new XUnitOutput(_output) }, Verbose = true }; IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("ToDoList", "http://*****:*****@"\Users\sukanyar\RiderProjects\ToDoWebapi\ToDoWebApi.ContractTests\bin\Debug\netcoreapp3.1\~\dotnet\pacts\service_consumer-todolist.json") .Verify(); }
public void EnsureAmortizationApiHonorsPactWithConsumer() { // Arrange var config = new PactVerifierConfig { Outputters = new List <IOutput> { new XUnitOutput(_output) }, Verbose = true }; // Act, Assert var pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("Mortgage API", "http://*****:*****@"C:\repos\mortgage-amortization\src\Mortgage.UI\pacts\mortgage_ui-mortgage_api.json") .Verify(); }
//[Ignore("PACT BROKER")] public void EnsurePactDemoProviderHobnoursPactWithPactDemoConsumerUsingPactBroker() { var wipSinceDate = "2020-01-01"; var token = Environment.GetEnvironmentVariable("PACT_BROKER_TOKEN"); var pactBrokerBaseUrl = "https://expandtesting.pact.dius.com.au"; var pactUriOptions = new PactUriOptions(token); // fake Git HashCode (only for demo) var version = "11bb818"; var config = new PactVerifierConfig { ProviderVersion = version, PublishVerificationResults = true, Verbose = true }; var consumerVersionSelectors = new List <VersionTagSelector> { new VersionTagSelector("master", null, null, false, true), }; var pactVerifier = new PactVerifier(config); pactVerifier.ProviderState($"{pactServiceUri}/provider-states"); pactVerifier.ServiceProvider(providerName, $"{providerServiceUri}"); var providerVersionTags = new List <string> { "master" }; // Verify pactVerifier.PactBroker(pactBrokerBaseUrl, uriOptions: pactUriOptions, enablePending: false, includeWipPactsSince: wipSinceDate, providerVersionTags: providerVersionTags, consumerVersionSelectors: consumerVersionSelectors) .Verify(); }
public void EnsureEventApiHonoursPactWithConsumer() { //Arrange const string serviceUri = "http://localhost:9222"; var config = new PactVerifierConfig { Outputters = new List <IOutput> { new XUnitOutput(_output) } }; using (WebApp.Start <Startup>(serviceUri)) { IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier .ServiceProvider("Provider", serviceUri) .HonoursPactWith("Consumer") .PactUri($"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}Consumer.Tests{Path.DirectorySeparatorChar}pacts{Path.DirectorySeparatorChar}consumer-provider.json") .Verify(); } }
public void EnsureEventApiHonoursPactWithConsumer() { ContextInfo.SetTestContextName(GetType().Name); //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); // todo (HACK): Find a better way to inject pact config into MockProviderNancyBootstrapper MockProviderNancyBootstrapper.PactConfig = new PactConfig(); var builder = new WebHostBuilder(); builder.UseStartup <Startup4ProviderRun>(); _server = new TestServer(builder); //Act / Assert pactVerifier .ServiceProvider("Event API", _server.CreateClient()) .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); }
public void EnsureDinkumCoinApiHonoursPactWithConsumer() { //Arrange const string serviceUri = "https://8lyhztzwh3.execute-api.ap-southeast-2.amazonaws.com/Dev"; var config = new PactVerifierConfig { Outputters = new List <IOutput> { new XUnitOutput(_output) } }; IPactVerifier pactVerifier = new PactVerifier(config); pactVerifier // .ProviderState($"{serviceUri}/provider-states") .ServiceProvider("dinkum-coin-api", serviceUri) .HonoursPactWith("dinkum-coin-web") .PactUri($"pacts/dinkum-coin-web-dinkum-coin-api.json") .Verify(); }
public void ProviderApiWeb_ClientPact_Compliance() { ContextInfo.SetTestContextName(GetType().Name); //Arrange var outputter = new CustomOutputter(); var config = new PactVerifierConfig() { LogDir = @"c:\logs\PactNetCore" }; 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); var pactUri = @"C:\Users\kharshaw\Documents\GitHub\Pact-Net-Core\Samples\EventApi\Provider.Api.Web.Tests\Consumer.Tests\pacts\consumer-event_api.json"; //Act / Assert pactVerifier .ServiceProvider("Event API", _client) .HonoursPactWith("Consumer") .PactUri(pactUri) .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); }
private PactnetVerificationResult VerifyUsingPactNet(string pactFile, bool publishResultViaBroker, Models.Pact runningPact) { var result = new PactnetVerificationResult(); var logger = new StringAppendOutput(); var verifierConfig = new PactVerifierConfig { Outputters = new IOutput[] { logger }, PublishVerificationResults = publishResultViaBroker, ProviderVersion = "1" }; var verifier = new PactVerifier(verifierConfig); verifier.ServiceProvider(runningPact.Provider?.Name, _serviceUri); verifier.PactUri(pactFile); try { verifier.Verify(); result.Success = true; } catch (Exception e) { result.Success = false; result.Exception = e; } result.Logs = logger.Log; return(result); }
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(); } }
public void Verify_WithProviderState_CallsProviderServiceValidatorWith2FilteredInteractions() { var providerState = "My Provider State"; var pactUri = "../../../Consumer.Tests/pacts/my_client-event_api.json"; var pactFileJson = "{ \"provider\": { \"name\": \"Event API\" }, \"consumer\": { \"name\": \"My client\" }, \"interactions\": [{ \"description\": \"My Description\", \"provider_state\": \"My Provider State\" }, { \"description\": \"My Description 2\", \"provider_state\": \"My Provider State\" }, { \"description\": \"My Description\", \"provider_state\": \"My Provider State 2\" }], \"metadata\": { \"pactSpecificationVersion\": \"1.0.0\" } }"; var httpClient = new HttpClient(); var mockFileSystem = Substitute.For<IFileSystem>(); var mockPactProviderServiceValidator = Substitute.For<IProviderServiceValidator>(); mockFileSystem.File.ReadAllText(pactUri).Returns(pactFileJson); var pactVerifier = new PactVerifier(mockFileSystem, client => mockPactProviderServiceValidator); pactVerifier.ProviderStatesFor("My client") .ProviderState("My Provider State") .ProviderState("My Provider State 2"); pactVerifier.ServiceProvider("Event API", httpClient) .HonoursPactWith("My client") .PactUri(pactUri); pactVerifier.Verify(providerState: providerState); mockPactProviderServiceValidator.Received(1).Validate( Arg.Is<ProviderServicePactFile>(x => x.Interactions.Count() == 2 && x.Interactions.All(i => i.ProviderState.Equals(providerState))), Arg.Any<ProviderStates>()); }