public async Task FileSystemWatcher_RazorFileEvent_Background_NotifiesChange() { // Arrange var filePath = "C:/path/to/file.razor"; var changeKind = RazorFileChangeKind.Added; var listener = new Mock <IRazorFileChangeListener>(MockBehavior.Strict); listener.Setup(l => l.RazorFileChanged(filePath, changeKind)).Verifiable(); var fileChangeDetector = new RazorFileChangeDetector(Dispatcher, FilePathNormalizer, new[] { listener.Object }) { EnqueueDelay = 50, BlockNotificationWorkStart = new ManualResetEventSlim(initialState: false), }; // Act fileChangeDetector.FileSystemWatcher_RazorFileEvent_Background(filePath, changeKind); // Assert // We acquire the notification prior to unblocking notification work because once we allow that work to proceed the notification will be removed. var notification = Assert.Single(fileChangeDetector._pendingNotifications); fileChangeDetector.BlockNotificationWorkStart.Set(); await notification.Value.NotifyTask; listener.VerifyAll(); }
public void FileSystemWatcher_RazorFileEvent_Background_AddRemoveDoesNotNotify() { // Arrange var filePath = "C:/path/to/file.razor"; var listenerCalled = false; var listener = new Mock <IRazorFileChangeListener>(MockBehavior.Strict); listener.Setup(l => l.RazorFileChanged(filePath, It.IsAny <RazorFileChangeKind>())).Callback(() => listenerCalled = true); var fileChangeDetector = new RazorFileChangeDetector(Dispatcher, FilePathNormalizer, new[] { listener.Object }) { EnqueueDelay = 50, NotifyNotificationNoop = new ManualResetEventSlim(initialState: false), BlockNotificationWorkStart = new ManualResetEventSlim(initialState: false) }; // Act fileChangeDetector.FileSystemWatcher_RazorFileEvent_Background(filePath, RazorFileChangeKind.Added); fileChangeDetector.FileSystemWatcher_RazorFileEvent_Background(filePath, RazorFileChangeKind.Removed); // Assert fileChangeDetector.BlockNotificationWorkStart.Set(); Assert.True(fileChangeDetector.NotifyNotificationNoop.Wait(TimeSpan.FromSeconds(10))); Assert.False(listenerCalled); }