/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/WorkspaceProjectFactoryServiceTests.cs
68 строк
3 KB
David Barbet
Use cached mef compositions in LSP tests when possible
10 июн 2026, 19:52
10 июн 2026, 19:52
3582a0a
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using Microsoft.CodeAnalysis.LanguageServer.BrokeredServices; using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; using Microsoft.CodeAnalysis.Remote.ProjectSystem; using Microsoft.Extensions.Logging; using Xunit.Abstractions; namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests; public sealed class WorkspaceProjectFactoryServiceTests(ITestOutputHelper testOutputHelper) : AbstractLanguageServerHostTests(testOutputHelper) { [Fact] public async Task CreateProjectAndBatch() { var loggerFactory = new LoggerFactory(); await using var testLspServer = await CreateLanguageServerAsync(serverConfiguration: ServerConfigurationWithoutDevKit); var workspaceFactory = testLspServer.GetRequiredLspService<LanguageServerWorkspaceFactory>(); var serviceBrokerFactory = testLspServer.GetRequiredLspService<ServiceBrokerFactory>(); var projectTargetFrameworkManager = testLspServer.GetRequiredLspService<ProjectTargetFrameworkManager>(); var clientLanguageServerManager = testLspServer.GetRequiredLspService<IClientLanguageServerManager>(); var container = await serviceBrokerFactory.CreateAsync(workspaceFactory.HostWorkspace); var workspaceProjectFactoryService = new WorkspaceProjectFactoryService( workspaceFactory, projectTargetFrameworkManager, new ProjectInitializationHandler( clientLanguageServerManager, container.GetFullAccessServiceBroker(), loggerFactory), loggerFactory); using var workspaceProject = await workspaceProjectFactoryService.CreateAndAddProjectAsync( new WorkspaceProjectCreationInfo(LanguageNames.CSharp, "DisplayName", FilePath: null, new Dictionary<string, string>()), CancellationToken.None); using var batch = await workspaceProject.StartBatchAsync(CancellationToken.None); var sourceFilePath = MakeAbsolutePath("SourceFile.cs"); var additionalFilePath = MakeAbsolutePath("AdditionalFile.txt"); await workspaceProject.AddSourceFilesAsync([new SourceFileInfo(sourceFilePath, ["Folder"])], CancellationToken.None); await workspaceProject.AddAdditionalFilesAsync([new SourceFileInfo(additionalFilePath, FolderNames: ["Folder"])], CancellationToken.None); await batch.ApplyAsync(CancellationToken.None); // Verify it actually did something; we won't exclusively test each method since those are tested at lower layers var project = workspaceFactory.HostWorkspace.CurrentSolution.Projects.Single(); var document = Assert.Single(project.Documents); Assert.Equal(sourceFilePath, document.FilePath); Assert.Equal("Folder", Assert.Single(document.Folders)); var additionalDocument = Assert.Single(project.AdditionalDocuments); Assert.Equal(additionalFilePath, additionalDocument.FilePath); Assert.Equal("Folder", Assert.Single(additionalDocument.Folders)); } private static string MakeAbsolutePath(string relativePath) { if (OperatingSystem.IsWindows()) return Path.Combine("Z:\\", relativePath); else return Path.Combine("//", relativePath); } }