public void WatcherComponent_CreatedEvent() { String path = String.Empty; EventHandler <FileSystemEventArgs> myEvent = (_, fseArgs) => { path = fseArgs.FullPath; }; // Assign event mock.Created += myEvent; var args = new FileSystemEventArgs(WatcherChangeTypes.Created, "SomeRootDir", "SomePath"); Assert.That(path, Is.EqualTo(String.Empty)); // Call event on mock object mock.OnCreated(args); Assert.That(path, Is.EqualTo(@"SomeRootDir\SomePath")); // Reset path path = String.Empty; Assert.That(path, Is.EqualTo(String.Empty)); // Remove the event mock.Created -= myEvent; mock.OnCreated(args); Assert.That(path, Is.EqualTo(String.Empty)); }
public async Task WatcherObservable_GetObservable_CreateEvent() { String monitorPath = ""; // Set monitorPath to the path that is updated when it is changed var asyncObs = watcherObservable.GetObservable() .Select(eventPath => monitorPath = eventPath) .FirstAsync().ToTask(); //Invoke Created Event on Mock String newRoot = "SomeRoot"; String newPath = "SomePath"; String newFullPath = String.Format("{0}\\{1}", newRoot, newPath); var args = new FileSystemEventArgs(WatcherChangeTypes.Created, newRoot, newPath); mock.OnCreated(args); var obs = await asyncObs; Assert.That(monitorPath, Is.EqualTo(newFullPath)); }