Wait() public method

public Wait ( System.TimeSpan timeout, bool expectedToChange, string errorMessage ) : void
timeout System.TimeSpan
expectedToChange bool
errorMessage string
return void
示例#1
0
        public void ExitOnChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"--exit-on-change -- {scenario.StatusFile} --no-exit");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Change a file
                var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                var programCs    = File.ReadAllText(fileToChange);
                File.WriteAllText(fileToChange, programCs);

                Waiters.WaitForProcessToStop(
                    scenario.WatcherProcess.Id,
                    _defaultTimeout,
                    expectedToStop: true,
                    errorMessage: "The watcher did not stop");

                // Check that the first child process is no longer running
                var ids            = File.ReadAllLines(scenario.StatusFile);
                var firstProcessId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    firstProcessId,
                    TimeSpan.FromSeconds(1),
                    expectedToStop: true,
                    errorMessage: $"PID: {firstProcessId} is still alive");
            }
        }
示例#2
0
            public void Start()
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(StartedFile))
                {
                    RunDotNetWatch(StatusFile, Path.Combine(_scenario.WorkFolder, TestAppName));

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {StartedFile}");
                }

                Waiters.WaitForFileToBeReadable(StartedFile, _defaultTimeout);
            }
示例#3
0
        public void DeleteCompiledFile()
        {
            using (var scenario = new GlobbingAppScenario())
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.Start();

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Foo.cs");
                    File.Delete(fileToChange);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
        }
示例#4
0
        public void DeleteSourceFolder()
        {
            using (var scenario = new GlobbingAppScenario())
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.Start();

                    var folderToDelete = Path.Combine(scenario.TestAppFolder, "include");
                    Directory.Delete(folderToDelete, recursive: true);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
        }
示例#5
0
        public void AddCompiledFile()
        {
            // Add a file in a folder that's included in compilation
            using (var scenario = new GlobbingAppScenario())
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.Start();

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Bar.cs");
                    File.WriteAllText(fileToChange, "");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
        }
示例#6
0
        public void AddCompiledFile()
        {
            // Add a file in a folder that's included in compilation
            using (var scenario = new GlobbingAppScenario())
            using (var wait = new WaitForFileToChange(scenario.StartedFile))
            {
                scenario.Start();

                var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Bar.cs");
                File.WriteAllText(fileToChange, "");

                wait.Wait(_defaultTimeout,
                    expectedToChange: true,
                    errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
            }
        }
示例#7
0
        public void ChangeFileInDependency()
        {
            using (var scenario = new AppWithDepsScenario())
            {
                scenario.Start();
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    var fileToChange = Path.Combine(scenario.DependencyFolder, "Foo.cs");
                    var programCs = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
            }
        }
示例#8
0
        public void ChangeFileInDependency()
        {
            using (var scenario = new AppWithDepsScenario())
            {
                scenario.Start();
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    var fileToChange = Path.Combine(scenario.DependencyFolder, "Foo.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
            }
        }
示例#9
0
        // Change a file included in compilation
        private void ChangeCompiledFile(bool usePollingWatcher)
        {
            using (var scenario = new GlobbingAppScenario())
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.UsePollingWatcher = usePollingWatcher;

                    scenario.Start();

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Foo.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
        }
示例#10
0
        public void RestartProcessThatTerminatesAfterFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile}");

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for the app to exit
                Waiters.WaitForFileToBeReadable(scenario.StartedFile, _defaultTimeout);
                var ids = File.ReadAllLines(scenario.StatusFile);
                var procId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    procId,
                    _defaultTimeout,
                    expectedToStop: true,
                    errorMessage: "Test app did not exit");

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    // On Unix the file write time is in 1s increments;
                    // if we don't wait, there's a chance that the polling
                    // watcher will not detect the change
                    Thread.Sleep(1000);

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
            }
        }
