/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Tools/ExternalAccess/RazorCompilerTest/HostOutputsTests.cs
49 строк
2 KB
Cyrus Najmabadi
Remove unused usings
18 июн 2025, 22:17
18 июн 2025, 22:17
481c36c
Код
Авторство
О чём код?
// 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.Linq; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Roslyn.Test.Utilities.TestGenerators; using Xunit; namespace Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler.UnitTests { public class HostOutputsTests : CSharpTestBase { [Fact] public void Added() { var source = """ class C { } """; var parseOptions = TestOptions.Regular; var compilation = CreateCompilation(source, options: TestOptions.DebugDllThrowing, parseOptions: parseOptions); compilation.VerifyDiagnostics(); Assert.Single(compilation.SyntaxTrees); var generator = new PipelineCallbackGenerator(ctx => { var syntaxProvider = ctx.SyntaxProvider.CreateSyntaxProvider((n, _) => n.IsKind(SyntaxKind.ClassDeclaration), (c, _) => c.Node); ctx.RegisterHostOutput(syntaxProvider, static (hpc, node, _) => { hpc.AddOutput("test", node.ToFullString()); }); }); GeneratorDriver driver = CSharpGeneratorDriver.Create(new[] { generator.AsSourceGenerator() }, parseOptions: parseOptions); driver = driver.RunGenerators(compilation); var result = driver.GetRunResult().Results.Single(); Assert.Empty(result.Diagnostics); var hostOutputs = result.GetHostOutputs(); Assert.Equal(1, hostOutputs.Length); Assert.Equal("test", hostOutputs[0].Key); Assert.Equal(source, hostOutputs[0].Value); } } }