Пример #1
0
        public void ShouldUseRemoteHovervyInstance()
        {
            var config = HoverflyConfig.Config().SetHoverflyBasePath(HoverFlyTestConfig.PackagePath);

            using (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 simulation = hoverfly.GetSimulation();

                var config2 = HoverflyConfig.Config().UseRemoteInstance(config.RemoteHost, config.ProxyPort, config.AdminPort);
                using (var reuseHoverfly = new Hoverfly(config: config2))
                {
                    var simulation2 = reuseHoverfly.GetSimulation();

                    Assert.Equal(hoverfly.GetAdminPort(), reuseHoverfly.GetAdminPort());
                    Assert.Equal(hoverfly.GetProxyPort(), reuseHoverfly.GetProxyPort());
                    Assert.Equal(simulation.HoverflyData.RequestResponsePair.First().Response.Body, simulation2.HoverflyData.RequestResponsePair.First().Response.Body);
                }
            }
        }
Пример #2
0
        public void ShouldGetHeaderInTheSimulation_WhenCapturingSpecificHeader()
        {
            var config = HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath();

            config.SetCaptureHeaders("My-Header");

            using (var hoverfly = new Hoverfly(HoverflyMode.Capture, config))
            {
                hoverfly.Start();

                var header = new Dictionary <string, string> {
                    { "My-Header", "Value" }
                };

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

                var simulation     = hoverfly.GetSimulation();
                var capturedHeader = simulation.HoverflyData.RequestResponsePair.First().Request.Headers;

                Assert.NotNull(capturedHeader);
                Assert.Equal("My-Header", capturedHeader.First().Key);
            }
        }
Пример #3
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");
            }
        }
Пример #4
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);
            }
        }
Пример #5
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");
        }