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); }
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)); }
public static ITextBufferFactory GetLinkBufferFactory() { if (_linkBufferFactory == null) { _linkBufferFactory = new LinkBufferFactory(); } return(_linkBufferFactory); }
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)); }
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); }
public void Dispose() { if (this.loader == null) { return; } this.loader.Dispose(); this.loader = (Loader)null; this.textBufferFactoryProvider = (ITextBufferFactory)null; this.textEditorFactoryProvider = (ITextEditorFactory)null; this.editorCommandsProvider = (IEditorOperationsProvider)null; this.undoManagerProvider = (ITextBufferUndoManagerProvider)null; this.contentTypeRegistry = (IContentTypeRegistry)null; this.squiggleProviderFactory = (ISquiggleProviderFactory)null; this.completionBrokerMap = (ICompletionBrokerMap)null; this.undoHistoryRegistry = (IUndoHistoryRegistry)null; }
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)); }
private void Initialize() { if (this.ready) { return; } if (this.loader == null) { this.loader = Loader.CreateLoader(((EditingService.CompiledCompositionEntryPoint)Delegate.CreateDelegate(typeof(EditingService.CompiledCompositionEntryPoint), Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(EditingService)).Location), "Microsoft.Nautilus.Composition.dll")).EntryPoint))()); this.loader.Initialize(); } this.textBufferFactoryProvider = this.loader.GetService <ITextBufferFactory>(); this.textEditorFactoryProvider = this.loader.GetService <ITextEditorFactory>(); this.editorCommandsProvider = this.loader.GetService <IEditorOperationsProvider>(); this.undoManagerProvider = this.loader.GetService <ITextBufferUndoManagerProvider>(); this.contentTypeRegistry = this.loader.GetService <IContentTypeRegistry>(); this.squiggleProviderFactory = this.loader.GetService <ISquiggleProviderFactory>(); this.completionBrokerMap = this.loader.GetService <ICompletionBrokerMap>(); this.undoHistoryRegistry = this.loader.GetService <IUndoHistoryRegistry>(); this.contentTypeRegistry.AddContentType("text.xml", "XML", (IEnumerable <string>) new string[1] { "text" }); this.contentTypeRegistry.AddContentType("text.xaml", "XAML", (IEnumerable <string>) new string[1] { "text" }); this.contentTypeRegistry.AddContentType("text.C#", "C#", (IEnumerable <string>) new string[1] { "text" }); this.contentTypeRegistry.AddContentType("text.VB", "VB", (IEnumerable <string>) new string[1] { "text" }); this.contentTypeRegistry.AddContentType("text.JS", "JS", (IEnumerable <string>) new string[1] { "text" }); this.ready = true; }