Beispiel #1
0
        private MigrateXprojProjectFactory CreateInstance(ProcessRunner processRunner, IFileSystem fileSystem, IVsSolution solutionParam = null)
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var solution        = solutionParam ?? IVsSolutionFactory.CreateWithSolutionDirectory(CreateSolutionInfo());
            var serviceProvider = IServiceProviderFactory.Create(typeof(SVsSolution), solution);

            var migrator = new MigrateXprojProjectFactory(processRunner, fileSystem, serviceProvider);

            return(migrator);
        }
 public void TempFileBufferStateListener_NullShellUtilities_Throws()
 {
     Assert.Throws <ArgumentNullException>("shellUtilities", () => new TempFileBufferStateListener(
                                               IProjectFileEditorPresenterFactory.Create(),
                                               IVsEditorAdaptersFactoryServiceFactory.Create(),
                                               ITextDocumentFactoryServiceFactory.Create(),
                                               IProjectThreadingServiceFactory.Create(),
                                               null,
                                               IServiceProviderFactory.Create()));
 }
Beispiel #3
0
        public void GlobalJsonSetup_ExistingRemover_ReturnsSameRemover()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            var remover = new GlobalJsonRemover(IServiceProviderFactory.Create(), IFileSystemFactory.Create());

            GlobalJsonRemover.Remover = remover;
            Assert.False(new GlobalJsonRemover.GlobalJsonSetup().SetupRemoval(IVsSolutionFactory.Create(),
                                                                              IServiceProviderFactory.Create(), IFileSystemFactory.Create()));
            Assert.Same(remover, GlobalJsonRemover.Remover);
        }
        public void DTE_ReturnsServiceProviderGetService()
        {
            var dte             = DteFactory.Create();
            var serviceProvider = IServiceProviderFactory.Create(typeof(SDTE), dte);

            var dteServices = CreateInstance(serviceProvider);

            var result = dteServices.Dte;

            Assert.Same(dte, result);
        }
        public async Task NoChangesFrom_DoesNotOverwriteNewChanges()
        {
            var projectFilePath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            // Use some file encoding that's not the default
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: Encoding.UTF8);

            var projectXml = "<Project />";
            var bufferXml  = "<Project></Project>";


            var docData      = IVsPersistDocDataFactory.ImplementAsIVsTextBufferIsDocDataDirty(true, VSConstants.S_OK);
            var textBuffer   = ITextBufferFactory.ImplementSnapshot(() => bufferXml);
            var textDocument = ITextDocumentFactory.ImplementTextBuffer(textBuffer);

            var fileSystem      = new IFileSystemMock();
            var tempFilePath    = @"C:\Temp\asdf.1234";
            var tempProjectPath = Path.Combine(tempFilePath, "ConsoleApp1.csproj");

            fileSystem.SetTempFile(tempFilePath);

            var msbuildAccessor = IProjectXmlAccessorFactory.Implement(() => projectXml, xml => fileSystem.WriteAllText(tempProjectPath, xml));

            var shellUtility         = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(Path.Combine(tempFilePath, "ConsoleApp1.csproj"), docData);
            var editorAdapterFactory = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDocumentService  = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDocument, true);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  editorAdapterFactory,
                                                                  textDocumentService,
                                                                  shellUtility,
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            var tempFile = fileSystem.Files.First(data => StringComparers.Paths.Equals(tempProjectPath, data.Key));

            // First save. File system should be "<Project></Project>", last saved is also "<Project></Project>"
            await textBufferManager.SaveAsync();

            Assert.Equal("<Project></Project>", fileSystem.ReadAllText(tempProjectPath));

            // Now we simulate some changes to the buffer and call Reset. Both the last saved and current project xml should be "<Project></Project>", so
            // the buffer shouldn't be reset
            projectXml = bufferXml;
            bufferXml  = "<Project>asdf</Project>";
            await textBufferManager.ResetBufferAsync();

            Mock.Get(textBuffer).Verify(t => t.Replace(It.IsAny <Span>(), It.IsAny <string>()), Times.Never);
            Assert.Equal("<Project></Project>", fileSystem.ReadAllText(tempProjectPath));
        }
