public void TestBackgroundWorker_ProcessNewFiles() { // Create a test directory to monitor var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Assert.IsNotNull(dir); var testDir = Path.Combine(dir, "TestBackgroundWorker"); if (Directory.Exists(testDir)) { Directory.Delete(testDir, true); } Assert.IsFalse(Directory.Exists(testDir)); Directory.CreateDirectory(testDir); Assert.IsTrue(Directory.Exists(testDir)); var appControl = new TestAppControl(); var logger = new TestLogger(); var processControl = new TestProcessControl(logger); var mainSettings = new MainSettings { FolderToWatch = testDir, InstrumentType = "NoInstrument", ResultsWindowString = "31", AcquisitionTimeString = "0" }; // Start the background worker. var backgroundWorker = new AutoQCBackgroundWorker(appControl, processControl, logger); backgroundWorker.Start(mainSettings); Assert.IsTrue(backgroundWorker.IsRunning()); // Create a new file in the test directory. Thread.Sleep(1000); CreateNewFile(testDir, "test1.txt"); // Wait till the the file has been processed. while (!processControl.IsDone()) { Thread.Sleep(500); } Assert.IsTrue(backgroundWorker.IsRunning()); // Create another file in the test directory. Thread.Sleep(1000); CreateNewFile(testDir, "test2.txt"); // Wait till the the file has been processed. // Process4 returns exit code 1 both times. This should stop the program. while (!processControl.IsDone()) { Thread.Sleep(500); } // Assert.IsTrue(appControl.Waiting); Thread.Sleep(2 * AutoQCBackgroundWorker.WAIT_5SEC); Assert.IsTrue(appControl.Stopped); Assert.AreEqual(Regex.Replace(logger.GetLog(), @"\s+", ""), Regex.Replace(GetExpectedLog_ProcessNew(), @"\s+", "")); }
public void TestBackgroundWorker_ProcessNewFiles() { // Create a test directory to monitor var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Assert.IsNotNull(dir); var testDir = Path.Combine(dir, "TestBackgroundWorker"); if (Directory.Exists(testDir)) { Directory.Delete(testDir, true); } Assert.IsFalse(Directory.Exists(testDir)); Directory.CreateDirectory(testDir); Assert.IsTrue(Directory.Exists(testDir)); var appControl = new TestAppControl(); var logger = new TestLogger(); var processControl = new TestProcessControl(logger); var mainSettings = new MainSettings { FolderToWatch = testDir, InstrumentType = "NoInstrument", ResultsWindowString = "31", AcquisitionTimeString = "0" }; // Start the background worker. var backgroundWorker = new AutoQCBackgroundWorker(appControl, processControl, logger); backgroundWorker.Start(mainSettings); Assert.IsTrue(backgroundWorker.IsRunning()); // Create a new file in the test directory. Thread.Sleep(1000); CreateNewFile(testDir, "test1.txt"); // Wait till the the file has been processed. while (!processControl.IsDone()) { Thread.Sleep(500); } Assert.IsTrue(backgroundWorker.IsRunning()); // Create another file in the test directory. Thread.Sleep(1000); CreateNewFile(testDir, "test2.txt"); // Wait till the the file has been processed. // Process4 returns exit code 1. This should put the file in the re-import queue. while (!processControl.IsDone()) { Thread.Sleep(500); } // Assert.IsTrue(appControl.Waiting); Thread.Sleep(2 * AutoQCBackgroundWorker.WAIT_FOR_NEW_FILE); //Assert.IsTrue(appControl.Waiting); Assert.AreEqual(Regex.Replace(logger.GetLog(), @"\s+", ""), Regex.Replace(GetExpectedLog_ProcessNew(), @"\s+", "")); }
public void TestBackgroundWorker_ProcessNewFiles() { // Create a test directory to monitor var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Assert.IsNotNull(dir); var testDir = Path.Combine(dir, "TestBackgroundWorker"); if (Directory.Exists(testDir)) { Directory.Delete(testDir, true); } Assert.IsFalse(Directory.Exists(testDir)); Directory.CreateDirectory(testDir); Assert.IsTrue(Directory.Exists(testDir)); var appControl = new TestAppControl(); var logger = new TestLogger(); var processControl = new TestProcessControl(logger); var mainSettings = MainSettings.GetDefault(); mainSettings.FolderToWatch = testDir; mainSettings.InstrumentType = "NoInstrument"; AutoQcConfig config = new AutoQcConfig(); config.MainSettings = mainSettings; config.PanoramaSettings = PanoramaSettings.GetDefault(); config.Name = "Test Config"; config.IsEnabled = true; var configRunner = new ConfigRunner(config, appControl); // Start the background worker. // configRunner.Start(); //Thread.Sleep(1000); // Assert.IsTrue(configRunner.IsBusy()); // Create a new file in the test directory. // Thread.Sleep(1000); CreateNewFile(testDir, "test1.txt"); // // Wait till the the file has been processed. // while (!processControl.IsDone()) // { // Thread.Sleep(500); // } // Assert.IsTrue(configRunner.IsRunning()); // // // Create another file in the test directory. // Thread.Sleep(1000); // CreateNewFile(testDir, "test2.txt"); // // // Wait till the the file has been processed. // // Process4 returns exit code 1. This should put the file in the re-import queue. // while (!processControl.IsDone()) // { // Thread.Sleep(500); // } // // // Assert.IsTrue(appControl.Waiting); // Thread.Sleep(2 * AutoQCBackgroundWorker.WAIT_FOR_NEW_FILE); // //Assert.IsTrue(appControl.Waiting); // // Assert.AreEqual(Regex.Replace(logger.GetLog(), @"\s+", ""), // Regex.Replace(GetExpectedLog_ProcessNew(), @"\s+", "")); }