예제 #1
0
        public void ShouldReturnCorrectSimulations_WhenUsingAnExistingSimulateAndWhenAddingOne()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                hoverfly.ImportSimulation(new FileSimulationSource("simulation_test.json"));

                hoverfly.AddSimulation(DslSimulationSource.Dsl(
                                           Service("http://echo.jsontest.com")
                                           .Get("/key/value/six/seven")
                                           .QueryParam("name", "test")
                                           .WillReturn(
                                               Success("Hello World!", "application/json"))));

                var simulation = hoverfly.GetSimulation();

                hoverfly.Stop();

                Assert.Equal("echo.jsontest.com", simulation.HoverflyData.RequestResponsePair.First().Request.Destination.ExactMatch);
                Assert.Equal("/key/value/one/two", simulation.HoverflyData.RequestResponsePair.First().Request.Path.ExactMatch);

                Assert.Equal("echo.jsontest.com", simulation.HoverflyData.RequestResponsePair.Last().Request.Destination.ExactMatch);
                Assert.Equal("/key/value/six/seven", simulation.HoverflyData.RequestResponsePair.Last().Request.Path.ExactMatch);
            }
        }
예제 #2
0
        public void ShouldReturnCorrectSimluationFromHoverfly_WhenImportingSimulation()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                var simulation = CreateTestSimulation();

                hoverfly.ImportSimulation(simulation);

                var expectedSimulation = hoverfly.GetSimulation();

                hoverfly.Stop();

                var expectedRequest  = expectedSimulation.HoverflyData.RequestResponsePair.First().Request;
                var expectedResponse = expectedSimulation.HoverflyData.RequestResponsePair.First().Response;

                Assert.Equal(expectedRequest.Method.ExactMatch, "GET");
                Assert.Equal(expectedRequest.Path.ExactMatch, "/key/value/three/four");
                Assert.Equal(expectedRequest.Destination.ExactMatch, "echo.jsontest.com");
                Assert.Equal(expectedRequest.Scheme.ExactMatch, "http");

                Assert.Equal(expectedResponse.Status, 200);
                Assert.Equal(expectedResponse.Body, "{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n");
            }
        }
예제 #3
0
        public void ShouldReturnCorrectHoverflyMode()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                var mode = hoverfly.GetMode();

                hoverfly.Stop();

                Assert.Equal(HoverflyMode.Simulate, mode);
            }
        }
예제 #4
0
        public void ShouldReturnCorrectHoverflyMode()
        {
            var config   = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);
            var hoverfly = new Hoverfly(HoverflyMode.Simulate, config);

            hoverfly.Start();

            var mode = hoverfly.GetMode();

            hoverfly.Stop();

            Assert.Equal(HoverflyMode.Simulate, mode);
        }
예제 #5
0
        public void ShouldExportSimulation()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Capture, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                GetContentFrom("http://echo.jsontest.com/key/value/one/two");

                //http://localhost:8888/api/v2/simulation
                var destinatonSource = new FileSimulationSource("simulation.json");
                hoverfly.ExportSimulation(destinatonSource);

                hoverfly.Stop();
            }
        }
예제 #6
0
        public void ShouldExportSimulation()
        {
            var config   = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);
            var hoverfly = new Hoverfly(HoverflyMode.Capture, config);

            hoverfly.Start();

            GetContentFrom("http://echo.jsontest.com/key/value/one/two");

            var destinatonSource = new FileSimulationSource("simulation.json");

            hoverfly.ExportSimulation(destinatonSource);

            hoverfly.Stop();
        }
예제 #7
0
        public void ShouldReturnCorrectRestultFromARequest_WhenImportingSimulationAndUsingSimulationMode()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                var simulation = CreateTestSimulation();

                hoverfly.ImportSimulation(simulation);

                var result = GetContentFrom("http://echo.jsontest.com/key/value/three/four?name=test");

                hoverfly.Stop();

                Assert.Equal("{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n", result);
            }
        }