示例#11
0
        public void RestartProcessThatTerminatesAfterFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile}");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for the app to exit
                Waiters.WaitForFileToBeReadable(scenario.StartedFile, _defaultTimeout);
                var ids    = File.ReadAllLines(scenario.StatusFile);
                var procId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    procId,
                    _defaultTimeout,
                    expectedToStop: true,
                    errorMessage: "Test app did not exit");

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    // On Unix the file write time is in 1s increments;
                    // if we don't wait, there's a chance that the polling
                    // watcher will not detect the change
                    Thread.Sleep(1000);

                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }
            }
        }
示例#12
0
        public void RestartProcessOnFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile} --no-exit");

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs    = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                              expectedToChange: true,
                              errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }

                // Check that the first child process is no longer running
                Waiters.WaitForFileToBeReadable(scenario.StatusFile, _defaultTimeout);
                var ids            = File.ReadAllLines(scenario.StatusFile);
                var firstProcessId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    firstProcessId,
                    TimeSpan.FromSeconds(1),
                    expectedToStop: true,
                    errorMessage: $"PID: {firstProcessId} is still alive");
            }
        }
示例#13
0
        public void RestartProcessOnFileChange()
        {
            using (var scenario = new NoDepsAppScenario())
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    scenario.RunDotNetWatch($"run {scenario.StatusFile} --no-exit");

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"File not created: {scenario.StartedFile}");
                }

                // Then wait for it to restart when we change a file
                using (var wait = new WaitForFileToChange(scenario.StartedFile))
                {
                    var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs");
                    var programCs = File.ReadAllText(fileToChange);
                    File.WriteAllText(fileToChange, programCs);

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
                }

                // Check that the first child process is no longer running
                Waiters.WaitForFileToBeReadable(scenario.StatusFile, _defaultTimeout);
                var ids = File.ReadAllLines(scenario.StatusFile);
                var firstProcessId = int.Parse(ids[0]);
                Waiters.WaitForProcessToStop(
                    firstProcessId,
                    TimeSpan.FromSeconds(1),
                    expectedToStop: true,
                    errorMessage: $"PID: {firstProcessId} is still alive");
            }
        }
示例#14
0
            public void Start()
            {
                // Wait for the process to start
                using (var wait = new WaitForFileToChange(StatusFile))
                {
                    RunDotNetWatch($"run {StatusFile}", Path.Combine(_scenario.WorkFolder, AppWithDeps));

                    wait.Wait(_defaultTimeout,
                        expectedToChange: true,
                        errorMessage: $"File not created: {StatusFile}");
                }

                Waiters.WaitForFileToBeReadable(StatusFile, _defaultTimeout);
            }
示例#15
0
        // Change a file included in compilation
        private void ChangeCompiledFile(bool usePollingWatcher)
        {
            using (var scenario = new GlobbingAppScenario())
            using (var wait = new WaitForFileToChange(scenario.StartedFile))
            {
                scenario.UsePollingWatcher = usePollingWatcher;

                scenario.Start();

                var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Foo.cs");
                var programCs = File.ReadAllText(fileToChange);
                File.WriteAllText(fileToChange, programCs);

                wait.Wait(_defaultTimeout,
                    expectedToChange: true,
                    errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
            }
        }
示例#16
0
        public void DeleteCompiledFile()
        {
            using (var scenario = new GlobbingAppScenario())
            using (var wait = new WaitForFileToChange(scenario.StartedFile))
            {
                scenario.Start();

                var fileToChange = Path.Combine(scenario.TestAppFolder, "include", "Foo.cs");
                File.Delete(fileToChange);

                wait.Wait(_defaultTimeout,
                    expectedToChange: true,
                    errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
            }
        }
示例#17
0
        public void DeleteSourceFolder()
        {
            using (var scenario = new GlobbingAppScenario())
            using (var wait = new WaitForFileToChange(scenario.StartedFile))
            {
                scenario.Start();

                var folderToDelete = Path.Combine(scenario.TestAppFolder, "include");
                Directory.Delete(folderToDelete, recursive: true);

                wait.Wait(_defaultTimeout,
                    expectedToChange: true,
                    errorMessage: $"Process did not restart because {scenario.StartedFile} was not changed");
            }
        }