示例#1
0
        public async Task ShouldThrowWhenClientThrowsForAnyOtherReason()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler
            {
                ObjectToReturn   = new Contract(),
                ExceptionToThrow = new HttpRequestException("Something went wrong.")
            };

            var config = new PactVerifierConfig
            {
                PactBrokerClient = new HttpClient(fakePactBrokerMessageHandler)
                {
                    BaseAddress = new Uri("http://localhost:9292")
                }
            };

            var mockConsumer = new PactVerifier(config);

            try
            {
                await mockConsumer.GetPactFromBroker("some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("Pact cannot be retrieved using the provided Pact Broker Client: Something went wrong.", e.Message);
                throw;
            }
        }
示例#2
0
        public async Task ShouldThrowWhenResponseIsNotSuccessful()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler
            {
                ObjectToReturn     = new Contract(),
                StatusCodeToReturn = System.Net.HttpStatusCode.BadRequest
            };

            var config = new PactVerifierConfig
            {
                PactBrokerClient = new HttpClient(fakePactBrokerMessageHandler)
                {
                    BaseAddress = new Uri("http://localhost:9292")
                }
            };

            var mockConsumer = new PactVerifier(config);

            try
            {
                await mockConsumer.GetPactFromBroker("some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("Getting pact from Pact Broker failed. Pact Broker returned BadRequest", e.Message);
                throw;
            }
        }
示例#3
0
        public async Task ShouldGetPactFromPactBroker()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler();

            fakePactBrokerMessageHandler.Configure(HttpMethod.Get, "http://localhost:9292/some/path")
            .RespondsWith(HttpStatusCode.OK).Returns(new Contract());

            var pactBrokerResults = await PactVerifier.GetPactFromBroker(new HttpClient(fakePactBrokerMessageHandler) { BaseAddress = new Uri("http://localhost:9292") }, "some/path");

            Assert.IsNotNull(pactBrokerResults);
            Assert.IsNotNull(JsonConvert.DeserializeObject <Contract>(pactBrokerResults.PactContent));
            Assert.IsNotNull(pactBrokerResults.PublishVerificationResultsUrl);
        }
示例#4
0
        public async Task ShouldThrowWhenClientHasNoBaseAddress()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler();

            fakePactBrokerMessageHandler.Configure(HttpMethod.Put, "http://localhost:9292")
            .RespondsWith(HttpStatusCode.Created).Returns(new Contract());

            try
            {
                await PactVerifier.GetPactFromBroker(new HttpClient(fakePactBrokerMessageHandler), "some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("A PactBrokerClient with at least a BaseAddress should be configured to be able to retrieve contracts.", e.Message);
                throw;
            }
        }
示例#5
0
        public async Task ShouldThrowWhenResponseIsNotSuccessful()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler();

            fakePactBrokerMessageHandler.Configure(HttpMethod.Get, "http://localhost:9292/some/path")
            .RespondsWith(HttpStatusCode.BadRequest).Returns(new Contract());

            try
            {
                await PactVerifier.GetPactFromBroker(new HttpClient(fakePactBrokerMessageHandler) { BaseAddress = new Uri("http://localhost:9292") }, "some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("Getting pact from Pact Broker failed. Pact Broker returned BadRequest", e.Message);
                throw;
            }
        }
示例#6
0
        public async Task ShouldThrowWhenClientThrowsForAnyOtherReason()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler();

            fakePactBrokerMessageHandler.Configure(HttpMethod.Get, "http://localhost:9292")
            .RespondsWith(HttpStatusCode.Created).Returns(new Contract())
            .ThowsException(new HttpRequestException("Something went wrong."));

            try
            {
                await PactVerifier.GetPactFromBroker(new HttpClient(fakePactBrokerMessageHandler) { BaseAddress = new Uri("http://localhost:9292") }, "some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("Pact cannot be retrieved using the provided Pact Broker Client: Something went wrong.", e.Message);
                throw;
            }
        }
示例#7
0
        public async Task ShouldGetPactFromPactBroker()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler
            {
                ObjectToReturn = new Contract()
            };

            var config = new PactVerifierConfig
            {
                PactBrokerClient = new HttpClient(fakePactBrokerMessageHandler)
                {
                    BaseAddress = new Uri("http://localhost:9292")
                }
            };

            var mockConsumer = new PactVerifier(config);

            var stringContent = await mockConsumer.GetPactFromBroker("some/path");

            Assert.IsNotNull(stringContent);
            Assert.IsNotNull(JsonConvert.DeserializeObject <Contract>(stringContent));
        }
示例#8
0
        public async Task ShouldThrowWhenClientHasNoBaseAddress()
        {
            var fakePactBrokerMessageHandler = new FakePactBrokerMessageHandler
            {
                ObjectToReturn = new Contract(),
            };

            var config = new PactVerifierConfig
            {
                PactBrokerClient = new HttpClient(fakePactBrokerMessageHandler)
            };

            var mockConsumer = new PactVerifier(config);

            try
            {
                await mockConsumer.GetPactFromBroker("some/path");
            }
            catch (PactException e)
            {
                Assert.AreEqual("A PactBrokerClient with at least a BaseAddress should be configured to be able to retrieve contracts.", e.Message);
                throw;
            }
        }