public void RegisterTest() { bool? bChanged = false; string fileName = Path.Combine(Directory.GetCurrentDirectory(), "test1.txt"); string fileName0 = Path.Combine(Directory.GetCurrentDirectory(), "test2.txt"); using (var watcher = new SingleFileWatcher(fileName)) { Assert.AreEqual(false, bChanged); Action notify = () => bChanged = true; File.WriteAllText(fileName, "کپها رو میگیره"); watcher.Register(notify); File.WriteAllText(fileName, "کپها رو میگیرن"); Thread.Sleep(10); Assert.AreEqual(true, bChanged); bChanged = false; File.WriteAllText(fileName0, "do not get notified"); Thread.Sleep(10); Assert.AreEqual(false, bChanged); } File.Delete(fileName); File.Delete(fileName0); }
public void MultiRegisterUnregister() { bool? bChange1 = false; bool? bChange2 = false; string fileName = Path.Combine(Directory.GetCurrentDirectory(), "test3.txt"); string fileName0 = Path.Combine(Directory.GetCurrentDirectory(), "test4.txt"); using (var watcher = new SingleFileWatcher(fileName)) { Assert.AreEqual(false, bChange1); Assert.AreEqual(false, bChange2); Action notify1 = () => bChange1 = true; Action notify2 = () => bChange2 = true; File.WriteAllText(fileName, "کپها رو میگیره"); watcher.Register(notify1); watcher.Register(notify2); File.WriteAllText(fileName, "کپها رو میگیرن"); Thread.Sleep(10); Assert.AreEqual(true, bChange1); Assert.AreEqual(true, bChange2); bChange1 = false; bChange2 = false; watcher.Unregister(notify1); File.WriteAllText(fileName, ":)))"); Thread.Sleep(10); Assert.AreEqual(false, bChange1); Assert.AreEqual(true, bChange2); } File.Delete(fileName); File.Delete(fileName0); }