public static void FileSystemWatcher_Renamed_Negative() { using (var dir = Utility.CreateTestDirectory()) using (var watcher = new FileSystemWatcher()) { // put everything in our own directory to avoid collisions watcher.Path = Path.GetFullPath(dir.Path); watcher.Filter = "*.*"; AutoResetEvent eventOccured = Utility.WatchForEvents(watcher, WatcherChangeTypes.Renamed); watcher.EnableRaisingEvents = true; // run all scenarios together to avoid unnecessary waits, // assert information is verbose enough to trace to failure cause // create a file using (var testFile = new TemporaryTestFile(Path.Combine(dir.Path, "file"))) using (var testDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir"))) { // change a file testFile.WriteByte(0xFF); testFile.Flush(); // deleting a file & directory by leaving the using block } Utility.ExpectNoEvent(eventOccured, "created"); } }
public static void FileSystemWatcher_Created_Negative() { using (var dir = Utility.CreateTestDirectory()) using (var watcher = new FileSystemWatcher()) { // put everything in our own directory to avoid collisions watcher.Path = Path.GetFullPath(dir.Path); watcher.Filter = "*.*"; AutoResetEvent eventOccurred = Utility.WatchForEvents(watcher, WatcherChangeTypes.Created); // run all scenarios together to avoid unnecessary waits, // assert information is verbose enough to trace to failure cause using (var testFile = new TemporaryTestFile(Path.Combine(dir.Path, "file"))) using (var testDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir"))) { // start listening after we've created these watcher.EnableRaisingEvents = true; // change a file testFile.WriteByte(0xFF); testFile.Flush(); // renaming a directory // // We don't do this on Linux because depending on the timing of MOVED_FROM and MOVED_TO events, // a rename can trigger delete + create as a deliberate handling of an edge case, and this // test is checking that no create events are raised. if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { testDir.Move(testDir.Path + "_rename"); } // deleting a file & directory by leaving the using block } Utility.ExpectNoEvent(eventOccurred, "created"); } }
public static void FileSystemWatcher_Deleted_Negative() { using (var dir = Utility.CreateTestDirectory()) using (var watcher = new FileSystemWatcher()) { // put everything in our own directory to avoid collisions watcher.Path = Path.GetFullPath(dir.Path); watcher.Filter = "*.*"; AutoResetEvent eventOccured = Utility.WatchForEvents(watcher, WatcherChangeTypes.Deleted); // run all scenarios together to avoid unnecessary waits, // assert information is verbose enough to trace to failure cause watcher.EnableRaisingEvents = true; // create a file using (var testFile = new TemporaryTestFile(Path.Combine(dir.Path, "file"))) using (var testDir = new TemporaryTestDirectory(Path.Combine(dir.Path, "dir"))) { // change a file testFile.WriteByte(0xFF); testFile.Flush(); // renaming a directory // // We don't do this on Linux because depending on the timing of MOVED_FROM and MOVED_TO events, // a rename can trigger delete + create as a deliberate handling of an edge case, and this // test is checking that no delete events are raised. if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { testDir.Move(testDir.Path + "_rename"); } Utility.ExpectNoEvent(eventOccured, "deleted"); } } }