public void ShouldStartInSimulationMode() { using (var runner = HoverflyRunner.StartInSimulationMode(HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { Assert.Equal(HoverflyMode.Simulate, runner.GetHoverflyMode()); } }
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); } }
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"); } }
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 ShouldReturnCaptureMode_WhenHoverFlyIsSetToUseCaptureMode() { using (var hoverfly = new Hoverfly(HoverflyMode.Capture, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { hoverfly.Start(); Assert.Equal(HoverflyMode.Capture, hoverfly.GetMode()); } }
public void ShouldStartInCaptureMode() { var fakeDestination = new FakeSimulationDestinationSource(); using (var runner = HoverflyRunner.StartInCaptureMode(fakeDestination, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { Assert.Equal(HoverflyMode.Capture, runner.GetHoverflyMode()); } }
public void ShouldGetExternalResponse_WhenUsingSpyModeAndSimulationIsNotAdded() { using (var runner = HoverflyRunner.StartInSpyMode(HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { var result = GetContentFrom("http://echo.jsontest.com/key/value/one/two?name=testSpy"); Assert.Equal("{\n \"one\": \"two\",\n \"key\": \"value\"\n}\n", result); } }
public void ShouldExportSimulationOnStop_WhenInCaptureMode() { var fakeDestination = new FakeSimulationDestinationSource(); using (var runner = HoverflyRunner.StartInCaptureMode(fakeDestination, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { } Assert.Equal(true, fakeDestination.WasSaved); }
public void ShouldLoadSimulation_WhenStartInSimulationModeWithASimulationSource() { var fakeSource = new FileSimulationSource("simulation_test.json"); using (var runner = HoverflyRunner.StartInSimulationMode(fakeSource, HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { var simulation = runner.GetSimulation(); Assert.Equal("echo.jsontest.com", simulation.HoverflyData.RequestResponsePair.First().Request.Destination.ExactMatch); Assert.Equal(HoverflyMode.Simulate, runner.GetHoverflyMode()); } }
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); } }
public void ShouldReturnCorrectSimulation_WhenUsingSimulateWithDsl() { using (var runner = HoverflyRunner.StartInSimulationMode(HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { 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); } }
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(); } }
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); } }
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); } }
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); } }
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 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); } }
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); } }
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); } }
public void ShouldGetSimulationResponse_WhenUsingSpyModeAndSimulationFromFileIsAreadyAdded() { using (var runner = HoverflyRunner.StartInSpyMode("simulation_test.json", HoverFlyTestConfig.GetHoverFlyConfigWIthBasePath())) { var result = GetContentFrom("http://echo.jsontest.com/key/value/one/two"); Assert.Equal("{\n \"one\": \"two\",\n \"key\": \"value\"\n}\n", result); } }