public async Task StartNgrok_ShouldStartNgrok_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); // ACT ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ASSERT var downloadedString = await HttpClient.GetStringAsync("http://localhost:4040/api/"); Assert.False(string.IsNullOrWhiteSpace(downloadedString)); }
public async Task RegisterAuthToken_ThrowsExptionUsingRegisterAuthTokenWhileAlreadyStarted_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); // ACT ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ASSERT var ex = await Assert.ThrowsAsync <Exception>(async() => await ngrokManager.RegisterAuthTokenAsync("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")); Assert.Equal( "The Ngrok process is already running. Please use StopNgrok() and then register the AuthToken again.", ex.Message); }
public async Task StartTunnel_StartTunnelDTOIsNullArgumentNullException_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); // ACT ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var ex = await Assert.ThrowsAsync <ArgumentNullException>(async() => await ngrokManager.StartTunnelAsync(null)); // ASSERT Assert.Equal("Value cannot be null. (Parameter 'startTunnelDto')", ex.Message); }
public async Task ListTunnels_StartTunnel8080AndCheckTheList_True() { // ARRANGE var are = new AutoResetEvent(false); if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "foundryvtt", proto = "http", addr = "30000", bind_tls = "false" }; await ngrokManager.StartTunnelAsync(startTunnelDto); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ACT are.WaitOne(TimeSpan.FromSeconds(1)); var httpResponseMessage = await ngrokManager.ListTunnelsAsync(); var tunnelDetail = JsonSerializer.Deserialize <TunnelsDetailsDTO>( await httpResponseMessage.Content.ReadAsStringAsync()); // ASSERT Assert.Equal("foundryvtt", tunnelDetail.Tunnels[0].Name); }
public async Task RegisterAuthToken_AddNewAuthTokenAfterStop_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } var are = new AutoResetEvent(false); File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); DirectoryInfo path = SetNgrokYml(); var ngrokManager = new NgrokManager(); ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ACT ngrokManager.StopNgrok(); //Wait for ngrok to stop, it can be slow on some systems. Thread.Sleep(1000); await ngrokManager.RegisterAuthTokenAsync("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); // ASSERT are.WaitOne(TimeSpan.FromSeconds(1)); // wait for the ngrok process to start and write the file string acualNgrokYml = null; if (OperatingSystem.IsWindows()) { acualNgrokYml = File.ReadAllText($"{path.FullName + Path.DirectorySeparatorChar}ngrok.yml"); } if (OperatingSystem.IsLinux()) { acualNgrokYml = File.ReadAllText($"{path.FullName + Path.DirectorySeparatorChar}ngrok.yml"); } Assert.Equal("authtoken: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", acualNgrokYml); }
public async Task StartTunnel_TestOptionalRegions_True(string regionNameShort, string regionNameFull) { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var parsedEnum = (NgrokManager.Region)Enum.Parse(typeof(NgrokManager.Region), regionNameFull, true); var ngrokManager = new NgrokManager(); // ACT ngrokManager.StartNgrok(parsedEnum); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "test", proto = "http", addr = "30000", bind_tls = "false" }; var httpResponseMessage = await ngrokManager.StartTunnelAsync(startTunnelDto); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ASSERT var tunnelDetail = JsonSerializer.Deserialize <TunnelDetailDTO>( await httpResponseMessage.Content.ReadAsStringAsync()); Assert.Contains($".{regionNameShort}.", tunnelDetail.PublicUrl.ToString()); }
public async Task DeleteCapturedRequests_Return204WithNoBody_True() { // ARRANGE var are = new AutoResetEvent(false); if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "foundryvtt", proto = "http", addr = "30000", bind_tls = "false" }; await ngrokManager.StartTunnelAsync(startTunnelDto); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ACT are.WaitOne(TimeSpan.FromSeconds(1)); var httpResponseMessage = await ngrokManager.DeleteCapturedRequests(); // ASSERT Assert.Equal(HttpStatusCode.NoContent, httpResponseMessage.StatusCode); }
public async Task StopTunnel_StopATunnelThatIsRunning_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "foundryvtt", proto = "http", addr = "30000", bind_tls = "false" }; await ngrokManager.StartTunnelAsync(startTunnelDto); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); // ACT var stopTunnel = await ngrokManager.StopTunnelAsync("foundryvtt"); // ASSERT Assert.Equal(HttpStatusCode.NoContent, stopTunnel.StatusCode); // Should return 204 status code with no content }
public async Task StartTunnel_UseSubDomainGuid_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var newGuid = Guid.NewGuid().ToString(); var ngrokManager = new NgrokManager(); // ACT ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "foundryvtt", proto = "http", addr = "30000", bind_tls = "false", subdomain = newGuid }; await ngrokManager.StartTunnelAsync(startTunnelDto); // ASSERT var downloadedString = await HttpClient.GetStringAsync("http://localhost:4040/api/tunnels/foundryvtt"); Assert.Contains(newGuid, downloadedString); }
public async Task StopTunnel_StopTunnelNameIsNullArgumentNullException_True() { // ARRANGE if (!Directory.Exists(_downloadFolder)) { Directory.CreateDirectory(_downloadFolder); } File.WriteAllBytes($"{_downloadFolder}ngrok-stable-amd64.zip", _ngrokBytes); var fastZip = new FastZip(); fastZip.ExtractZip($"{_downloadFolder}ngrok-stable-amd64.zip", _downloadFolder, null); SetNgrokYml(); var ngrokManager = new NgrokManager(); ngrokManager.StartNgrok(); //Wait for ngrok to start, it can be slow on some systems. Thread.Sleep(1000); var startTunnelDto = new StartTunnelDTO { name = "foundryvtt", proto = "http", addr = "30000", bind_tls = "false" }; await ngrokManager.StartTunnelAsync(startTunnelDto); // ACT var ex = await Assert.ThrowsAsync <ArgumentException>(async() => await ngrokManager.StopTunnelAsync("")); // ASSERT Assert.Equal("Value cannot be null or whitespace. (Parameter 'name')", ex.Message); }