public void ShouldWatchRenamedFile() { // Arrange FileWatcherEventArgs args = null; const string fileName = "FileWatcherRename.test"; const string fileName2 = "FileWatcherRename2.test"; FileWatcher fileWatcher = new FileWatcher(new FileInfo(fileName)); fileWatcher.OnChange += (s, a) => args = a; using (StreamWriter writer = File.CreateText(fileName)) { writer.WriteLine(); writer.Flush(); } // Act fileWatcher.Start(); File.Move(fileName, fileName2); Thread.Sleep(1200); FileWatcherEventArgs previousArgs = args; fileWatcher.ChangeFileToWatch(new FileInfo(fileName2)); fileWatcher.Start(); File.Delete(fileName2); Thread.Sleep(1200); fileWatcher.Dispose(); // Assert Assert.IsNotNull(previousArgs); Assert.IsTrue(previousArgs.IsFileNameChanged); Assert.IsNotNull(previousArgs.NewFilePath); Assert.AreEqual(fileName2, new FileInfo(previousArgs.NewFilePath).Name); Assert.IsNotNull(args); Assert.IsTrue(args.IsFileDeleted); }