Beispiel #6
0
 public void ProjectFileEditorPresenter_NullTextBufferListenerFactory_Throws()
 {
     Assert.Throws <ArgumentNullException>("textBufferListenerFactory", () => new ProjectFileEditorPresenter(
                                               IProjectThreadingServiceFactory.Create(),
                                               UnconfiguredProjectFactory.Create(),
                                               IServiceProviderFactory.Create(),
                                               IVsShellUtilitiesHelperFactory.Create(),
                                               ExportFactoryFactory.CreateInstance <IProjectFileModelWatcher>(),
                                               null,
                                               ExportFactoryFactory.CreateInstance <IFrameOpenCloseListener>(),
                                               ExportFactoryFactory.CreateInstance <ITextBufferManager>()));
 }
        public void Solution_ReturnsServiceProviderGetService()
        {
            var solution        = SolutionFactory.Create();
            var dte             = DteFactory.ImplementSolution(() => solution);
            var serviceProvider = IServiceProviderFactory.Create(typeof(SDTE), dte);

            var dteServices = CreateInstance(serviceProvider);

            var result = dteServices.Solution;

            Assert.Same(solution, result);
        }
 public void NullFileSystem_Throws()
 {
     Assert.Throws <ArgumentNullException>("fileSystem", () => new TempFileTextBufferManager(
                                               UnconfiguredProjectFactory.Create(),
                                               IProjectXmlAccessorFactory.Create(),
                                               IVsEditorAdaptersFactoryServiceFactory.Create(),
                                               ITextDocumentFactoryServiceFactory.Create(),
                                               IVsShellUtilitiesHelperFactory.Create(),
                                               null,
                                               IProjectThreadingServiceFactory.Create(),
                                               IServiceProviderFactory.Create()));
 }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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 ResetBufferDirtyDocData_UpdatesFileNotBuffer()
        {
            var projectFilePath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            // Use some file encoding that's not the default
            var encoding            = Encoding.Default.Equals(Encoding.UTF8) ? Encoding.UTF32 : Encoding.UTF8;
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: encoding);

            var xml = "<Project />";

            var msbuildAccessor = IProjectXmlAccessorFactory.Implement(() => xml, s => { });

            var docData      = IVsPersistDocDataFactory.ImplementAsIVsTextBufferIsDocDataDirty(true, VSConstants.S_OK);
            var textBuffer   = ITextBufferFactory.ImplementSnapshot("<Project />");
            var textDocument = ITextDocumentFactory.ImplementTextBuffer(textBuffer);

            var fileSystem   = new IFileSystemMock();
            var tempFilePath = @"C:\Temp\asdf.1234";

            fileSystem.SetTempFile(tempFilePath);

            var shellUtility         = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(Path.Combine(tempFilePath, "ConsoleApp1.csproj"), docData);
            var editorAdapterFactory = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDocumentService  = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDocument, true);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  editorAdapterFactory,
                                                                  textDocumentService,
                                                                  shellUtility,
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            var tempProjectPath = Path.Combine(tempFilePath, "ConsoleApp1.csproj");
            var tempFile        = fileSystem.Files.First(data => StringComparers.Paths.Equals(tempProjectPath, data.Key));

            Assert.Equal("<Project />", fileSystem.ReadAllText(tempProjectPath));

            xml = "<Project></Project>";
            await textBufferManager.ResetBufferAsync();

            Mock.Get(textBuffer).Verify(t => t.Replace(It.IsAny <Span>(), It.IsAny <string>()), Times.Never);
            Assert.Equal("<Project></Project>", fileSystem.ReadAllText(tempProjectPath));
            Mock.Get(unconfiguredProject).Verify(u => u.SaveAsync(null), Times.Once);
        }
