public async Task Dispose_UnsubscribtesFromTextChangedEvents()
        {
            var tempFile              = @"C:\Temp\ConsoleApp1.csproj";
            var docData               = IVsPersistDocDataFactory.ImplementAsIVsTextBuffer();
            var textBuffer            = ITextBufferFactory.Create();
            var shellUtilities        = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(tempFile, docData);
            var editorAdaptersService = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDoc               = ITextDocumentFactory.Create();
            var textDocFactoryService = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDoc, true);
            var editorModel           = IProjectFileEditorPresenterFactory.Create();

            var watcher = new TempFileBufferStateListener(editorModel, editorAdaptersService, textDocFactoryService, new IProjectThreadingServiceMock(), shellUtilities,
                                                          IServiceProviderFactory.Create());

            await watcher.InitializeListenerAsync(tempFile);

            Mock.Get(shellUtilities).Verify(u => u.GetRDTDocumentInfoAsync(It.IsAny <IServiceProvider>(), tempFile), Times.Once);
            Mock.Get(editorAdaptersService).Verify(e => e.GetDocumentBuffer((IVsTextBuffer)docData), Times.Once);
            Mock.Get(textDocFactoryService).Verify(t => t.TryGetTextDocument(textBuffer, out textDoc), Times.Once);

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null,
                                    new[] { null, new TextDocumentFileActionEventArgs(tempFile, DateTime.Now, FileActionTypes.ContentSavedToDisk) });
            Mock.Get(editorModel).Verify(e => e.SaveProjectFileAsync(), Times.Once);

            await watcher.DisposeAsync();

            Mock.Get(textDoc).Raise(t => t.FileActionOccurred += null,
                                    new[] { null, new TextDocumentFileActionEventArgs(tempFile, DateTime.Now, FileActionTypes.ContentSavedToDisk) });
            Mock.Get(editorModel).Verify(e => e.SaveProjectFileAsync(), Times.Once);
        }
Esempio n. 2
0
        private EditProjectFileCommand SetupScenario(string projectXml, string tempPath, string tempProjectFile, string projectFile, string caption,
                                                     IFileSystemMock fileSystem, ITextDocument textDoc, IVsWindowFrame frame)
        {
            fileSystem.SetTempFile(tempPath);
            var configuredProject   = ConfiguredProjectFactory.Create();
            var unconfiguredProject = IUnconfiguredProjectFactory.Create(filePath: projectFile, configuredProject: configuredProject);
            var shellUtilities      = new TestShellUtilitiesHelper((sp, path) =>
            {
                Assert.Equal(tempProjectFile, path);
                return(Tuple.Create(IVsHierarchyFactory.Create(), (uint)0, IVsPersistDocDataFactory.ImplementAsIVsTextBuffer(), (uint)0));
            }, (sp, path, factoryGuid, logicalView) =>
            {
                Assert.Equal(tempProjectFile, path);
                Assert.Equal(XmlGuid, factoryGuid);
                Assert.Equal(Guid.Empty, logicalView);

                return(frame);
            });

            var textBuffer           = ITextBufferFactory.ImplementSnapshot(projectXml);
            var editorFactoryService = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);

            Mock.Get(textDoc).SetupGet(t => t.TextBuffer).Returns(textBuffer);
            var textDocFactory = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDoc, true);

            var msbuildAccessor = IMsBuildAccessorFactory.Implement(projectXml, async(writeLock, callback) =>
            {
                await callback();
                Assert.True(writeLock);
            });

            var threadingService = IProjectThreadingServiceFactory.Create();

            return(CreateInstance(unconfiguredProject, true, msbuildAccessor, fileSystem, textDocFactory, editorFactoryService, threadingService, shellUtilities));
        }