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 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 TestIsEmpty()
        {
            var archive = new LastModifiedArchive(testDirectory, "archive.txt");

            Assert.That(archive.IsEmpty);

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

            File.Create(pathToFoo).Dispose();
            archive.AddOrUpdateFile(pathToFoo);
            Assert.That(archive.IsEmpty, Is.False);
        }
        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 TestIsEmpty() {
     var archive = new LastModifiedArchive(testDirectory, "archive.txt");
     Assert.That(archive.IsEmpty);
     
     string pathToFoo = Path.GetFullPath(Path.Combine(testDirectory, "foo.txt"));
     File.Create(pathToFoo).Dispose();
     archive.AddOrUpdateFile(pathToFoo);
     Assert.That(archive.IsEmpty, Is.False);
 }
        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));
        }