Example #1
0
        public void Validate_Pact_File_Is_Downloaded_From_Pact_Broker_To_Local_Machine()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(PactAsJson);

            var performance = new Performance(FakePactBrokerUrl);

            fakePactBroker.Dispose();

            Assert.True(File.Exists(performance.LocalPact), "Failed to download the pact to local machine.");

            File.Delete(performance.LocalPact);
        }
Example #2
0
        public void Validate_When_Request_Is_Matched()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(_pactAsString);

            var dad = Stub.Create(9000).FromPactbroker(FakePactBrokerUrl);

            var response = DoHttpPost("/please/give/me/some/money");

            dad.Dispose();
            fakePactBroker.Dispose();

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Example #3
0
        public void Validate_When_Request_Is_Not_Matched()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(_pactAsString);

            var dad = Stub.Create(9000).FromPactbroker(FakePactBrokerUrl);

            var response = DoHttpPost("/please/give/me/some/food");

            dad.Dispose();
            fakePactBroker.Dispose();

            response.StatusCode.ToString().Should().Be("551");
            response.StatusDescription.Should().Be("Stub on port 9000 says interaction not found. Please verify that the pact associated with this port contains the following request(case insensitive) : Method 'POST', Path '/please/give/me/some/food', Body ''. If you have specified filters please also check them.");
        }
Example #4
0
        public void Validate_When_Filtered_On_Description()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(_pactAsString);

            var dad = Stub.Create(9000).FromPactbroker(FakePactBrokerUrl);

            dad.FilterOnDescription("a request for money or advice");

            var response = DoHttpPost("/please/give/me/some/money");

            dad.Dispose();
            fakePactBroker.Dispose();

            response.StatusCode.Should().Be(HttpStatusCode.Accepted);
        }
Example #5
0
        public void Validate_When_Filtered_On_Provider_State()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(_pactAsString);

            var dad = Stub.Create(9000).FromPactbroker(FakePactBrokerUrl);

            dad.FilterOnProviderState("Dad has enough money and an advice");

            var response = DoHttpPost("/please/give/me/some/money");

            dad.Dispose();
            fakePactBroker.Dispose();

            response.StatusCode.Should().Be(HttpStatusCode.Accepted);
        }
Example #6
0
        public void Validate_When_Filters_Are_Cleared()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(_pactAsString);

            var dad = Stub.Create(9000).FromPactbroker(FakePactBrokerUrl);

            dad.FilterOnProviderState("Dad has enough money and an advice");
            dad.FilterOnDescription("a request for money or advice");
            dad.ClearFilters();

            var response = DoHttpPost("/please/give/me/some/money");

            dad.Dispose();
            fakePactBroker.Dispose();

            response.StatusCode.Should().Be(HttpStatusCode.OK);
        }
Example #7
0
        public void Validate_Max_Execution_Time()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(PactAsJson);

            var fakeStopWatch = new FakeStopWatch {
                Elapsed = new TimeSpan(0, 0, 0, 1234)
            };
            var fakeLapStopWatch = new FakeStopWatch {
                Elapsed = new TimeSpan(0, 0, 0, 1234)
            };
            var performance = new Performance(FakePactBrokerUrl, fakeStopWatch, fakeLapStopWatch);

            performance.Run(() => { System.Threading.Thread.Sleep(1); }, 10);

            fakePactBroker.Dispose();

            Performance.Round(performance.MaxExecutionTime.TotalMilliseconds).Should().Be(1234000);
        }
Example #8
0
        public void Validate_Average_Execution_Time()
        {
            var fakePactBroker = new FakePactBroker(FakePactBrokerUrl);

            fakePactBroker.RespondWith(PactAsJson);

            var fakeStopWatch = new FakeStopWatch {
                Elapsed = new TimeSpan(0, 0, 0, 1234)
            };
            var fakeLapStopWatch = new FakeStopWatch {
                Elapsed = new TimeSpan(0, 0, 0, 1234)
            };
            var performance = new Performance(FakePactBrokerUrl, fakeStopWatch, fakeLapStopWatch);

            performance.Run(() => { }, 10);

            fakePactBroker.Dispose();

            Performance.Round(performance.AverageExecutionTime.TotalSeconds).Should().Be(123.4);
        }