public void TestRename()
        {
            bool receivedFileAdd = false, receivedFileRename = false;
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);

            archive.FileChanged += (sender, e) => {
                switch (e.EventType)
                {
                case FileEventType.FileAdded:
                    receivedFileAdd = true;
                    break;

                case FileEventType.FileRenamed:
                    receivedFileRename = true;
                    break;
                }
            };
            string pathToFoo = Path.Combine(testDirectory, "foo.txt");
            string pathToBar = Path.Combine(testDirectory, "bar.txt");

            File.Create(pathToFoo).Dispose();

            archive.AddOrUpdateFile(pathToFoo);
            Assert.That(archive.ContainsFile(pathToFoo));
            Assert.That(receivedFileAdd);

            File.Move(pathToFoo, pathToBar);
            Assert.That(archive.IsOutdated(pathToFoo));
            archive.RenameFile(pathToFoo, pathToBar);
            Assert.That(receivedFileRename);
            Assert.That(archive.ContainsFile(pathToBar));
            Assert.IsFalse(archive.ContainsFile(pathToFoo));
        }
        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 TestAddUpdateDelete()
        {
            bool receivedFileAdded = false, receivedFileUpdated = false, receivedFileDeleted = false;
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);

            archive.FileChanged += (sender, e) => {
                switch (e.EventType)
                {
                case FileEventType.FileAdded:
                    receivedFileAdded = true;
                    break;

                case FileEventType.FileChanged:
                    receivedFileUpdated = true;
                    break;

                case FileEventType.FileDeleted:
                    receivedFileDeleted = true;
                    break;
                }
            };

            string fileFoo = Path.Combine(testDirectory, "foo.txt");

            File.Create(fileFoo).Dispose();
            archive.AddOrUpdateFile(fileFoo);
            Assert.That(receivedFileAdded);

            Assert.That(archive.ContainsFile(fileFoo));
            Assert.IsFalse(archive.IsOutdated(fileFoo));

            System.Threading.Thread.Sleep(5000);
            File.AppendAllText(fileFoo, "This is bar!\n");
            Assert.That(archive.IsOutdated(fileFoo));
            archive.AddOrUpdateFile(fileFoo);
            Assert.That(receivedFileUpdated);

            File.Delete(fileFoo);
            Assert.That(archive.IsOutdated(fileFoo));
            archive.DeleteFile(fileFoo);
            Assert.That(receivedFileDeleted);
            Assert.IsFalse(archive.ContainsFile(fileFoo));
        }
        public void TestRelativePathInsertWithFullPathCheck()
        {
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            string relativePathToFoo    = Path.Combine(testDirectory, "foo.txt");
            string fullPathToFoo        = Path.GetFullPath(relativePathToFoo);

            File.Create(relativePathToFoo).Dispose();

            archive.AddOrUpdateFile(relativePathToFoo);
            Assert.That(archive.ContainsFile(fullPathToFoo));
        }
        public void TestAddUpdateDelete() {
            bool receivedFileAdded = false, receivedFileUpdated = false, receivedFileDeleted = false;
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            archive.FileChanged += (sender, e) => {
                switch(e.EventType) {
                    case FileEventType.FileAdded:
                        receivedFileAdded = true;
                        break;
                    case FileEventType.FileChanged:
                        receivedFileUpdated = true;
                        break;
                    case FileEventType.FileDeleted:
                        receivedFileDeleted = true;
                        break;
                }
            };

            string fileFoo = Path.Combine(testDirectory, "foo.txt");
            File.Create(fileFoo).Dispose();
            archive.AddOrUpdateFile(fileFoo);
            Assert.That(receivedFileAdded);

            Assert.That(archive.ContainsFile(fileFoo));
            Assert.IsFalse(archive.IsOutdated(fileFoo));

            System.Threading.Thread.Sleep(5000);
            File.AppendAllText(fileFoo, "This is bar!\n"); 
            Assert.That(archive.IsOutdated(fileFoo));
            archive.AddOrUpdateFile(fileFoo);
            Assert.That(receivedFileUpdated);

            File.Delete(fileFoo);
            Assert.That(archive.IsOutdated(fileFoo));
            archive.DeleteFile(fileFoo);
            Assert.That(receivedFileDeleted);
            Assert.IsFalse(archive.ContainsFile(fileFoo));
        }
        public void TestArchiveLoadRoundTrip()
        {
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            var    archivePath          = archive.ArchivePath;
            string pathToFoo            = Path.GetFullPath(Path.Combine(testDirectory, "foo.txt"));

            File.Create(pathToFoo).Dispose();

            archive.AddOrUpdateFile(pathToFoo);

            archive.Dispose();

            Assert.That(File.Exists(archivePath));

            archive = new LastModifiedArchive(testDirectory);

            Assert.That(archive.ContainsFile(pathToFoo));
        }
        public void TestRename() {
            bool receivedFileAdd = false, receivedFileRename = false;
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            archive.FileChanged += (sender, e) => {
                switch(e.EventType) {
                    case FileEventType.FileAdded:
                        receivedFileAdd = true;
                        break;
                    case FileEventType.FileRenamed:
                        receivedFileRename = true;
                        break;
                }
            };
            string pathToFoo = Path.Combine(testDirectory, "foo.txt");
            string pathToBar = Path.Combine(testDirectory, "bar.txt");

            File.Create(pathToFoo).Dispose();

            archive.AddOrUpdateFile(pathToFoo);
            Assert.That(archive.ContainsFile(pathToFoo));
            Assert.That(receivedFileAdd);

            File.Move(pathToFoo, pathToBar);
            Assert.That(archive.IsOutdated(pathToFoo));
            archive.RenameFile(pathToFoo, pathToBar);
            Assert.That(receivedFileRename);
            Assert.That(archive.ContainsFile(pathToBar));
            Assert.IsFalse(archive.ContainsFile(pathToFoo));
        }
        public void TestArchiveLoadRoundTrip() {
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            var archivePath = archive.ArchivePath;
            string pathToFoo = Path.GetFullPath(Path.Combine(testDirectory, "foo.txt"));

            File.Create(pathToFoo).Dispose();

            archive.AddOrUpdateFile(pathToFoo);

            archive.Dispose();

            Assert.That(File.Exists(archivePath));

            archive = new LastModifiedArchive(testDirectory);

            Assert.That(archive.ContainsFile(pathToFoo));
        }
        public void TestRelativePathInsertWithFullPathCheck() {
            LastModifiedArchive archive = new LastModifiedArchive(testDirectory);
            string relativePathToFoo = Path.Combine(testDirectory, "foo.txt");
            string fullPathToFoo = Path.GetFullPath(relativePathToFoo);
            
            File.Create(relativePathToFoo).Dispose();

            archive.AddOrUpdateFile(relativePathToFoo);
            Assert.That(archive.ContainsFile(fullPathToFoo));
        }