public async Task TokensFiredForOldAndNewNamesOnRename() { using (var root = new DisposableFileSystem()) { using (var fileSystemWatcher = new MockFileSystemWatcher(root.RootPath)) { using (var physicalFilesWatcher = new PhysicalFilesWatcher(root.RootPath + Path.DirectorySeparatorChar, fileSystemWatcher, pollForChanges: false)) { using (var provider = new PhysicalFileProvider(root.RootPath, physicalFilesWatcher)) { var oldFileName = Guid.NewGuid().ToString(); var oldToken = provider.Watch(oldFileName); var newFileName = Guid.NewGuid().ToString(); var newToken = provider.Watch(newFileName); fileSystemWatcher.CallOnRenamed(new RenamedEventArgs(WatcherChangeTypes.Renamed, root.RootPath, newFileName, oldFileName)); await Task.Delay(WaitTimeForTokenToFire); Assert.True(oldToken.HasChanged); Assert.True(newToken.HasChanged); } } } } }
public async Task TokenFiredForFilesUnderPathEndingWithSlash() { using (var root = new DisposableFileSystem()) { using (var fileSystemWatcher = new MockFileSystemWatcher(root.RootPath)) { using (var physicalFilesWatcher = new PhysicalFilesWatcher(root.RootPath + Path.DirectorySeparatorChar, fileSystemWatcher, pollForChanges: false)) { using (var provider = new PhysicalFileProvider(root.RootPath, physicalFilesWatcher)) { var directoryName = Guid.NewGuid().ToString(); root.CreateFolder(directoryName) .CreateFile(Path.Combine(directoryName, "some-file")); var newDirectory = Path.GetRandomFileName(); var token = provider.Watch(directoryName + Path.DirectorySeparatorChar); Directory.Move( Path.Combine(root.RootPath, directoryName), Path.Combine(root.RootPath, newDirectory)); fileSystemWatcher.CallOnRenamed(new RenamedEventArgs( WatcherChangeTypes.Renamed, root.RootPath, newDirectory, directoryName)); await Task.Delay(WaitTimeForTokenToFire); Assert.True(token.HasChanged); } } } } }