示例#1
0
 private async Task Save()
 {
     using (var repo = new PactRepo(_configuration))
     {
         await repo.Put(this);
     }
 }
示例#2
0
        /// <summary>
        /// Fetches all pacts and verifies them. Returns all test results.
        /// </summary>
        /// <param name="providerName">The name of the provider, as stated in the pacts.</param>
        /// <returns>Testresults. Use <seealso cref="ITestResult.Success" /> to check the results of each pact.</returns>
        public async Task <IEnumerable <ITestResult> > Verify(string providerName)
        {
            var repo    = new PactRepo(configuration);
            var results = new List <ITestResult>();

            foreach (var pact in repo.FetchAll(providerName))
            {
                using (var server = new TestServer(new WebHostBuilder().UseStartup <TStartup>(pact, setup)))
                    using (var client = server.CreateClient())
                    {
                        var result = await pact.Verify(client);

                        var args = new PactResultEventArgs(pact, result);
                        Verified?.Invoke(this, args);
                        if (!result.Success)
                        {
                            VerificationFailed?.Invoke(this, args);
                            pact.Configuration.LogSafe(LogLevel.Error, $"Assertion failed:{Environment.NewLine}{result}{Environment.NewLine}");
                        }
                        results.Add(result);
                    }
            }
            if (!(DoNotGenerateOneDummyTestResultWhenNoPactsAreFound || results.Any()))
            {
                results.Add(new DummyTestResult());
            }
            return(results);
        }
示例#3
0
        public void FetchAll_FromFile_ParsesJsonFilesAndReturnsOnlyPactsSpecificForProvider(string path, string provider, int expectedCount)
        {
            var config = Configuration.With.Log(System.Console.WriteLine).PublishPath(path).LogLevel(LogLevel.Verbose);
            var target = new PactRepo(config);
            var count  = 0;

            foreach (var pact in target.FetchAll(provider))
            {
                Assert.NotNull(pact.ProviderState);
                count++;
            }
            Assert.Equal(expectedCount, count);
        }
示例#4
0
        private async Task PublishIfSuccessful()
        {
            if (_configuration == null)
            {
                return;
            }
            if (_failures.Any())
            {
                _configuration.LogSafe(LogLevel.Error, $"There are {_failures.Count} failing pacts. Publishing is omitted.");
            }
            var repo = new PactRepo(_configuration);

            foreach (var pact in new PactGrouper(_successful))
            {
                await repo.Put(pact);
            }
        }