public void Verify_WithHttpsPactFileUriAndBasicAuthUriOptions_CallsHttpClientWithJsonGetRequestAndBasicAuthorizationHeader() { var serviceProvider = "Event API"; var serviceConsumer = "My client"; var pactUri = "https://yourpactserver.com/getlatestpactfile"; 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 options = new PactUriOptions("someuser", "somepassword"); var pactVerifier = GetSubject(); _fakeHttpMessageHandler.Response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(pactFileJson, Encoding.UTF8, "application/json") }; pactVerifier .ServiceProvider(serviceProvider, new HttpClient()) .HonoursPactWith(serviceConsumer) .PactUri(pactUri, options); pactVerifier.Verify(); Assert.Equal(HttpMethod.Get, _fakeHttpMessageHandler.RequestsRecieved.Single().Method); Assert.Equal("application/json", _fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Single(x => x.Key == "Accept").Value.Single()); Assert.Equal(_fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Authorization.Scheme, options.AuthorizationScheme); Assert.Equal(_fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Authorization.Parameter, options.AuthorizationValue); }
private string BuildExpectedArguments( Uri baseUri, string pactUri, Uri providerStateSetupUri, PactUriOptions pactUriOptions = null, bool publishVerificationResults = false, string providerVersion = "", Dictionary <string, string> customHeaders = null, bool verbose = false) { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : ""; var brokerCredentials = pactUriOptions != null ? !String.IsNullOrEmpty(pactUriOptions.Username) && !String.IsNullOrEmpty(pactUriOptions.Password) ? $" --broker-username \"{pactUriOptions.Username}\" --broker-password \"{pactUriOptions.Password}\"" : $" --broker-token \"{pactUriOptions.Token}\"" : string.Empty; var publishResults = publishVerificationResults ? $" --publish-verification-results=true --provider-app-version=\"{providerVersion}\"" : string.Empty; var customProviderHeaders = customHeaders != null? String.Join("", customHeaders.Select(c => $" --custom-provider-header \"{c.Key}:{c.Value}\"")) : string.Empty; var verboseOutput = verbose ? " --verbose true" : string.Empty; return($"\"{pactUri}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}{customProviderHeaders}{verboseOutput}"); }
public PactVerifierHostConfig(Uri baseUri, string pactUri, PactUriOptions pactBrokerUriOptions, Uri providerStateSetupUri, PactVerifierConfig config, IDictionary <string, string> environment) { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : string.Empty; var brokerCredentials = pactBrokerUriOptions != null ? !String.IsNullOrEmpty(pactBrokerUriOptions.Username) && !String.IsNullOrEmpty(pactBrokerUriOptions.Password) ? $" --broker-username \"{pactBrokerUriOptions.Username}\" --broker-password \"{pactBrokerUriOptions.Password}\"" : $" --broker-token \"{pactBrokerUriOptions.Token}\"" : string.Empty; var publishResults = config?.PublishVerificationResults == true ? $" --publish-verification-results=true --provider-app-version=\"{config.ProviderVersion}\"" : string.Empty; var customHeaders = this.BuildCustomHeaders(config); var verbose = config?.Verbose == true ? " --verbose true" : string.Empty; var monkeyPatchOption = !string.IsNullOrEmpty(config?.MonkeyPatchFile) ? $" --monkeypatch=\"${config.MonkeyPatchFile}\"" : string.Empty; Script = "pact-provider-verifier"; Arguments = $"\"{FixPathForRuby(pactUri)}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}{customHeaders}{verbose}{monkeyPatchOption}"; WaitForExit = true; Outputters = config?.Outputters; Environment = new Dictionary <string, string> { { "PACT_INTERACTION_RERUN_COMMAND", "To re-run just this failing interaction, change the verify method to '.Verify(description: \"<PACT_DESCRIPTION>\", providerState: \"<PACT_PROVIDER_STATE>\")'. Please do not check in this change!" } }; if (environment != null) { foreach (var envVar in environment) { Environment.Add(envVar.Key, envVar.Value); } } }
/// <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(); }
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(); }
public void Ctor_WithValidToken_ReturnsCorrectToken() { const string token = "MyToken"; var options = new PactUriOptions().SetBearerAuthentication(token); Assert.Equal(token, options.Token); }
public void Ctor_WithValidUsernameAndPassword_ReturnsCorrectUsernameAndPassword() { const string username = "******"; const string password = "******"; var options = new PactUriOptions(username, password); Assert.Equal(username, options.Username); Assert.Equal(password, options.Password); }
//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(); }
public void Ctor_WithValidToken_ReturnsCorrectAuthorizationSchemeAndValue() { const string token = "MyToken"; const string expectedAuthScheme = "Bearer"; const string expectedAuthValue = token; var options = new PactUriOptions().SetBearerAuthentication(token); Assert.Equal(expectedAuthScheme, options.AuthorizationScheme); Assert.Equal(expectedAuthValue, options.AuthorizationValue); }
public void Ctor_WithValidUsernameAndPassword_ReturnsCorrectAuthorizationSchemeAndValue() { const string username = "******"; const string password = "******"; var expectedAuthScheme = "Basic"; var expectedAuthValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; var options = new PactUriOptions(username, password); Assert.Equal(expectedAuthScheme, options.AuthorizationScheme); Assert.Equal(expectedAuthValue, options.AuthorizationValue); }
public void Ctor_WithValidUsernameAndPassword_ReturnsCorrectAuthorizationSchemeAndValue() { const string username = "******"; const string password = "******"; var expectedAuthScheme = "Basic"; var expectedAuthValue = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="; var options = new PactUriOptions(username, password); Assert.Equal(expectedAuthScheme, options.AuthorizationScheme); Assert.Equal(expectedAuthValue, options.AuthorizationValue); }
public void Ctor_WhenCalledWithAAuthenticatedHttpsPactUri_SetsTheCorrectArgs() { var baseUri = new Uri("http://127.0.0.1"); var pactUri = "https://broker:9292/test"; var pactUriOptions = new PactUriOptions("username", "password"); var providerStateSetupUri = new Uri("http://127.0.0.1/states/"); var config = GetSubject(baseUri, pactUri, pactUriOptions, providerStateSetupUri); var expectedArguments = BuildExpectedArguments(baseUri, pactUri, providerStateSetupUri, pactUriOptions); Assert.Equal(expectedArguments, config.Arguments); }
private string BuildExpectedArguments( Uri baseUri, string pactUri, Uri providerStateSetupUri, PactUriOptions pactUriOptions = null, bool publishVerificationResults = false, string providerVersion = "") { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : ""; var brokerCredentials = pactUriOptions != null ? $" --broker-username \"{pactUriOptions.Username}\" --broker-password \"{pactUriOptions.Password}\"" : ""; var publishResults = publishVerificationResults ? $" --publish-verification-results=true --provider-app-version=\"{providerVersion}\"" : string.Empty; return($"--pact-urls \"{pactUri}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}"); }
public PactVerifierHostConfig(Uri baseUri, string pactUri, PactUriOptions pactBrokerUriOptions, Uri providerStateSetupUri, PactVerifierConfig config) { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : string.Empty; var brokerCredentials = pactBrokerUriOptions != null ? $" --broker-username \"{pactBrokerUriOptions.Username}\" --broker-password \"{pactBrokerUriOptions.Password}\"" : string.Empty; var publishResults = config?.PublishVerificationResults == true ? $" --publish-verification-results=true --provider-app-version=\"{config.ProviderVersion}\"" : string.Empty; var customHeader = config?.CustomHeader != null && !string.IsNullOrEmpty(config.CustomHeader?.Key) && !string.IsNullOrEmpty(config.CustomHeader?.Value) ? $" --custom-provider-header \"{config.CustomHeader?.Key}:{config.CustomHeader?.Value}\"" : string.Empty; var verbose = config?.Verbose == true ? " --verbose true" : string.Empty; Script = "pact-provider-verifier"; Arguments = $"\"{FixPathForRuby(pactUri)}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}{customHeader}{verbose}"; WaitForExit = true; Outputters = config?.Outputters; }
public PactVerifierHostConfig(Uri baseUri, string pactUri, PactUriOptions pactBrokerUriOptions, Uri providerStateSetupUri, PactVerifierConfig config) { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : ""; var brokerCredentials = pactBrokerUriOptions != null ? $" --broker-username \"{pactBrokerUriOptions.Username}\" --broker-password \"{pactBrokerUriOptions.Password}\"" : ""; string publishResults = string.Empty; if (config?.PublishVerificationResults == true) { publishResults = $" --publish-verification-results=true --provider-app-version=\"{config.ProviderVersion}\""; } Script = "pact-provider-verifier.rb"; Arguments = $"--pact-urls \"{FixPathForRuby(pactUri)}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}"; WaitForExit = true; Outputters = config?.Outputters; }
private IPactCoreHostConfig GetSubject(Uri baseUri = null, string pactUri = null, PactBrokerConfig brokerConfig = null, PactUriOptions pactBrokerUriOptions = null, Uri providerStateSetupUri = null, PactVerifierConfig verifierConfig = null, IDictionary <string, string> environment = null) { return(new PactVerifierHostConfig( baseUri ?? new Uri("http://localhost:2833"), pactUri, brokerConfig, pactBrokerUriOptions, providerStateSetupUri, verifierConfig, environment)); }
public void PublishToBroker_WithAuthentication_PublishesPact() { var brokerBaseUri = "https://test.pact.dius.com.au"; var pactUriOptions = new PactUriOptions("username", "password"); var pactPublisher = GetSubject(brokerBaseUri, pactUriOptions); var pactFilePath = "..\\..\\..\\Samples\\EventApi\\Consumer.Tests\\pacts\\event_api_consumer-event_api.json"; var consumerVersion = "1.0.2"; var pactFileText = File.ReadAllText(pactFilePath); var pactDetails = JsonConvert.DeserializeObject <PactDetails>(pactFileText); pactPublisher.PublishToBroker(pactFilePath, consumerVersion); var requestsReceived = _fakeHttpMessageHandler.RequestsReceived; Assert.Equal(1, requestsReceived.Count()); Assert.True(ValidPactPublishRequest(requestsReceived.ElementAt(0), _fakeHttpMessageHandler.RequestContentReceived.ElementAt(0), brokerBaseUri, pactDetails, pactFileText, consumerVersion, pactUriOptions)); }
public void Verify_WhenTheVerifierIsCorrectlySetUpWithAHttpsPactFileWitTokenAuthCredentials_PactVerifyCoreHostIsStarted() { var serviceProvider = "Event API"; var serviceConsumer = "My client"; var pactUri = "https://broker/consumer/test/provider/hello/latest"; var pactUriOptions = new PactUriOptions().SetBearerAuthentication("mytoken"); var pactVerifier = GetSubject(); pactVerifier .ServiceProvider(serviceProvider, "http://localhost") .HonoursPactWith(serviceConsumer) .PactUri(pactUri, pactUriOptions); pactVerifier.Verify(); _mockVerifierCoreHost.Received(1).Start(); }
//[InlineData("OtherConsumer")] public void EnsureProviderApiHonoursPactWithConsumer(string consumerName) { //This token is taken from within the broker UI (See settings > Read/write token (CI)) //This is used to authenticate requests to the pact broker as part of the PactVerifier var options = new PactUriOptions(Config.Pact_Bearer_Token); //Create the mocked provider service using (var ProviderWebHost = WebHost.CreateDefaultBuilder() .UseUrls(ProviderUri) .UseStartup <TestStartup>() .UseSetting(WebHostDefaults.ApplicationKey, typeof(Startup).Assembly.GetName().Name) .ConfigureServices(DependencyRegistration.ConfigureStaticDependencies) .Build()) { ProviderWebHost.Start(); VerifyPactFor(consumerName, PactConfig, options); } }
private string BuildExpectedArguments( Uri baseUri, string pactUri, Uri providerStateSetupUri, PactUriOptions pactUriOptions = null, bool publishVerificationResults = false, string providerVersion = "", KeyValuePair <string, string>?customHeader = null, bool verbose = false) { var providerStateOption = providerStateSetupUri != null ? $" --provider-states-setup-url {providerStateSetupUri.OriginalString}" : ""; var brokerCredentials = pactUriOptions != null ? $" --broker-username \"{pactUriOptions.Username}\" --broker-password \"{pactUriOptions.Password}\"" : ""; var publishResults = publishVerificationResults ? $" --publish-verification-results=true --provider-app-version=\"{providerVersion}\"" : string.Empty; var customProviderHeader = customHeader != null ? $" --custom-provider-header \"{customHeader.Value.Key}:{customHeader.Value.Value}\"" : string.Empty; var verboseOutput = verbose ? " --verbose true" : string.Empty; return($"\"{pactUri}\" --provider-base-url {baseUri.OriginalString}{providerStateOption}{brokerCredentials}{publishResults}{customProviderHeader}{verboseOutput}"); }
//[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(); }
private void AssertPactTagRequest( HttpRequestMessage httpRequest, string httpRequestContent, string brokerBaseUri, PactDetails expectedPactDetails, string expectedConsumerVersion, string expectedTag, PactUriOptions expectedPactUriOptions = null) { if (expectedPactUriOptions != null) { Assert.Equal(expectedPactUriOptions.AuthorizationScheme, httpRequest.Headers.Authorization.Scheme); Assert.Equal(expectedPactUriOptions.AuthorizationValue, httpRequest.Headers.Authorization.Parameter); } string expectedUri = $"{brokerBaseUri}/pacticipants/{Uri.EscapeDataString(expectedPactDetails.Consumer.Name)}/versions/{expectedConsumerVersion}/tags/{Uri.EscapeDataString(expectedTag)}"; Assert.Equal(HttpMethod.Put, httpRequest.Method); Assert.Equal(expectedUri, httpRequest.RequestUri.OriginalString); Assert.Equal(string.Empty, httpRequestContent); Assert.Equal("application/json", httpRequest.Content.Headers.ContentType.MediaType); Assert.Equal("utf-8", httpRequest.Content.Headers.ContentType.CharSet); }
public void Verify_WhenTheVerifierIsCorrectlySetUpWithABrokerConfiguration_PactVerifyCoreHostIsStarted() { var serviceProvider = "Event API"; var serviceConsumer = "My client"; var pactUri = "https://broker/consumer/test/provider/hello/latest"; var pactUriOptions = new PactUriOptions().SetBearerAuthentication("mytoken"); var pactVerifier = GetSubject(); pactVerifier .ServiceProvider(serviceProvider, "http://localhost") .HonoursPactWith(serviceConsumer) .PactBroker(pactUri, pactUriOptions, true, new List <string> { "t1" }, new List <string> { "t2" }, new List <VersionTagSelector> { new VersionTagSelector("t3", latest: true) }); pactVerifier.Verify(); _mockVerifierCoreHost.Received(1).Start(); }
private bool ValidPactTagRequest( HttpRequestMessage httpRequest, string httpRequestContent, string brokerBaseUri, PactDetails expectedPactDetails, string expectedConsumerVersion, string expectedTag, PactUriOptions expectedPactUriOptions = null) { var authHeadersCorrect = false; if (expectedPactUriOptions != null) { if (httpRequest.Headers.Authorization.Scheme == expectedPactUriOptions.AuthorizationScheme && httpRequest.Headers.Authorization.Parameter == expectedPactUriOptions.AuthorizationValue) { authHeadersCorrect = true; } } else if (httpRequest.Headers.Authorization == null) { authHeadersCorrect = true; } if (httpRequest.Method == HttpMethod.Put && httpRequest.RequestUri.OriginalString == $"{brokerBaseUri}/pacticipants/{Uri.EscapeDataString(expectedPactDetails.Consumer.Name)}/versions/{expectedConsumerVersion}/tags/{Uri.EscapeDataString(expectedTag)}" && httpRequestContent == "" && httpRequest.Content.Headers.ContentType.MediaType == "application/json" && httpRequest.Content.Headers.ContentType.CharSet == "utf-8" && authHeadersCorrect) { return(true); } return(false); }
private IPactCoreHostConfig GetSubject(Uri baseUri = null, string pactUri = "../test/pact.json", PactUriOptions pactBrokerUriOptions = null, Uri providerStateSetupUri = null, PactVerifierConfig verifierConfig = null) { return(new PactVerifierHostConfig( baseUri ?? new Uri("http://localhost:2833"), pactUri, pactBrokerUriOptions, providerStateSetupUri, verifierConfig)); }
private PactPublisher GetSubject(string brokerBaseUri, PactUriOptions brokerUriOptions = null) { _fakeHttpMessageHandler = new FakeHttpMessageHandler(); return(new PactPublisher(brokerBaseUri, brokerUriOptions, _fakeHttpMessageHandler)); }
public void PactflowWebhook_EnsureProviderApiHonorsContractsWithPublishedPact() { // arrange // setup mocked Foo API const string guidRegex = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"; _fooApiMock.ClearInteractions(); _fooApiMock .Given("There is a foo with some-guid") .UponReceiving("A GET request to retrieve foo") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/foos", Query = Match.Regex("name=00000000-0000-0000-0000-000000000000", $"^name={guidRegex}$"), Headers = new Dictionary <string, object> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new[] { new { id = "some id", name = "some name", description = "some description" } } }); // get environment variables DotNetEnv.Env.TraversePath().Load(); bool isRunningInPipeline = "true".Equals(Environment.GetEnvironmentVariable("CI")); string pactBrokerBaseUrl = Environment.GetEnvironmentVariable("PACT_BROKER_BASE_URL"); string pactBrokerApiToken = Environment.GetEnvironmentVariable("PACT_BROKER_API_TOKEN"); string pactProviderTag = Environment.GetEnvironmentVariable("PACT_PROVIDER_TAG"); string pactUrl = Environment.GetEnvironmentVariable("PACT_URL"); string gitCommitShortSha = Environment.GetEnvironmentVariable("GIT_COMMIT_SHORT_SHA"); var pactVerifier = new PactVerifier(new PactVerifierConfig { ProviderVersion = gitCommitShortSha, PublishVerificationResults = isRunningInPipeline, Outputters = new[] { new XUnitOutput(_outputHelper) }, Verbose = true }); PactUriOptions pactUriOptions = new PactUriOptions().SetBearerAuthentication(pactBrokerApiToken); pactVerifier .ProviderState($"{TestServiceBaseUri}/provider-states") .ServiceProvider("Provider API", TestServiceBaseUri); // pactUrl is provided to pipeline triggered by pactflow webhook indicating what specific pact should be verified // if value is missing then default verification is performed for all consumers with tags: main, dev, uat, prod bool isVerifyingSpecificPact = !string.IsNullOrWhiteSpace(pactUrl); if (isVerifyingSpecificPact) { pactVerifier.PactUri(pactUrl, pactUriOptions); } else { var consumerVersionSelectors = new List <VersionTagSelector> { new VersionTagSelector("refs/heads/main", latest: true), new VersionTagSelector("dev", latest: true), new VersionTagSelector("uat", latest: true), new VersionTagSelector("prod", latest: true) }; pactVerifier.PactBroker(pactBrokerBaseUrl, pactUriOptions, true, providerVersionTags: new[] { pactProviderTag }, consumerVersionSelectors: consumerVersionSelectors); } // act // assert pactVerifier.Verify(); }
public void Verify_WithHttpsPactFileUriAndBasicAuthUriOptions_CallsHttpClientWithJsonGetRequestAndBasicAuthorizationHeader() { var serviceProvider = "Event API"; var serviceConsumer = "My client"; var pactUri = "https://yourpactserver.com/getlatestpactfile"; 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 options = new PactUriOptions("someuser", "somepassword"); var pactVerifier = GetSubject(); _fakeHttpMessageHandler.Response = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(pactFileJson, Encoding.UTF8, "application/json") }; pactVerifier .ServiceProvider(serviceProvider, new HttpClient()) .HonoursPactWith(serviceConsumer) .PactUri(pactUri, options); pactVerifier.Verify(); Assert.Equal(HttpMethod.Get, _fakeHttpMessageHandler.RequestsRecieved.Single().Method); Assert.Equal("application/json", _fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Single(x => x.Key == "Accept").Value.Single()); Assert.Equal(_fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Authorization.Scheme, options.AuthorizationScheme); Assert.Equal(_fakeHttpMessageHandler.RequestsRecieved.Single().Headers.Authorization.Parameter, options.AuthorizationValue); }
public IPactVerifier PactUri(string uri, PactUriOptions options = null) { if (String.IsNullOrEmpty(uri)) { throw new ArgumentException("Please supply a non null or empty consumerName"); } PactFileUri = uri; PactUriOptions = options; return this; }