GFramework/GFramework.Core.Tests/Cqrs/CqrsPublicNamespaceCompatibilityTests.cs
gewuyou ff553977e3 chore(license): 补齐 Apache-2.0 文件头治理
- 新增许可证文件头检查与修复脚本

- 补充维护者手动修复 PR 工作流和 CI 校验

- 更新贡献指南中的文件头说明

- 补齐仓库维护源码和配置文件的许可证声明
2026-05-03 19:39:49 +08:00

80 lines
3.0 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.

// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
using GFramework.Cqrs.Abstractions.Cqrs;
using GFramework.Cqrs.Abstractions.Cqrs.Command;
using GFramework.Cqrs.Abstractions.Cqrs.Notification;
using GFramework.Cqrs.Abstractions.Cqrs.Query;
using GFramework.Cqrs.Abstractions.Cqrs.Request;
using GFramework.Cqrs.Command;
using GFramework.Cqrs.Notification;
using GFramework.Cqrs.Query;
using GFramework.Cqrs.Request;
namespace GFramework.Core.Tests.Cqrs;
/// <summary>
/// 锁定 CQRS 基础消息类型在 runtime 拆分后的公开命名空间与程序集兼容性。
/// </summary>
[TestFixture]
public sealed class CqrsPublicNamespaceCompatibilityTests
{
/// <summary>
/// 验证基础消息类型继续暴露在历史公开 CQRS 命名空间GFramework.Cqrs.*),同时由独立 runtime 程序集承载实现。
/// </summary>
[Test]
public void Base_Message_Types_Should_Live_In_Cqrs_Namespaces_And_Runtime_Assembly()
{
Assert.Multiple(() =>
{
AssertLegacyType(typeof(CommandBase<TestCommandInput, Unit>), "GFramework.Cqrs.Command");
AssertLegacyType(typeof(QueryBase<TestQueryInput, string>), "GFramework.Cqrs.Query");
AssertLegacyType(typeof(RequestBase<TestRequestInput, string>), "GFramework.Cqrs.Request");
AssertLegacyType(typeof(NotificationBase<TestNotificationInput>), "GFramework.Cqrs.Notification");
});
}
/// <summary>
/// 验证旧的 GFramework.Core 程序集限定名仍可解析到迁移后的 runtime 实现类型。
/// </summary>
[Test]
public void Type_Forwarding_Should_Resolve_Cqrs_Types_From_Core_Assembly()
{
Assert.Multiple(() =>
{
AssertForwardedType("GFramework.Cqrs.Command.CommandBase`2, GFramework.Core");
AssertForwardedType("GFramework.Cqrs.Query.QueryBase`2, GFramework.Core");
AssertForwardedType("GFramework.Cqrs.Request.RequestBase`2, GFramework.Core");
AssertForwardedType("GFramework.Cqrs.Notification.NotificationBase`1, GFramework.Core");
});
}
private static void AssertLegacyType(Type type, string expectedNamespace)
{
Assert.Multiple(() =>
{
Assert.That(type.Namespace, Is.EqualTo(expectedNamespace));
Assert.That(type.Assembly.GetName().Name, Is.EqualTo("GFramework.Cqrs"));
});
}
private static void AssertForwardedType(string assemblyQualifiedTypeName)
{
var resolvedType = Type.GetType(assemblyQualifiedTypeName, throwOnError: false);
Assert.Multiple(() =>
{
Assert.That(resolvedType, Is.Not.Null);
Assert.That(resolvedType!.Assembly.GetName().Name, Is.EqualTo("GFramework.Cqrs"));
});
}
private sealed record TestCommandInput : ICommandInput;
private sealed record TestQueryInput : IQueryInput;
private sealed record TestRequestInput : IRequestInput;
private sealed record TestNotificationInput : INotificationInput;
}