コード例 #1
0
        public void CreateNewFileTest()
        {
            IFileSystemWatch fileSystemWatch = new FileSystemWatch(testFolder, "*.txt", NotifyFilters.LastAccess
                                                                   | NotifyFilters.LastWrite
                                                                   | NotifyFilters.FileName
                                                                   | NotifyFilters.DirectoryName, true);

            using var monitoredSubject = fileSystemWatch.Monitor();
            var fileName = Guid.NewGuid().ToString() + ".txt";

            fileSystemWatch.Start();
            Thread.Sleep(1000);
            File.WriteAllText(CombineFileName(fileName), Guid.NewGuid().ToString());
            Thread.Sleep(1000);

            monitoredSubject.Should()
            .Raise("Created")
            .WithArgs <FileSystemEventArgs>(args => args.ChangeType == WatcherChangeTypes.Created);
        }
コード例 #2
0
        public void FileDeleteTest()
        {
            const string fileName = "testfiled.txt";
            var          fullDir  = CombineFileName(fileName);

            File.WriteAllText(fullDir, Guid.NewGuid().ToString());
            IFileSystemWatch fileSystemWatch = new FileSystemWatch(testFolder, "*.txt", NotifyFilters.LastAccess
                                                                   | NotifyFilters.LastWrite
                                                                   | NotifyFilters.FileName
                                                                   | NotifyFilters.DirectoryName, true);

            using var monitoredSubject = fileSystemWatch.Monitor();
            fileSystemWatch.Start();
            Thread.Sleep(1000);
            File.Delete(fullDir);
            Thread.Sleep(1000);

            monitoredSubject.Should()
            .Raise("Deleted")
            .WithArgs <FileSystemEventArgs>(args => args.ChangeType == WatcherChangeTypes.Deleted);
        }