Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }