public void FilesChanged_WithSpecificFlags_InvokesChangedHandler_WithExpectedArguments(uint fileChangeFlag, int expectedKind)
        {
            // Arrange
            var  filePath = TestProjectData.SomeProjectImportFile.FilePath;
            uint cookie;
            var  fileChangeService = new Mock <IVsFileChangeEx>();

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

            var called = false;

            tracker.Changed += (sender, args) =>
            {
                called = true;
                Assert.Same(sender, tracker);
                Assert.Equal(filePath, args.FilePath);
                Assert.Equal((FileChangeKind)expectedKind, args.Kind);
            };

            // Act
            tracker.FilesChanged(fileCount: 1, filePaths: new[] { filePath }, fileChangeFlags: new[] { fileChangeFlag });

            // Assert
            Assert.True(called);
        }
예제 #2
0
        public override FileChangeTracker Create(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath));
            }

            var fileChangeTracker = new VisualStudioFileChangeTracker(filePath, _foregroundDispatcher, _errorReporter, _fileChangeService, _joinableTaskContext.Factory);

            return(fileChangeTracker);
        }
        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();
        }
예제 #4
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);
        }
예제 #5
0
        public async Task StartListening_AdvisesForFileChange()
        {
            // 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();
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, ErrorReporter, fileChangeService.Object, Dispatcher, JoinableTaskFactory.Context);

            // Act
            tracker.StartListening();
            await tracker._fileChangeAdviseTask;

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

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

            // Act
            tracker.StartListening();

            // Assert
            fileChangeService.Verify();
        }
예제 #7
0
        public async Task StartListening_AlreadyListening_DoesNothing()
        {
            // Arrange
            var callCount         = 0;
            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))
            .Callback(() => callCount++);
            var tracker = new VisualStudioFileChangeTracker(TestProjectData.SomeProjectImportFile.FilePath, Dispatcher, ErrorReporter, fileChangeService.Object, JoinableTaskFactory);

            tracker.StartListening();

            // Act
            tracker.StartListening();
            await tracker._fileChangeAdviseTask;

            // Assert
            Assert.Equal(1, callCount);
        }
        public void StartListening_AlreadyListening_DoesNothing()
        {
            // Arrange
            uint cookie            = 100;
            var  callCount         = 0;
            var  fileChangeService = new Mock <IVsFileChangeEx>();

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

            tracker.StartListening();

            // Act
            tracker.StartListening();

            // Assert
            Assert.Equal(1, callCount);
        }
예제 #9
0
        public async Task FilesChanged_WithSpecificFlags_InvokesChangedHandler_WithExpectedArguments(uint fileChangeFlag, int expectedKind)
        {
            // Arrange
            var filePath          = TestProjectData.SomeProjectImportFile.FilePath;
            var fileChangeService = Mock.Of <IVsAsyncFileChangeEx>(MockBehavior.Strict);
            var tracker           = new VisualStudioFileChangeTracker(filePath, ErrorReporter, fileChangeService, Dispatcher, JoinableTaskFactory.Context);

            var called = false;

            tracker.Changed += (sender, args) =>
            {
                called = true;
                Assert.Same(sender, tracker);
                Assert.Equal(filePath, args.FilePath);
                Assert.Equal((FileChangeKind)expectedKind, args.Kind);
            };

            // Act
            tracker.FilesChanged(fileCount: 1, filePaths: new[] { filePath }, fileChangeFlags: new[] { fileChangeFlag });
            await tracker._fileChangedTask;

            // Assert
            Assert.True(called);
        }
        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("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object);

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

            // Act
            tracker.StopListening();

            // Assert
            fileChangeService.Verify();
        }