예제 #8
0
        public void ShouldReturnCorrectRestultFromARequest_WhenImportingSimulationAndUsingWebServerMode()
        {
            var config   = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);
            var hoverfly = new Hoverfly(HoverflyMode.WebServer, config);

            hoverfly.Start();

            var simulation = CreateTestSimulation();

            hoverfly.ImportSimulation(simulation);

            var result = GetContentFrom("http://localhost:8500/key/value/three/four?name=test");

            hoverfly.Stop();

            Assert.Equal("{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n", result);
        }
예제 #9
0
        public void ShouldReturnCorrectSimulationDataResult_WhenHoverflyInSimulationMode()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                // The time.jsontest.com returns the current time and milliseconds from the server.
                var result = GetContentFrom("http://time.jsontest.com");

                Thread.Sleep(10);

                var result2 = GetContentFrom("http://time.jsontest.com");

                hoverfly.Stop();

                Assert.Equal(result, result2);
            }
        }
예제 #10
0
        public void ShouldReturnCorrectSimulationDataResult_WhenHoverflyInWebserverModeImportingSimulationData()
        {
            var result = GetContentFrom("http://echo.jsontest.com/key/value/one/two");

            var config   = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);
            var hoverfly = new Hoverfly(HoverflyMode.WebServer, config);

            hoverfly.Start();

            // Simulation_test.json holds a captured result from http://echo.jsontest.com/key/value/one/two
            hoverfly.ImportSimulation(new FileSimulationSource("simulation_test.json"));

            var result2 = GetContentFrom("http://localhost:8500/key/value/one/two");

            hoverfly.Stop();

            Assert.Equal(result, result2);
        }
예제 #11
0
        public void ShouldGetCorrectResponse_WhenUsingDsl()
        {
            var config = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);

            var hoverfly = new Hoverfly(HoverflyMode.Simulate, config);

            hoverfly.Start();

            hoverfly.ImportSimulation(DslSimulationSource.Dsl(
                                          Service("http://echo.jsontest.com")
                                          .Get("/key/value/three/four")
                                          .QueryParam("name", "test")
                                          .WillReturn(Success("{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n", "application/json"))));

            var result = GetContentFrom("http://echo.jsontest.com/key/value/three/four?name=test");

            hoverfly.Stop();

            Assert.Equal("{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n", result);
        }
예제 #12
0
        public async Task ShouldReturnCorrectRestultFromAPutRequest_WhenImportingSimulationAndUsingSimulationMode()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                hoverfly.ImportSimulation(new FileSimulationSource("simulation_test2.json"));

                var httpClient = new HttpClient();

                var content = new StringContent("{\"items\":[{\"sku\":\"6948017\",\"quantity\":2}]}", Encoding.UTF8, "application/json");

                var result = await httpClient.PutAsync("https://echo.jsontest.com/cart", content);

                var contentRestult = await result.Content.ReadAsStringAsync();

                hoverfly.Stop();

                Assert.Equal("{\n   \"one\": \"two\",\n   \"key\": \"value\"\n}\n", contentRestult);
            }
        }
예제 #13
0
        public void ShouldReturnSimluationFromHoverfly_WhenFileSimulationSourceIsUsed()
        {
            var config   = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath);
            var hoverfly = new Hoverfly(HoverflyMode.WebServer, config);

            hoverfly.Start();

            hoverfly.ImportSimulation(new FileSimulationSource("simulation_test.json"));

            var simulation = hoverfly.GetSimulation();

            hoverfly.Stop();

            var request  = simulation.HoverflyData.RequestResponsePair.First().Request;
            var response = simulation.HoverflyData.RequestResponsePair.First().Response;

            Assert.Equal(request.Method, "GET");
            Assert.Equal(request.Path, "/key/value/one/two");
            Assert.Equal(request.Destination, "echo.jsontest.com");
            Assert.Equal(request.Scheme, "http");

            Assert.Equal(response.Status, 200);
            Assert.Equal(response.Body, "{\n   \"one\": \"two\",\n   \"key\": \"value\"\n}\n");
        }