Beispiel #12
0
        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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        public void ProjectFileEditorPresenter_UpdateProjectFileIncorrectEditorState_DoesNothing(int state)
        {
            var editorState = new ProjectFileEditorPresenterTester(
                IProjectThreadingServiceFactory.Create(),
                UnconfiguredProjectFactory.Create(),
                IServiceProviderFactory.Create(),
                IVsShellUtilitiesHelperFactory.Create(),
                ExportFactoryFactory.CreateInstance <IProjectFileModelWatcher>(),
                ExportFactoryFactory.CreateInstance <ITextBufferStateListener>(),
                ExportFactoryFactory.CreateInstance <IFrameOpenCloseListener>(),
                ExportFactoryFactory.CreateInstance <ITextBufferManager>())
            {
                CurrentState = (ProjectFileEditorPresenter.EditorState)state
            };

            Assert.Null(editorState.ScheduleProjectFileUpdate());
        }
        public async Task SetReadonly_SetsOnlyReadonlyFlag()
        {
            var projectFilePath = @"C:\ConsoleApp\ConsoleApp1\ConsoleApp1.csproj";
            // Use some file encoding that's not the default
            var encoding            = Encoding.Default.Equals(Encoding.UTF8) ? Encoding.UTF32 : Encoding.UTF8;
            var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: projectFilePath, projectEncoding: encoding);

            var xml = "<Project />";

            var msbuildAccessor = IProjectXmlAccessorFactory.ImplementGetProjectXml(xml);

            var docData      = IVsPersistDocDataFactory.ImplementAsIVsTextBufferGetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
            var textBuffer   = ITextBufferFactory.ImplementSnapshot("<Project></Project>");
            var textDocument = ITextDocumentFactory.ImplementTextBuffer(textBuffer);

            var fileSystem   = new IFileSystemMock();
            var tempFilePath = @"C:\Temp\asdf.1234";

            fileSystem.SetTempFile(tempFilePath);

            var shellUtility         = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(Path.Combine(tempFilePath, "ConsoleApp1.csproj"), docData);
            var editorAdapterFactory = IVsEditorAdaptersFactoryServiceFactory.ImplementGetDocumentBuffer(textBuffer);
            var textDocumentService  = ITextDocumentFactoryServiceFactory.ImplementGetTextDocument(textDocument, true);

            var textBufferManager = new TempFileTextBufferManager(unconfiguredProject,
                                                                  msbuildAccessor,
                                                                  editorAdapterFactory,
                                                                  textDocumentService,
                                                                  shellUtility,
                                                                  fileSystem,
                                                                  new IProjectThreadingServiceMock(),
                                                                  IServiceProviderFactory.Create());

            await textBufferManager.InitializeBufferAsync();

            await textBufferManager.SetReadOnlyAsync(true);

            Mock.Get(docData).As <IVsTextBuffer>().Verify(t =>
                                                          t.SetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY | (uint)BUFFERSTATEFLAGS.BSF_USER_READONLY));
            await textBufferManager.SetReadOnlyAsync(false);

            Mock.Get(docData).As <IVsTextBuffer>().Verify(t => t.SetStateFlags(~(uint)BUFFERSTATEFLAGS.BSF_USER_READONLY));
        }
Beispiel #16
0
        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);
        }
Beispiel #17
0
        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);
        }
Beispiel #18
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);
        }
        public async Task NonFileSavedToDisk_DoesNotSaveProjectFile(FileActionTypes action)
        {
            var tempFile              = @"C:\Temp\ConsoleApp1.csproj";
            var docData               = IVsPersistDocDataFactory.ImplementAsIVsTextBuffer();
            var shellUtilities        = IVsShellUtilitiesHelperFactory.ImplementGetRDTInfo(tempFile, docData);
            var textBuffer            = ITextBufferFactory.Create();
            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, action) });
            Mock.Get(editorModel).Verify(e => e.SaveProjectFileAsync(), Times.Never);
        }
