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); } } }
public void ShouldReturnCorrectConfiguredAdminPort() { var config = HoverflyConfig.Config().SetAdminPort(8880); var hoverfly = new Hoverfly(HoverflyMode.Simulate, config); Assert.Equal(8880, hoverfly.GetAdminPort()); }
public void ShouldReturnCorrectSimluationFromHoverfly_WhenImportingSimulation() { var config = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath); var hoverfly = new Hoverfly(HoverflyMode.Simulate, config); 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, "GET"); Assert.Equal(expectedRequest.Path, "/key/value/three/four"); Assert.Equal(expectedRequest.Destination, "echo.jsontest.com"); Assert.Equal(expectedRequest.Scheme, "http"); Assert.Equal(expectedResponse.Status, 200); Assert.Equal(expectedResponse.Body, "{\n \"three\": \"four\",\n \"key\": \"value\"\n}\n"); }
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); }
/// <summary> /// Provide access to Hoverfly to start and stop simulation or capture HTTP calls. /// </summary> /// <param name="hoverflyMode">The <see cref="HoverflyMode"/> Hoverfly should be started in. Default is Simulate if nothing is specified.</param> /// <param name="config">Hoverfly configurations. <see cref="HoverflyConfig"/></param> /// <param name="hoverflyClient">Hoverfly client, by default the <see cref="HoverflyClient"/> is used to accessing the Hoverfly process REST API.</param> public Hoverfly( HoverflyMode hoverflyMode = HoverflyMode.Simulate, HoverflyConfig config = null, IHoverflyClient hoverflyClient = null) { _hoverflyMode = hoverflyMode; _hoverflyConfig = config ?? HoverflyConfig.Config(); _hoverflyClient = hoverflyClient ?? new HoverflyClient( new Uri($"{_hoverflyConfig.RemoteHost}:{_hoverflyConfig.AdminPort}"), _hoverflyConfig.Logger); }
private Hoverfly.Core.Hoverfly HoverflySetup(Hoverfly.Core.HoverflyMode hoverflyMode) { var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var hoverflyPath = Path.Combine(assemblyPath, @"Hoverfly"); var cfg = HoverflyConfig.Config(); cfg = cfg.SetHoverflyBasePath(hoverflyPath); var hoverfly = new Hoverfly.Core.Hoverfly(hoverflyMode, cfg); return(hoverfly); }
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(); }
/// <summary> /// Provide access to Hoverfly to start and stop simulation or capture HTTP calls. /// </summary> /// <param name="hoverflyMode">The <see cref="HoverflyMode"/> Hoverfly should be started in. Default is Simulate if nothing is specified.</param> /// <param name="config">Hoverfly configurations. <see cref="HoverflyConfig"/></param> /// <param name="loggerFactory">A logger factory for creating a logger to log messages.</param> /// <param name="hoverflyClient">Hoverfly client, by default the <see cref="HoverflyClient"/> is used to accessing the Hoverfly process REST API.</param> public Hoverfly( HoverflyMode hoverflyMode = HoverflyMode.Simulate, HoverflyConfig config = null, ILoggerFactory loggerFactory = null, IHoverflyClient hoverflyClient = null) { _hoverflyMode = hoverflyMode; _hoverflyConfig = config ?? HoverflyConfig.Config(); _logger = loggerFactory?.Create(GetType().Name); _hoverflyClient = hoverflyClient ?? new HoverflyClient( new Uri($"{_hoverflyConfig.RemoteHost}:{_hoverflyConfig.AdminPort}"), _logger); }
public void ShouldReturnCorrectRestultFromARequest_WhenImportingSimulationAndUsingSimulationMode() { var config = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath); var hoverfly = new Hoverfly(HoverflyMode.Simulate, config); 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() { var config = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath); var hoverfly = new Hoverfly(HoverflyMode.Simulate, config); 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 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); }
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); }
public void ShouldBeDelay_WhenAddingADelaryToRequestWithDsl() { var config = HoverflyConfig.Config().SetHoverflyBasePath(_hoverflyPath); using (var hoverfly = new Hoverfly(HoverflyMode.Simulate, config)) { 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 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"); }
/// <summary> /// Instantiates a runner which runs <see cref="Hoverfly"/> in simulate mode. /// </summary> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInSimulationMode() { return(StartInSimulationMode(HoverflyConfig.Config())); }
/// <summary> /// Instantiates a runner which runs <see cref="Hoverfly"/> in capture mode. /// </summary> /// <param name="output">The <see cref="ISimulationDestinationSource"/> to store recorded simulations.</param> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInCaptureMode(ISimulationDestinationSource output) { return(StartInCaptureMode(output, HoverflyConfig.Config())); }
/// <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> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInCaptureMode(string outputFilename) { return(StartInCaptureMode(outputFilename, HoverflyConfig.Config())); }
/// <summary> /// Instantiates a runner which runs <see cref="Hoverfly"/> in Spy mode. /// </summary> /// <param name="simulationSource">The simulation to import.</param> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInSpyMode(ISimulationSource simulationSource) { return(StartInSpyMode(simulationSource, HoverflyConfig.Config())); }
/// <summary> /// Instantiates a runner which runs <see cref="Hoverfly"/> in Spy mode. /// </summary> /// <param name="simulationFile">The simulation to import.</param> /// <returns>Returns <see cref="HoverflyRunner"/>.</returns> public static HoverflyRunner StartInSpyMode(string simulationFile) { return(StartInSpyMode(simulationFile, HoverflyConfig.Config())); }
public static HoverflyConfig GetHoverFlyConfigWIthBasePath() { return(HoverflyConfig.Config().SetHoverflyBasePath(PackagePath)); }