public async Task ProjectReferencingOutputTrackedReference() { string solFile = Util.GetSampleProject("csharp-app-fsharp-lib", "csappfslib.sln"); using (Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { var csharpApp = sol.Items.FirstOrDefault(pr => pr.Name == "csappfslib") as DotNetProject; var fsharpLibrary = sol.Items.FirstOrDefault(pr => pr.Name == "fslib") as DotNetProject; Assert.IsTrue(IdeApp.TypeSystemService.IsOutputTrackedProject(fsharpLibrary)); using (var workspace = await TypeSystemServiceTestExtensions.LoadSolution(sol)) { var projectId = workspace.GetProjectId(csharpApp); var analysisProject = workspace.CurrentSolution.GetProject(projectId); var refs = analysisProject.MetadataReferences.Select(r => new FilePath(r.Display).FileName); Assert.That(refs, Contains.Item("fslib.dll")); } } }
public async Task ProjectModifiedWhilstBeingAddedToSolution() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) { try { var workspace = await TypeSystemServiceTestExtensions.LoadSolution(sol); var project = new ModifyReferencesDuringGetSourceFilesDotNetProject(); project.FileName = Path.Combine(sol.BaseDirectory, "ProjectModifiedWhilstBeingAddedToSolution.csproj"); await project.SaveAsync(Util.GetMonitor()); var reference = ProjectReference.CreateCustomReference(ReferenceType.Package, "System.ComponentModel.Composition"); var assemblyFileName = typeof(System.Xml.Linq.XName).Assembly.Location; project.AddExtraReference(new AssemblyReference(assemblyFileName)); var projectLoadedTask = new TaskCompletionSource <bool> (); workspace.WorkspaceChanged += (sender, e) => { if (e.Kind == Microsoft.CodeAnalysis.WorkspaceChangeKind.ProjectReloaded) { projectLoadedTask.TrySetResult(true); } }; sol.RootFolder.AddItem(project); if (await Task.WhenAny(projectLoadedTask.Task, Task.Delay(5000)) != projectLoadedTask.Task) { Assert.Fail("Timeout waiting for project to be reloaded by the type system service."); } var projectId = workspace.GetProjectId(project); var projectInfo = workspace.CurrentSolution.GetProject(projectId); var metadataReference = projectInfo.MetadataReferences .OfType <Microsoft.CodeAnalysis.PortableExecutableReference> () .FirstOrDefault(r => r.FilePath.EndsWith("System.Xml.Linq.dll", StringComparison.Ordinal)); Assert.IsNotNull(metadataReference, "System.Xml.Linq reference missing from type system information"); } finally { TypeSystemServiceTestExtensions.UnloadSolution(sol); } } }
public async Task TestWorkspacePersistentStorage() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); using (Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) using (var ws = await TypeSystemServiceTestExtensions.LoadSolution(sol)) { var storageLocationService = (MonoDevelopPersistentStorageLocationService)ws.Services.GetService <IPersistentStorageLocationService> (); var storageLocation = System.IO.Path.Combine( storageLocationService.TryGetStorageLocation(ws.CurrentSolution.Id), "sqlite3", "storage.ide"); if (System.IO.File.Exists(storageLocation)) { System.IO.File.Delete(storageLocation); } var solutionSizeTracker = (IIncrementalAnalyzerProvider)Composition.CompositionManager.GetExportedValue <ISolutionSizeTracker> (); // This will return the tracker, since it's a singleton. var analyzer = solutionSizeTracker.CreateIncrementalAnalyzer(ws); // We need this hack because we can't guess when the work coordinator will run the incremental analyzers. await analyzer.NewSolutionSnapshotAsync(ws.CurrentSolution, CancellationToken.None); foreach (var projectFile in sol.GetAllProjects().SelectMany(x => x.Files.Where(file => file.BuildAction == BuildAction.Compile))) { var projectId = ws.GetProjectId(projectFile.Project); var docId = ws.GetDocumentId(projectId, projectFile.FilePath); var doc = ws.GetDocument(docId); if (!doc.SupportsSyntaxTree) { continue; } await Microsoft.CodeAnalysis.FindSymbols.SyntaxTreeIndex.PrecalculateAsync(doc, CancellationToken.None); } var fi = new System.IO.FileInfo(storageLocation); Assert.That(fi.Length, Is.GreaterThan(0)); } }
public async Task TestWorkspacePersistentStorageImplementation() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); var streamName1 = "PersistentService_Solution_WriteReadDifferentInstances1"; var streamName2 = "PersistentService_Solution_WriteReadDifferentInstances2"; using (Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) using (var ws = await TypeSystemServiceTestExtensions.LoadSolution(sol)) { try { var persistentStorageService = ws.Services.GetService <IPersistentStorageService> (); Assert.That(persistentStorageService, Is.TypeOf(typeof(Microsoft.CodeAnalysis.SQLite.SQLitePersistentStorageService))); if (!(persistentStorageService is Microsoft.CodeAnalysis.SQLite.SQLitePersistentStorageService sqlitePersistentStorageService)) { return; } var solutionSizeTracker = (IIncrementalAnalyzerProvider)Composition.CompositionManager.Instance.GetExportedValue <ISolutionSizeTracker> (); // This will return the tracker, since it's a singleton. var analyzer = solutionSizeTracker.CreateIncrementalAnalyzer(ws); // We need this hack because we can't guess when the work coordinator will run the incremental analyzers. await analyzer.NewSolutionSnapshotAsync(ws.CurrentSolution, CancellationToken.None); // Due to the nature of roslyn returning a new wrapper every time we request the storage, do a reflection check. const System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance; var fieldInfo = sqlitePersistentStorageService.GetType().BaseType.GetField("_currentPersistentStorage", flags); using (var persistentStorage = sqlitePersistentStorageService.GetStorage(ws.CurrentSolution, checkBranchId: false)) { Assert.That(persistentStorage, Is.Not.TypeOf(typeof(NoOpPersistentStorage))); Assert.True(await persistentStorage.WriteStreamAsync(streamName1, EncodeString("MyString"))); Assert.True(await persistentStorage.WriteStreamAsync(streamName2, EncodeString("MyString2"))); } var initialFieldValue = fieldInfo.GetValue(sqlitePersistentStorageService); using (var persistentStorage = sqlitePersistentStorageService.GetStorage(ws.CurrentSolution, checkBranchId: false)) { Assert.That(persistentStorage, Is.Not.TypeOf(typeof(NoOpPersistentStorage))); } var secondFieldValue = fieldInfo.GetValue(sqlitePersistentStorageService); Assert.AreSame(initialFieldValue, secondFieldValue); using (var persistentStorage = sqlitePersistentStorageService.GetStorage(ws.CurrentSolution, checkBranchId: false)) { Assert.AreEqual("MyString", ReadStringToEnd(await persistentStorage.ReadStreamAsync(streamName1))); Assert.AreEqual("MyString2", ReadStringToEnd(await persistentStorage.ReadStreamAsync(streamName2))); } } finally { TypeSystemServiceTestExtensions.UnloadSolution(sol); } } Stream EncodeString(string text) { var bytes = Encoding.UTF8.GetBytes(text); var stream = new MemoryStream(bytes); return(stream); } string ReadStringToEnd(Stream stream) { using (stream) { var bytes = new byte [stream.Length]; int count = 0; while (count < stream.Length) { count = stream.Read(bytes, count, (int)stream.Length - count); } return(Encoding.UTF8.GetString(bytes)); } } }