public void RoundTripVersionReset_NoChanges_Test()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName();
        string fullName   = Path.Combine(currentDir, fileName);

        using (var file = File.Create(fullName)) { }

        FileSystemState state = new FileSystemState(currentDir);

        state.LoadState();
        state.GetChanges();

        FileSystemState state2 = new FileSystemState(currentDir);

        RoundTrip(state, state2);

        try
        {
            Assert.Empty(state.GetChanges());
            Assert.Empty(state2.GetChanges());
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
예제 #2
0
    public static void FileSystemWatcher_Deleted_File()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName();
        string fullName   = Path.Combine(currentDir, fileName);

        FileSystemState watcher = new FileSystemState(currentDir);

        using (FileStream file = File.Create(fullName)) { }
        watcher.LoadState();
        File.Delete(fullName);
        var changes = watcher.GetChanges();

        try
        {
            Assert.Single(changes);
            FileChange change = changes[0];
            Assert.Equal(WatcherChangeTypes.Deleted, change.ChangeType);
            Assert.Equal(fileName, change.Name);
            Assert.Equal(currentDir, change.Directory);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
예제 #3
0
    public static void FileSystemWatcher_Recursive()
    {
        string currentDir   = Utility.GetRandomDirectory();
        string fileName     = Path.GetRandomFileName();
        string subDirectory = new DirectoryInfo(currentDir).CreateSubdirectory("sub").FullName;
        string fullName     = Path.Combine(subDirectory, fileName);

        FileSystemState watcher = new FileSystemState(currentDir, options: new EnumerationOptions {
            RecurseSubdirectories = true
        });

        watcher.LoadState();
        using (FileStream file = File.Create(fullName)) { }
        var changes = watcher.GetChanges();

        try
        {
            Assert.Single(changes);
            FileChange change = changes[0];
            Assert.Equal(WatcherChangeTypes.Created, change.ChangeType);
            Assert.Equal(fileName, change.Name);
            Assert.Equal(subDirectory, change.Directory);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
예제 #4
0
    public static void FileSystemWatcher_Filter_Ignore()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = $"{Path.GetRandomFileName()}.txt";
        string fullName   = Path.Combine(currentDir, fileName);

        FileSystemState watcher = new FileSystemState(currentDir, filter: "*.csv");

        watcher.LoadState();
        using (FileStream file = File.Create(fullName)) { }
        var changes = watcher.GetChanges();

        try
        {
            Assert.Empty(changes);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
예제 #5
0
        public void FileSystemWatcherNoChange()
        {
            var dir = GetRandomDirectory();

            try
            {
                File.WriteAllText(Path.Combine(dir, "text1.txt"), "Hello");
                File.WriteAllText(Path.Combine(dir, "blah.txt"), "Hello");

                var watcher = new FileSystemState(dir, options: new EnumerationOptions {
                    RecurseSubdirectories = true
                });
                watcher.LoadState();

                var q = watcher.GetChanges();
                q.Count.ShouldBe(0);
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }
예제 #6
0
    public static void FileSystemWatcher_Renamed_Directory()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName();
        string subDir     = Path.Combine(currentDir, "subdir");
        string fullName   = Path.Combine(currentDir, fileName);
        string newName    = Path.Combine(subDir, fileName);

        FileSystemState watcher = new FileSystemState(currentDir, options: new EnumerationOptions()
        {
            RecurseSubdirectories = true
        });

        Directory.CreateDirectory(subDir);

        using (FileStream file = File.Create(fullName)) { }
        watcher.LoadState();

        File.Move(fullName, Path.Combine(currentDir, newName));

        var changes = watcher.GetChanges();

        try
        {
            Assert.Single(changes);
            FileChange change = changes[0];
            Assert.Equal(WatcherChangeTypes.Renamed, change.ChangeType);
            Assert.Equal(fileName, change.OldName);
            Assert.Equal(currentDir, change.OldDirectory);
            Assert.Equal(fileName, change.Name);
            Assert.Equal(subDir, change.Directory);
        }
        finally
        {
            Directory.Delete(subDir, true);
            Directory.Delete(currentDir, true);
        }
    }
예제 #7
0
    public static void FileSystemWatcher_NotRecursive()
    {
        string currentDir   = Utility.GetRandomDirectory();
        string fileName     = Path.GetRandomFileName();
        string subDirectory = new DirectoryInfo(currentDir).CreateSubdirectory("sub").FullName;
        string fullName     = Path.Combine(subDirectory, fileName);

        FileSystemState watcher = new FileSystemState(currentDir, options: new EnumerationOptions {
            RecurseSubdirectories = false
        });

        watcher.LoadState();
        using (FileStream file = File.Create(fullName)) { }
        var changes = watcher.GetChanges();

        try
        {
            Assert.Empty(changes);
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }
    public void RoundTripDoesNotAffectOriginalTest()
    {
        string currentDir = Utility.GetRandomDirectory();
        string fileName   = Path.GetRandomFileName() + ".txt";
        string fullName   = Path.Combine(currentDir, fileName);

        FileSystemState state  = new FileSystemState(currentDir, "*.csv");
        FileSystemState state2 = new FileSystemState(currentDir, "*.txt");

        state.LoadState();
        RoundTrip(state, state2);

        using (var file = File.Create(fullName)) { }

        try
        {
            Assert.Empty(state.GetChanges());
            Assert.Single(state2.GetChanges());
        }
        finally
        {
            Directory.Delete(currentDir, true);
        }
    }