예제 #1
0
        public async Task ProjectFileEditorPresenter_DisposeWithOpen_DisposesListeners()
        {
            var filePath                 = @"C:\Temp\ConsoleApp1.csproj";
            var textBufferManager        = ITextBufferManagerFactory.ImplementFilePath(filePath);
            var textBufferManagerFactory = ExportFactoryFactory.ImplementCreateValue(() => textBufferManager);

            var textBufferListener        = ITextBufferStateListenerFactory.Create();
            var textBufferListenerFactory = ExportFactoryFactory.ImplementCreateValue(() => textBufferListener);

            var frameListener        = IFrameOpenCloseListenerFactory.Create();
            var frameListenerFactory = ExportFactoryFactory.ImplementCreateValue(() => frameListener);

            var projectFileWatcher        = IProjectFileModelWatcherFactory.Create();
            var projectFileWatcherFactory = ExportFactoryFactory.ImplementCreateValue(() => projectFileWatcher);

            var windowFrame = IVsWindowFrameFactory.ImplementCloseFrame(options =>
            {
                Assert.Equal((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave, options);
                return(VSConstants.S_OK);
            });
            var shellUtilities = IVsShellUtilitiesHelperFactory.ImplementOpenDocument(filePath, XmlFactoryGuid, Guid.Empty, windowFrame);

            var editorState = new ProjectFileEditorPresenterTester(
                new IProjectThreadingServiceMock(),
                UnconfiguredProjectFactory.Create(),
                IServiceProviderFactory.Create(),
                shellUtilities,
                projectFileWatcherFactory,
                textBufferListenerFactory,
                frameListenerFactory,
                textBufferManagerFactory);

            // Mock dispose for one of the listeners so it can verify the editor is actually in EditorClosing
            Mock.Get(textBufferListener).Setup(t => t.Dispose()).Callback(() =>
                                                                          Assert.Equal(ProjectFileEditorPresenter.EditorState.EditorClosing, editorState.CurrentState));

            await editorState.OpenEditorAsync();

            await editorState.CloseCurrentEditorAsync();

            Mock.Get(textBufferManager).Verify(t => t.Dispose(), Times.Once);
            Mock.Get(textBufferListener).Verify(t => t.Dispose(), Times.Once);
            Mock.Get(frameListener).Verify(f => f.DisposeAsync(), Times.Once);
            Mock.Get(projectFileWatcher).Verify(p => p.Dispose(), Times.Once);
            Assert.Equal(ProjectFileEditorPresenter.EditorState.NoEditor, editorState.CurrentState);
        }
예제 #2
0
        public async Task DisposeWithoutOpen_DoesNothing()
        {
            var filePath                 = @"C:\Temp\ConsoleApp1.csproj";
            var textBufferManager        = ITextBufferManagerFactory.ImplementFilePath(filePath);
            var textBufferManagerFactory = ExportFactoryFactory.ImplementCreateValue(() => textBufferManager);

            var textBufferListener        = ITextBufferStateListenerFactory.Create();
            var textBufferListenerFactory = ExportFactoryFactory.ImplementCreateValue(() => textBufferListener);

            var frameListener        = IFrameOpenCloseListenerFactory.Create();
            var frameListenerFactory = ExportFactoryFactory.ImplementCreateValue(() => frameListener);

            var projectFileWatcher        = IProjectFileModelWatcherFactory.Create();
            var projectFileWatcherFactory = ExportFactoryFactory.ImplementCreateValue(() => projectFileWatcher);

            var windowFrame = IVsWindowFrameFactory.ImplementCloseFrame(options =>
            {
                Assert.Equal((uint)__FRAMECLOSE.FRAMECLOSE_PromptSave, options);
                return(VSConstants.S_OK);
            });
            var shellUtilities = IVsShellUtilitiesHelperFactory.ImplementOpenDocument(filePath, XmlFactoryGuid, Guid.Empty, windowFrame);

            var editorState = new ProjectFileEditorPresenterTester(
                new IProjectThreadingServiceMock(),
                UnconfiguredProjectFactory.Create(),
                IServiceProviderFactory.Create(),
                shellUtilities,
                projectFileWatcherFactory,
                textBufferListenerFactory,
                frameListenerFactory,
                textBufferManagerFactory);

            await editorState.CloseCurrentEditorAsync();

            Mock.Get(textBufferManager).Verify(t => t.Dispose(), Times.Never);
            Mock.Get(textBufferListener).Verify(t => t.Dispose(), Times.Never);
            Mock.Get(frameListener).Verify(f => f.DisposeAsync(), Times.Never);
            Mock.Get(projectFileWatcher).Verify(p => p.Dispose(), Times.Never);
        }