GFramework/GFramework.Core.Tests/Packaging/TransitiveGlobalUsingsPackagingTests.cs
GeWuYou 2d1d1a43b6 chore(build): 移除静态全局using配置并实现自动化生成
- 删除所有手动维护的 buildTransitive props 文件
- 从项目文件中移除静态的 global usings 配置
- 删除废弃的 global-usings.modules.json 清单文件
- 移除旧的 TransitiveGlobalUsingsGenerationTests 测试
- 添加新的 TransitiveGlobalUsingsPackagingTests 验证自动化生成
- 在 Directory.Build.targets 中集成 MSBuild 自动化生成任务
- 实现基于源码扫描的动态命名空间发现机制
2026-03-24 22:24:52 +08:00

56 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.IO;
namespace GFramework.Core.Tests.Packaging;
/// <summary>
/// 验证运行时模块在构建期间会自动生成 transitive global usings 资产。
/// 该测试覆盖命名空间自动发现、框架侧过滤和消费者侧排除钩子的最终构建产物。
/// </summary>
[TestFixture]
public class TransitiveGlobalUsingsPackagingTests
{
/// <summary>
/// 验证 GFramework.Core 在构建后会生成 transitive global usings props
/// 且 props 内容来自源码自动发现,并保留消费者侧排除机制。
/// </summary>
[Test]
public void CoreBuild_Should_Generate_AutoDiscovered_TransitiveGlobalUsingsProps()
{
var repositoryRoot = FindRepositoryRoot();
var propsPath = Path.Combine(
repositoryRoot,
"GFramework.Core",
"obj",
"gframework",
"GeWuYou.GFramework.Core.props");
Assert.That(File.Exists(propsPath), Is.True, $"Expected generated props to exist: {propsPath}");
var propsContent = File.ReadAllText(propsPath);
Assert.That(propsContent, Does.Contain("GFramework.Core.Extensions"));
Assert.That(propsContent, Does.Contain("GFramework.Core.Architectures"));
Assert.That(propsContent, Does.Contain("GFramework.Core.Coroutine.Extensions"));
Assert.That(propsContent, Does.Contain("Remove=\"@(GFrameworkExcludedUsing)\""));
Assert.That(propsContent, Does.Not.Contain("System.Runtime.CompilerServices"));
}
/// <summary>
/// 从测试输出目录向上回溯,定位包含解决方案文件的仓库根目录。
/// </summary>
/// <returns>仓库根目录绝对路径。</returns>
private static string FindRepositoryRoot()
{
var currentDirectory = new DirectoryInfo(TestContext.CurrentContext.TestDirectory);
while (currentDirectory != null)
{
var solutionPath = Path.Combine(currentDirectory.FullName, "GFramework.sln");
if (File.Exists(solutionPath))
return currentDirectory.FullName;
currentDirectory = currentDirectory.Parent;
}
throw new DirectoryNotFoundException("Could not locate the repository root for GFramework.");
}
}