public void StopListening_NotListening_DoesNothing()
        {
            // Arrange
            uint cookie            = VSConstants.VSCOOKIE_NIL;
            var  fileChangeService = new Mock <IVsFileChangeEx>(MockBehavior.Strict);

            fileChangeService
            .Setup(f => f.UnadviseFileChange(cookie))
            .Throws(new InvalidOperationException());
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, Dispatcher, ErrorReporter, fileChangeService.Object);

            // Act & Assert
            tracker.StopListening();
        }
Beispiel #2
0
        public void StopListening_NotListening_DoesNothing()
        {
            // Arrange
            var fileChangeService = new Mock <IVsAsyncFileChangeEx>(MockBehavior.Strict);

            fileChangeService
            .Setup(f => f.UnadviseFileChangeAsync(123, It.IsAny <CancellationToken>()))
            .Throws(new InvalidOperationException());
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, ErrorReporter, fileChangeService.Object, Dispatcher, JoinableTaskFactory.Context);

            // Act
            tracker.StopListening();

            // Assert
            Assert.Null(tracker._fileChangeUnadviseTask);
        }
Beispiel #3
0
        public async Task StopListening_UnadvisesForFileChange()
        {
            // Arrange
            var fileChangeService = new Mock <IVsAsyncFileChangeEx>(MockBehavior.Strict);

            fileChangeService
            .Setup(f => f.AdviseFileChangeAsync(It.IsAny <string>(), It.IsAny <_VSFILECHANGEFLAGS>(), It.IsAny <IVsFreeThreadedFileChangeEvents2>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <uint>(123))
            .Verifiable();
            fileChangeService
            .Setup(f => f.UnadviseFileChangeAsync(123, It.IsAny <CancellationToken>()))
            .Verifiable();
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, ErrorReporter, fileChangeService.Object, Dispatcher, JoinableTaskFactory.Context);

            tracker.StartListening(); // Start listening for changes.
            await tracker._fileChangeAdviseTask;

            // Act
            tracker.StopListening();
            await tracker._fileChangeUnadviseTask;

            // Assert
            fileChangeService.Verify();
        }
        public void StopListening_UnadvisesForFileChange()
        {
            // Arrange
            uint cookie            = 100;
            var  fileChangeService = new Mock <IVsFileChangeEx>(MockBehavior.Strict);

            fileChangeService
            .Setup(f => f.AdviseFileChange(It.IsAny <string>(), It.IsAny <uint>(), It.IsAny <IVsFileChangeEvents>(), out cookie))
            .Returns(VSConstants.S_OK)
            .Verifiable();
            fileChangeService
            .Setup(f => f.UnadviseFileChange(cookie))
            .Returns(VSConstants.S_OK)
            .Verifiable();
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, Dispatcher, ErrorReporter, fileChangeService.Object);

            tracker.StartListening(); // Start listening for changes.

            // Act
            tracker.StopListening();

            // Assert
            fileChangeService.Verify();
        }