/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.ProcessHost.UnitTests/CodeActions/ExtractRefactoringTests.cs
94 строки
3 KB
David Barbet
Add language server integration test project and implement auto load tests (#84000)
16 июн 2026, 20:34
Не верифицирован
16 июн 2026, 20:34
02c934b
Код
Авторство
О чём код?
// 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 System.Diagnostics.CodeAnalysis; using Microsoft.CodeAnalysis; using Roslyn.Test.Utilities; using Xunit.Abstractions; using LSP = Roslyn.LanguageServer.Protocol; namespace Microsoft.CodeAnalysis.LanguageServer.ProcessHost.UnitTests.CodeActions; public sealed class ExtractRefactoringTests(ITestOutputHelper testOutputHelper) : AbstractLanguageServerClientTests(testOutputHelper) { [Theory, CombinatorialData] public async Task TestExtractBaseClass(bool includeDevKitComponents) { var markup = """ class {|caret:A|} { public void M() { } } """; var workspaceContent = LspTestWorkspaces.SimpleProject.WithCSharp(markup); await using var testLspServer = await CreateLanguageServerAsync(workspaceContent, new() { IncludeDevKitComponents = includeDevKitComponents }); var caretLocation = testLspServer.GetLocations("caret").Single(); await TestCodeActionAsync(testLspServer, caretLocation, FeaturesResources.Extract_base_class, """ internal class NewBaseType { public void M() { } } class A : NewBaseType { } """); } [Theory, CombinatorialData] public async Task TestExtractInterface(bool includeDevKitComponents) { var markup = """ class {|caret:A|} { public void M() { } } """; var workspaceContent = LspTestWorkspaces.SimpleProject.WithCSharp(markup); await using var testLspServer = await CreateLanguageServerAsync(workspaceContent, new() { IncludeDevKitComponents = includeDevKitComponents }); var caretLocation = testLspServer.GetLocations("caret").Single(); await TestCodeActionAsync(testLspServer, caretLocation, FeaturesResources.Extract_interface, """ interface IA { void M(); } class A : IA { public void M() { } } """); } private static async Task TestCodeActionAsync( TestLspClient testLspClient, LSP.Location caretLocation, string codeActionTitle, [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string expected) { var codeActionResults = await testLspClient.RunGetCodeActionsAsync(CreateCodeActionParams(caretLocation)); var unresolvedCodeAction = Assert.Single(codeActionResults, codeAction => codeAction.Title == codeActionTitle); var resolvedCodeAction = await testLspClient.RunGetCodeActionResolveAsync(unresolvedCodeAction); testLspClient.ApplyWorkspaceEdit(resolvedCodeAction.Edit); var updatedCode = testLspClient.GetFileText(caretLocation.DocumentUri); AssertEx.Equal(expected, updatedCode); } }