public async Task ProjectFileEditorPresenter_SaveProjectFile_OnlySavesInEditorOpen(int state) { 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.Create(); var shellUtilities = IVsShellUtilitiesHelperFactory.ImplementOpenDocument(filePath, XmlFactoryGuid, Guid.Empty, windowFrame); var threadingService = IProjectThreadingServiceFactory.Create(); var editorState = new ProjectFileEditorPresenterTester( threadingService, UnconfiguredProjectFactory.Create(), IServiceProviderFactory.Create(), shellUtilities, projectFileWatcherFactory, textBufferListenerFactory, frameListenerFactory, textBufferManagerFactory) { CurrentState = (ProjectFileEditorPresenter.EditorState)state }; // When SaveAsync is called, we should hit an assert in the NoEditor case. bool assertHit = false; try { await editorState.SaveProjectFileAsync(); } catch (InvalidOperationException) { assertHit = true; } Assert.True(state != (int)ProjectFileEditorPresenter.EditorState.NoEditor || assertHit); var textBufferMock = Mock.Get(textBufferManager); textBufferMock.Verify(t => t.SetReadOnlyAsync(It.IsAny <bool>()), Times.Never); textBufferMock.Verify(t => t.SaveAsync(), Times.Never); }
public async Task ProjectFileEditorPresenter_UpdateProjectFile_SchedulesUpdate() { 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.Create(); var shellUtilities = IVsShellUtilitiesHelperFactory.ImplementOpenDocument(filePath, XmlFactoryGuid, Guid.Empty, windowFrame); var threadingService = IProjectThreadingServiceFactory.Create(); var editorState = new ProjectFileEditorPresenterTester( threadingService, UnconfiguredProjectFactory.Create(), IServiceProviderFactory.Create(), shellUtilities, projectFileWatcherFactory, textBufferListenerFactory, frameListenerFactory, textBufferManagerFactory); // Implement ResetBuffer so we can verify that the editor is in BufferUpdateScheduled when calling ResetBuffer. While here, // verify that the buffer was set to readonly before reset was called var textBufferMock = Mock.Get(textBufferManager); textBufferMock.Setup(t => t.ResetBufferAsync()).Callback(() => { Assert.Equal(ProjectFileEditorPresenter.EditorState.BufferUpdateScheduled, editorState.CurrentState); textBufferMock.Verify(t => t.SetReadOnlyAsync(true), Times.Once); }).Returns(Task.CompletedTask); await editorState.OpenEditorAsync(); var jt = editorState.ScheduleProjectFileUpdate(); // Ensure the update actually runs await jt.JoinAsync(); textBufferMock.Verify(t => t.SetReadOnlyAsync(true), Times.Once); textBufferMock.Verify(t => t.ResetBufferAsync(), Times.Once); textBufferMock.Verify(t => t.SetReadOnlyAsync(false), Times.Once); }
public async Task ProjectFileEditorPresenter_SaveProjectFile_SavesFile() { 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.Create(); var shellUtilities = IVsShellUtilitiesHelperFactory.ImplementOpenDocument(filePath, XmlFactoryGuid, Guid.Empty, windowFrame); var threadingService = IProjectThreadingServiceFactory.Create(); var editorState = new ProjectFileEditorPresenterTester( threadingService, UnconfiguredProjectFactory.Create(), IServiceProviderFactory.Create(), shellUtilities, projectFileWatcherFactory, textBufferListenerFactory, frameListenerFactory, textBufferManagerFactory); var textBufferMock = Mock.Get(textBufferManager); // Implement textBufferManager.SaveAsync to verify the editor is in WritingProjectFile while saving textBufferMock.Setup(t => t.SaveAsync()).Callback(() => { Assert.Equal(ProjectFileEditorPresenter.EditorState.WritingProjectFile, editorState.CurrentState); textBufferMock.Verify(t => t.SetReadOnlyAsync(true), Times.Once); }).Returns(Task.CompletedTask); await editorState.OpenEditorAsync(); await editorState.SaveProjectFileAsync(); textBufferMock.Verify(t => t.SetReadOnlyAsync(true), Times.Once); textBufferMock.Verify(t => t.SaveAsync(), Times.Once); textBufferMock.Verify(t => t.SetReadOnlyAsync(false), Times.Once); }
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); }
public async Task ProjectFileEditorPresenter_MultipleOpen_CallsShowSecondTime() { 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.Create(); 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.OpenEditorAsync(); Mock.Get(windowFrame).Verify(w => w.Show(), Times.Never); // On the second call, we should call show on the frame, and none of the listeners should have been set up again await editorState.OpenEditorAsync(); Mock.Get(windowFrame).Verify(w => w.Show(), Times.Once); Mock.Get(textBufferManager).Verify(t => t.InitializeBufferAsync(), Times.Once); Mock.Get(textBufferListener).Verify(t => t.InitializeListenerAsync(filePath), Times.Once); Mock.Get(frameListener).Verify(f => f.InitializeEventsAsync(windowFrame), Times.Once); Mock.Get(projectFileWatcher).Verify(p => p.InitializeModelWatcher(), Times.Once); Assert.Equal(editorState.CurrentState, ProjectFileEditorPresenter.EditorState.EditorOpen); }
public async Task ProjectFileEditorPresenter_OpenEditor_SetsUpListeners() { 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.Create(); 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 textBufferManager.InitializeBufferAsync so it can verify the editor is actually in Initializing Mock.Get(textBufferManager).Setup(t => t.InitializeBufferAsync()).Callback(() => Assert.Equal(ProjectFileEditorPresenter.EditorState.Initializing, editorState.CurrentState)).Returns(Task.CompletedTask); await editorState.OpenEditorAsync(); Mock.Get(textBufferManager).Verify(t => t.InitializeBufferAsync(), Times.Once); Mock.Get(textBufferListener).Verify(t => t.InitializeListenerAsync(filePath), Times.Once); Mock.Get(frameListener).Verify(f => f.InitializeEventsAsync(windowFrame), Times.Once); Mock.Get(projectFileWatcher).Verify(p => p.InitializeModelWatcher(), Times.Once); Assert.Equal(editorState.CurrentState, ProjectFileEditorPresenter.EditorState.EditorOpen); }
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); }
public async Task ProjectFileEditorPresenter_CloseWindowFail_ReturnsStopClose() { 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.E_FAIL); }); 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.OpenEditorAsync(); Assert.False(await editorState.CanCloseWindowAsync()); }