コード例 #1
0
        public void OnUnsubscribed_StopsTrackingImport()
        {
            // 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();

            uint cookie            = 100;
            var  fileChangeService = new Mock <IVsFileChangeEx>(MockBehavior.Strict);

            fileChangeService
            .Setup(f => f.AdviseFileChange("C:\\path\\to\\project\\_ViewImports.cshtml", 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 manager = new DefaultImportDocumentManager(fileChangeService.Object, templateEngineFactoryService, Dispatcher, new DefaultErrorReporter());

            manager.OnSubscribed(tracker); // Start tracking the import.

            // Act
            manager.OnUnsubscribed(tracker);

            // Assert
            fileChangeService.Verify();
        }
コード例 #2
0
        public void OnUnsubscribed_AnotherDocumentTrackingImport_DoesNotStopTrackingImport()
        {
            // 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();

            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);
            fileChangeService
            .Setup(f => f.UnadviseFileChange(It.IsAny <uint>()))
            .Returns(VSConstants.S_OK)
            .Callback(() => throw new InvalidOperationException());

            var manager = new DefaultImportDocumentManager(fileChangeService.Object, templateEngineFactoryService, Dispatcher, new DefaultErrorReporter());

            manager.OnSubscribed(tracker); // Starts tracking import for the first document.

            var anotherFilePath = "C:\\path\\to\\project\\anotherFile.cshtml";
            var anotherTracker  = Mock.Of <VisualStudioDocumentTracker>(t => t.FilePath == anotherFilePath && t.ProjectPath == projectPath);

            manager.OnSubscribed(anotherTracker); // Starts tracking import for the second document.

            // Act & Assert (Does not throw)
            manager.OnUnsubscribed(tracker);
        }