Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }
        public void ShouldReturnCorrectSimulation_WhenUsingSimulateWithDsl()
        {
            using (var runner = HoverflyRunner.StartInSimulationMode())
            {
                runner.Simulate(DslSimulationSource.Dsl(
                                    Service("http://echo.jsontest.com")
                                    .Get("/key/value/three/four")
                                    .QueryParam("name", "test")
                                    .WillReturn(
                                        Success("Hello World!", "application/json"))));

                var result = GetContentFrom("http://echo.jsontest.com/key/value/three/four?name=test");
                Assert.Equal("Hello World!", result);
            }
        }
Ejemplo n.º 4
0
        public void ShouldReturnCorrectNumberOfRequest_WhenGettingSimulation()
        {
            var service1 = HoverflyDsl.Service("www.my-test1.com")
                           .Get("/1").WillReturn(ResponseCreators.Success("Hello World 1", "plain/text"))
                           .Get("/10").WillReturn(ResponseCreators.Success("Hello World 10", "plain/text"));

            var service2 = HoverflyDsl.Service("www.my-test2.com").Get("/2").WillReturn(ResponseCreators.Success("Hello World 2", "plain/text"));
            var service3 = HoverflyDsl.Service("www.my-test3.com").Get("/3").WillReturn(ResponseCreators.Success("Hello World 3", "plain/text"));

            var dsl = new DslSimulationSource(service1, service2, service3);

            var simulation = dsl.GetSimulation();

            Assert.Equal(4, simulation.HoverflyData.RequestResponsePair.Count);
        }
Ejemplo n.º 5
0
        public void ShouldReturnCorrectDelaySettings_WhenUsingPost()
        {
            var service1 =
                HoverflyDsl.Service("www.my-test1.com/")
                .Post("/1")
                .WithDelay(2000)
                .WillReturn(ResponseCreators.Success("Hello World 1", "text/plain"));

            var dsl = new DslSimulationSource(service1);

            var simulation = dsl.GetSimulation();

            Assert.Equal("www.my-test1.com/1", simulation.HoverflyData.GlobalActions.Delays.First().UrlPattern);
            Assert.Equal(2000, simulation.HoverflyData.GlobalActions.Delays.First().Delay);
            Assert.Equal("POST", simulation.HoverflyData.GlobalActions.Delays.First().HttpMethod);
        }
Ejemplo n.º 6
0
        public void ShouldReturnCorrectNumberDelays_WhenGettingSimulation()
        {
            var service1 = HoverflyDsl.Service("www.my-test1.com")
                           .Get("/1").WithDelay(2000).WillReturn(ResponseCreators.Success("Hello World 1", "text/plain"))
                           .Get("/10").WithDelay(1000).WillReturn(ResponseCreators.Success("Hello World 10", "ptext/plain"));

            var service2 = HoverflyDsl.Service("www.my-test1.com").AddDelay("www.my-test1.com", 4000, HttpMethod.Post);

            var service3 = HoverflyDsl.Service("www.my-test1.com").Put("/test").WithDelay(100).WillReturn(ResponseCreators.Success("Hello World 3", "text/plain"));

            var dsl = new DslSimulationSource(service1, service2, service3);

            var simulation = dsl.GetSimulation();

            Assert.Equal(4, simulation.HoverflyData.GlobalActions.Delays.Count);
        }
Ejemplo n.º 7
0
        public void ShouldGetSimulationResponse_WhenUsingSpyModeAndSimulationDslIsAreadyAddedDuringStart()
        {
            var simulation = DslSimulationSource.Dsl(
                Service("http://echo.jsontest.com")
                .Get("/key/value/three/four")
                .QueryParam("name", "test")
                .WillReturn(
                    Success("MyData", "application/json")));

            using (var runner = HoverflyRunner.StartInSpyMode(simulation, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                var result = GetContentFrom("http://echo.jsontest.com/key/value/three/four?name=test");

                Assert.Equal("MyData", result);
            }
        }
Ejemplo n.º 8
0
        public void ShouldGetCorrectResponse_WhenUsingDsl()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                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");

                Assert.Equal("{\n   \"three\": \"four\",\n   \"key\": \"value\"\n}\n", result);
            }
        }
        public void ShouldReturnCorrectSimulations_WhenUsingAnExistingSimulateAndWhenAddingOne()
        {
            using (var runner = HoverflyRunner.StartInSimulationMode("simulation_test.json"))
            {
                runner.AddSimulation(DslSimulationSource.Dsl(
                                         Service("http://echo.jsontest.com")
                                         .Get("/key/value/six/seven")
                                         .QueryParam("name", "test")
                                         .WillReturn(
                                             Success("Hello World!", "application/json"))));

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

                Assert.Equal("echo.jsontest.com", simulation.HoverflyData.RequestResponsePair.Last().Request.Destination);
                Assert.Equal("/key/value/six/seven", simulation.HoverflyData.RequestResponsePair.Last().Request.Path);
            }
        }
Ejemplo n.º 10
0
        public void ShouldGetSimulationResponse_WhenUsingSpyModeAndSimulationIsAreadyAdded()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Spy, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

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

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

                Assert.Equal("MyData", result);
            }
        }
Ejemplo n.º 11
0
        public void ShouldBeDelay_WhenAddingADelaryToRequestWithDsl()
        {
            using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath()))
            {
                hoverfly.Start();

                hoverfly.ImportSimulation(
                    DslSimulationSource.Dsl(
                        Service("http://echo.jsontest.com")
                        .Get("/key/value/three/four")
                        .WithDelay(2000)
                        .WillReturn(Success("Test", "application/json"))));

                var stopWatch = Stopwatch.StartNew();
                GetContentFrom("http://echo.jsontest.com/key/value/three/four");
                stopWatch.Stop();

                Assert.Equal(true, stopWatch.Elapsed.TotalMilliseconds >= 2000);
            }
        }