public int FilesChanged(uint cChanges, string[] rgpszFile, uint[] rggrfChange) { _foregroundDispatcher.AssertForegroundThread(); _importDocumentManager.OnFilesChanged(cChanges, rgpszFile, rggrfChange); return(VSConstants.S_OK); }
public void OnFilesChanged_WithSpecificFlags_InvokesChangedHandler_WithExpectedArguments(uint fileChangeFlag, int expectedKind) { // Arrange var filePath = "C:\\path\\to\\project\\file.cshtml"; var projectPath = "C:\\path\\to\\project\\project.csproj"; var tracker = Mock.Of <VisualStudioDocumentTracker>(t => t.FilePath == filePath && t.ProjectPath == projectPath); var templateEngineFactoryService = GetTemplateEngineFactoryService(); var anotherFilePath = "C:\\path\\to\\project\\anotherFile.cshtml"; var anotherTracker = Mock.Of <VisualStudioDocumentTracker>(t => t.FilePath == anotherFilePath && t.ProjectPath == projectPath); 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 manager = new DefaultImportDocumentManager(fileChangeService.Object, templateEngineFactoryService, Dispatcher, new DefaultErrorReporter()); manager.OnSubscribed(tracker); manager.OnSubscribed(anotherTracker); var called = false; manager.Changed += (sender, args) => { called = true; Assert.Same(sender, manager); Assert.Equal("C:\\path\\to\\project\\_ViewImports.cshtml", args.FilePath); Assert.Equal((ImportChangeKind)expectedKind, args.Kind); Assert.Collection( args.AssociatedDocuments, f => Assert.Equal(filePath, f), f => Assert.Equal(anotherFilePath, f)); }; // Act manager.OnFilesChanged(fileCount: 1, filePaths: new[] { "C:\\path\\to\\project\\_ViewImports.cshtml" }, fileChangeFlags: new[] { fileChangeFlag }); // Assert Assert.True(called); }