Ejemplo n.º 1
0
        internal static async Task PublishVerificationResultsAsync(Contract pact, List <Test> tests, string providerVersion, HttpClient pactBrokerClient, string publishVerificationResultsUrl)
        {
            if (string.IsNullOrWhiteSpace(providerVersion))
            {
                throw new PactException("ProviderVersion should be configured to be able to publish verification results.");
            }

            var failureCount = tests.Count(t => t.Status == "failed");

            var testResults = new TestResults
            {
                Summary = new Summary {
                    TestCount = tests.Count(), FailureCount = failureCount
                },
                Tests = tests
            };

            var verificationResults = new VerificationResults
            {
                ProviderName = pact.Provider.Name,
                ProviderApplicationVersion = providerVersion,
                Success          = failureCount == 0,
                VerificationDate = DateTime.UtcNow.ToString("u"),
                TestResults      = testResults
            };
            var content = new StringContent(JsonConvert.SerializeObject(verificationResults), Encoding.UTF8, "application/json");

            var response = await pactBrokerClient.PostAsync(publishVerificationResultsUrl, content);

            if (!response.IsSuccessStatusCode)
            {
                throw new PactException("Publishing verification results failed. Pact Broker returned " + response.StatusCode);
            }
        }
Ejemplo n.º 2
0
        internal async Task PublishVerificationResultsAsync(Contract pact, List <FailedInteraction> failedInteractions)
        {
            if (string.IsNullOrWhiteSpace(_config.ProviderVersion))
            {
                throw new PactException("ProviderVersion should be configured to be able to publish verification results.");
            }

            var verificationResults = new VerificationResults
            {
                ProviderName = pact.Provider.Name,
                ProviderApplicationVersion = _config.ProviderVersion,
                Success            = !failedInteractions.Any(),
                VerificationDate   = DateTime.UtcNow.ToString("u"),
                FailedInteractions = failedInteractions
            };
            var content = new StringContent(JsonConvert.SerializeObject(verificationResults), Encoding.UTF8, "application/json");

            var response = await _config.PactBrokerClient.PostAsync(_publishVerificationResultsPath, content);

            if (!response.IsSuccessStatusCode)
            {
                throw new PactException("Publishing verification results failed. Pact Broker returned " + response.StatusCode);
            }
        }