public void ShouldLoadSimulation_WhenStartInSimulationModeWithASimulationSource() { var fakeSource = new FileSimulationSource("simulation_test.json"); using (var runner = HoverflyRunner.StartInSimulationMode(fakeSource)) { var simulation = runner.GetSimulation(); Assert.Equal("echo.jsontest.com", simulation.HoverflyData.RequestResponsePair.First().Request.Destination); Assert.Equal(HoverflyMode.Simulate, runner.GetHoverflyMode()); } }
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 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(); }
public void ShouldReturnCorrectSimulationDate() { var fileSimulation = new FileSimulationSource("simulation_test.json"); var simulation = fileSimulation.GetSimulation(); 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"); }
/// <summary> /// Instantiates a runner which runs <see cref="Hoverfly"/> in capture mode. /// </summary> /// <param name="outputFilename">The path and filename where to store recorded simulations.</param> /// <param name="hoverflyConfig">The hoverfly configuration.</param> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInCaptureMode(string outputFilename, HoverflyConfig hoverflyConfig) { var fileSimulation = new FileSimulationSource(outputFilename) as ISimulationDestinationSource; return(StartInCaptureMode(fileSimulation, hoverflyConfig)); }
public void ShouldSaveTheSimulation() { var fileSimulation = new FileSimulationSource("simulation_save_test.json"); var requestHeaders = new Dictionary <string, IList <string> > { { "Content-Type", new List <string> { "application/json" } } }; var request = new Request { Scheme = "http", Destination = "echo.jsontest.com", Method = "GET", Path = "/key/value/three/four", Query = "name=test", Headers = requestHeaders }; var responseHeaders = new Dictionary <string, IList <string> > { { "Content-Type", new List <string> { "application/json" } } }; var response = new Response { Status = 200, Body = "{\n \"three\": \"four\",\n \"key\": \"value\"\n}\n", EncodedBody = false, Headers = responseHeaders }; var simulation = new Simulation( new HoverflyData( new List <RequestResponsePair> { new RequestResponsePair(request, response) }, new GlobalActions( new List <DelaySettings> { new DelaySettings(urlPattern: "echo.jsontest.com", delay: 2000) }) ), new HoverflyMetaData()); fileSimulation.SaveSimulation(simulation); var fileSimulation2 = new FileSimulationSource("simulation_save_test.json"); var simulation2 = fileSimulation2.GetSimulation(); var expectedRequest = simulation2.HoverflyData.RequestResponsePair.First().Request; var expectedresponse = simulation2.HoverflyData.RequestResponsePair.First().Response; var expectedGlobalActionDelay = simulation2.HoverflyData.GlobalActions.Delays.First(); Assert.Equal(expectedGlobalActionDelay.Delay, simulation.HoverflyData.GlobalActions.Delays.First().Delay); Assert.Equal(expectedGlobalActionDelay.UrlPattern, simulation.HoverflyData.GlobalActions.Delays.First().UrlPattern); Assert.Equal(expectedRequest.Method, request.Method); Assert.Equal(expectedRequest.Path, request.Path); Assert.Equal(expectedRequest.Query, request.Query); Assert.Equal(expectedRequest.Destination, request.Destination); Assert.Equal(expectedRequest.Scheme, request.Scheme); Assert.Equal(expectedRequest.Headers["Content-Type"][0], request.Headers["Content-Type"][0]); Assert.Equal(expectedresponse.Status, response.Status); Assert.Equal(expectedresponse.Body, response.Body); Assert.Equal(expectedresponse.EncodedBody, response.EncodedBody); Assert.Equal(expectedresponse.Headers["Content-Type"][0], response.Headers["Content-Type"][0]); // Clean up the test File.Delete("simulation_save_test.json"); }