public void FilesChanged_WithSpecificFlags_InvokesChangedHandler_WithExpectedArguments(uint fileChangeFlag, int expectedKind) { // Arrange var filePath = "C:\\path\\to\\project\\_ViewImports.cshtml"; 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 DefaultFileChangeTracker(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); }
public override FileChangeTracker Create(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(filePath)); } var fileChangeTracker = new DefaultFileChangeTracker(filePath, _foregroundDispatcher, _errorReporter, _fileChangeService); 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 DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object); // Act & Assert tracker.StopListening(); }
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 DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object); // Act tracker.StartListening(); // Assert fileChangeService.Verify(); }
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 DefaultFileChangeTracker("C:/_ViewImports.cshtml", Dispatcher, ErrorReporter, fileChangeService.Object); tracker.StartListening(); // Act tracker.StartListening(); // Assert Assert.Equal(1, callCount); }