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); }
public void NullShellUtilities_Throws() { Assert.Throws <ArgumentNullException>("shellUtilities", () => new TempFileBufferStateListener( IProjectFileEditorPresenterFactory.Create(), IVsEditorAdaptersFactoryServiceFactory.Create(), ITextDocumentFactoryServiceFactory.Create(), IProjectThreadingServiceFactory.Create(), null, IServiceProviderFactory.Create())); }
public async Task EditProjectFileCommand_CorrectNode_CallsOpenAsync() { var tree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}) "); var nodes = ImmutableHashSet.Create(tree); var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: @"C:\Temp\Root\Root.proj"); var editorStateModel = IProjectFileEditorPresenterFactory.Create(); var command = new EditProjectFileCommand(unconfiguredProject, new Lazy <IProjectFileEditorPresenter>(() => editorStateModel)); var result = await command.TryHandleCommandAsync(nodes, CommandId, true, 0, IntPtr.Zero, IntPtr.Zero); Assert.True(result); Mock.Get(editorStateModel).Verify(e => e.OpenEditorAsync(), Times.Once); }
public async Task EditProjectFileCommand_NonRootNode_ShouldntHandle() { var tree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}) Properties () "); var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: @"C:\Temp\Root\Root.proj"); var nodes = ImmutableHashSet.Create(tree.Children[0]); var command = new EditProjectFileCommand(unconfiguredProject, IProjectFileEditorPresenterFactory.CreateLazy()); var result = await command.GetCommandStatusAsync(nodes, CommandId, true, "", 0); Assert.False(result.Handled); Assert.Equal(CommandStatus.NotSupported, result.Status); }
public async Task EditProjectFileCommand_ValidNode_ShouldHandle() { var tree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}) "); var nodes = ImmutableHashSet.Create(tree); var unconfiguredProject = UnconfiguredProjectFactory.Create(filePath: @"C:\Temp\Root\Root.proj"); var command = new EditProjectFileCommand(unconfiguredProject, IProjectFileEditorPresenterFactory.CreateLazy()); var result = await command.GetCommandStatusAsync(nodes, CommandId, true, "", 0); Assert.True(result.Handled); Assert.Equal(CommandStatus.Enabled | CommandStatus.Supported, result.Status); Assert.Equal(string.Format(VSResources.EditProjectFileCommand, $"Root.{Extension}"), result.CommandText); }
public void EditProjectFileCommand_NullProject_Throws() { Assert.Throws <ArgumentNullException>("unconfiguredProject", () => new EditProjectFileCommand(null, IProjectFileEditorPresenterFactory.CreateLazy())); }
public void NullAsUnconfiguredProject_Throws() { var editorPresenter = IProjectFileEditorPresenterFactory.CreateLazy(); Assert.Throws <ArgumentNullException>("unconfiguredProject", () => new EditProjectFileCommand(null, editorPresenter)); }