public void TestStartup()
        {
            AutoResetEvent           are     = new AutoResetEvent(false);
            var                      archive = new LastModifiedArchive(monitorFolder);
            DirectoryScanningMonitor monitor = new DirectoryScanningMonitor(monitorFolder, archive);

            monitor.DirectoryAdded += (o, e) => { are.Set(); };
            monitor.AddDirectory(testFolder);
            Assert.IsTrue(are.WaitOne(WaitInterval));

            int count = 0;

            monitor.FileChanged += (o, e) => {
                if (e.EventType == FileEventType.FileAdded)
                {
                    count++;
                    if (count == numStartingFiles)
                    {
                        are.Set();
                    }
                }
            };
            monitor.UpdateArchives();

            Assert.IsTrue(are.WaitOne(WaitInterval));
            Assert.AreEqual(numStartingFiles, archive.GetFiles().Count(), String.Format("only found {0} files in the archive", archive.GetFiles().Count()));

            foreach (var fileName in Directory.EnumerateFiles(testFolder))
            {
                Assert.IsTrue(archive.ContainsFile(fileName));
                Assert.IsFalse(archive.IsOutdated(fileName));
                Assert.AreEqual(File.GetLastWriteTime(fileName), archive.GetLastModifiedTime(fileName));
            }
        }
        public void TestFileChanges()
        {
            var archive = new LastModifiedArchive(monitorFolder);
            DirectoryScanningMonitor monitor = new DirectoryScanningMonitor(monitorFolder, archive);

            monitor.ScanInterval = 1;
            monitor.AddDirectory(testFolder);
            monitor.UpdateArchives();

            AutoResetEvent are = new AutoResetEvent(false);
            var            expectedEventType = FileEventType.FileAdded;
            var            expectedFileName  = Path.GetFullPath(Path.Combine(testFolder, "new.txt"));

            monitor.FileChanged += (o, e) => {
                if (e.EventType == expectedEventType && e.FilePath == expectedFileName)
                {
                    are.Set();
                }
            };
            monitor.StartMonitoring();

            File.Create(expectedFileName).Close();
            Assert.IsTrue(are.WaitOne(WaitInterval));

            expectedEventType = FileEventType.FileChanged;
            var expectedLastWriteTime = DateTime.Now;

            File.SetLastWriteTime(expectedFileName, expectedLastWriteTime);
            Assert.IsTrue(are.WaitOne(WaitInterval));
            Assert.AreEqual(expectedLastWriteTime, archive.GetLastModifiedTime(expectedFileName));

            expectedEventType = FileEventType.FileDeleted;
            File.Delete(expectedFileName);
            Assert.IsTrue(are.WaitOne(WaitInterval));
        }