Beispiel #20
0
        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());
        }
        private void ProcessMessage(MessageRecord messageRecord)
        {
            InternalLogger.Trace(string.Format(Properties.Strings.WebEndpoint_ProcessingMessage, messageRecord.Id,
                                               messageRecord.ContentType), nameof(WebEndpoint));
            var isPipelineFound = false;

            foreach (IMessagePipeline pipeline in pipelines)
            {
                if (pipeline.MessageTypes.Contains(messageRecord.Type))
                {
                    var converter = pipeline as IMessageRecordConverter;
                    if (converter != null)
                    {
                        var pipelineService = new DefaultMessagePipelineService();
                        pipelineService.ServiceProvider = serviceProviderFactory.Create();
                        var message = converter.CreateMessageContext(pipelineService, messageRecord);
                        try
                        {
                            pipeline.Invoke(message);
                        }
                        finally
                        {
                            var disposable = pipelineService.ServiceProvider as IDisposable;
                            disposable?.Dispose();
                        }
                    }
                    isPipelineFound = true;
                }
            }

            if (!isPipelineFound)
            {
                InternalLogger.Warn(string.Format(Properties.Strings.WebEndpoint_PipelineNotFound,
                                                  messageRecord.Type, messageRecord.Id, messageRecord.ContentType), nameof(WebEndpoint));
            }
        }
 public void NullEditorState_Throws()
 {
     Assert.Throws <ArgumentNullException>("editorState", () => new TempFileBufferStateListener(null,
                                                                                                IVsEditorAdaptersFactoryServiceFactory.Create(),
                                                                                                ITextDocumentFactoryServiceFactory.Create(),
                                                                                                IProjectThreadingServiceFactory.Create(),
                                                                                                IVsShellUtilitiesHelperFactory.Create(),
                                                                                                IServiceProviderFactory.Create()));
 }
 public void GlobalJsonRemover_NullFileSystem_Throws()
 {
     Assert.Throws <ArgumentNullException>("fileSystem", () => new GlobalJsonRemover(IServiceProviderFactory.Create(), null));
 }
 public void FrameOpenCloseListener_NullEditorModel_Throws()
 {
     Assert.Throws <ArgumentNullException>("editorModel", () => new FrameOpenCloseListener(IServiceProviderFactory.Create(), null,
                                                                                           IProjectThreadingServiceFactory.Create(), UnconfiguredProjectFactory.Create()));
 }
        public void GlobaJsonSetup_NoExistingRemover_RegistersForAdvise()
        {
            UnitTestHelper.IsRunningUnitTests = true;
            GlobalJsonRemover.Remover         = null;

            var solution      = IVsSolutionFactory.CreateWithAdviseUnadviseSolutionEvents(1234);
            var setupOccurred = new GlobalJsonRemover.GlobalJsonSetup().SetupRemoval(solution, IServiceProviderFactory.Create(), IFileSystemFactory.Create());

            Assert.True(setupOccurred);
            Assert.Equal(1234u, GlobalJsonRemover.Remover.SolutionCookie);
        }
 public void FrameOpenCloseListener_NullProject_Throws()
 {
     Assert.Throws <ArgumentNullException>("unconfiguredProject", () => new FrameOpenCloseListener(IServiceProviderFactory.Create(),
                                                                                                   IProjectFileEditorPresenterFactory.Create(), IProjectThreadingServiceFactory.Create(), null));
 }
Beispiel #27
0
 public void MigrateXprojProjectFactory_NullProcessRunner_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("runner", () => new MigrateXprojProjectFactory(null, new IFileSystemMock(), IServiceProviderFactory.Create()));
 }
Beispiel #28
0
 public void MigrateXprojProjectFactory_NullFileSystem_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("fileSystem", () => new MigrateXprojProjectFactory(ProcessRunnerFactory.CreateRunner(), null, IServiceProviderFactory.Create()));
 }
 private static SingleFileGeneratorFactoryAggregator CreateInstance()
 {
     return(new SingleFileGeneratorFactoryAggregator(IServiceProviderFactory.Create(), IVsUnconfiguredProjectIntegrationServiceFactory.Create()));
 }