public void Initialize() { _expectedProcessCount = 0; _tempFile = Path.GetTempFileName(); _mockHttp = new MockHttpMessageHandler(); _client = new HttpClient(_mockHttp); _webApps = new Dictionary <string, WebAppConfig> { { "fakeApp", new WebAppConfig("1234") { SubDomain = "fake-app", HostName = "dev.fake-app.com", Region = "us" } } }; _mockErrorDisplay = new Mock <IErrorDisplayFunc>(); _mockErrorDisplay.Setup(x => x.ShowError(It.IsAny <string>())) .Returns(Task.FromResult(0)) .Verifiable("Error display not called."); InitializeUtils("ngrok version 2.3.34\r\n"); _emptyTunnelsResponse = new NgrokTunnelsApiResponse { tunnels = new Tunnel[0], uri = "" }; _expectedRequest = new NgrokTunnelApiRequest { addr = "localhost:1234", host_header = "localhost:1234", name = "fakeApp", proto = "http", subdomain = "fake-app", hostname = "dev.fake-app.com" }; }
public void Initialize() { _mockHttp = new MockHttpMessageHandler(); _client = new HttpClient(_mockHttp); _webApps = new Dictionary <string, WebAppConfig> { { "fakeApp", new WebAppConfig { PortNumber = 1234, SubDomain = "fake-app" } } }; _mockErrorDisplay = new Mock <IErrorDisplayFunc>(); _mockErrorDisplay.Setup(x => x.ShowError(It.IsAny <string>())) .Returns(Task.FromResult(0)) .Verifiable("Error display not called."); _ngrokProcess = new FakeNgrokProcess(""); _utils = new NgrokUtils(_webApps, "", _mockErrorDisplay.Object.ShowError, _client, _ngrokProcess); _emptyTunnelsResponse = new NgrokTunnelsApiResponse { tunnels = new Tunnel[0], uri = "" }; _expectedRequest = new NgrokTunnelApiRequest { addr = "localhost:1234", host_header = "localhost:1234", name = "fakeApp", proto = "http", subdomain = "fake-app" }; }
public async Task <Tunnel[]> GetTunnelListAsync() { var response = await _ngrokApi.GetAsync("/api/tunnels"); if (response.IsSuccessStatusCode) { var responseText = await response.Content.ReadAsStringAsync(); NgrokTunnelsApiResponse apiResponse = null; try { apiResponse = JsonConvert.DeserializeObject <NgrokTunnelsApiResponse>(responseText); } catch (Exception ex) { _logger.LogError("Failed to deserialize ngrok tunnel response"); throw ex; } return(apiResponse.tunnels); } return(null); }
public async Task TestStartTunnelExisting() { var tunnels = new NgrokTunnelsApiResponse { tunnels = new [] { new Tunnel { config = new Config { addr = "localhost:1234", inspect = true }, name = "fakeApp", proto = "https", public_url = "https://fake-app.ngrok.io" }, new Tunnel { config = new Config { addr = "localhost:1234", inspect = true }, name = "fakeApp", proto = "http", public_url = "http://fake-app.ngrok.io" } }, uri = "" }; _mockHttp.Expect("http://localhost:4040/api/tunnels") .Respond("application/json", JsonConvert.SerializeObject(tunnels)); await _utils.StartTunnelsAsync(); }