build-flow.api/tests/BuildFlow.Platform.Tests/Menus/MenuRouteNameResolverTests.cs
xiangning b0cf3949d0 feat(workflow): 扩展按钮定义功能并优化错误处理
- 实现三阶段动作链:前置钩子(BeforeActionsJson)、主链(ActionsJson)、后置钩子(AfterActionsJson)
- 扩展自定义函数支持HTTP请求类型,添加相关字段配置
- 重构异常处理机制,引入语义错误码字符串替代数字码
- 优化数据库表名前缀,统一使用b_前缀提升命名规范性
- 实现菜单路由名称自动派生,支持Code到Name的转换
- 重构错误响应信封,code字段改为语义错误码字符串格式
- 添加ImportJobProcessorService后台服务支持
- 优化Swagger文档默认URL重定向逻辑
- 修复IM模块列缺失的数据库补丁机制
2026-07-06 17:27:32 +08:00

52 lines
1.7 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 BuildFlow.Platform.Application.Menus.Helpers;
using FluentAssertions;
using Xunit;
namespace BuildFlow.Platform.Tests.Menus;
/// <summary>
/// 菜单路由 name 派生器测试。
/// 路由 name 不再由用户填写,创建菜单缺省时由后端根据 Code 自动派生。
/// </summary>
public class MenuRouteNameResolverTests
{
[Theory]
[InlineData("system.user", "SystemUser")]
[InlineData("system", "System")]
[InlineData("buildflow.form.expense.list", "BuildflowFormExpenseList")]
[InlineData("build-flow", "BuildFlow")]
[InlineData("expense_request", "ExpenseRequest")]
[InlineData("expenseRequest", "Expenserequest")]
public void DeriveFromCode_ShouldConvertToPascalCase(string code, string expected)
{
MenuRouteNameResolver.DeriveFromCode(code).Should().Be(expected);
}
[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
[InlineData("...___")]
public void DeriveFromCode_ShouldReturnFallbackWhenCodeHasNoAlphanumeric(string? code)
{
MenuRouteNameResolver.DeriveFromCode(code).Should().Be("Menu");
}
[Fact]
public void DeriveFromCode_ShouldTruncateWhenCodeTooLong()
{
// 极长 Code:派生结果不应超过列长度保护阈值(90 字符)。
var longCode = new string('a', 200);
var result = MenuRouteNameResolver.DeriveFromCode(longCode);
result.Should().NotBeEmpty();
result.Length.Should().BeLessThanOrEqualTo(90);
}
[Fact]
public void DeriveFromCode_ShouldHandleMixedCasingAndDigits()
{
MenuRouteNameResolver.DeriveFromCode("app.v2.userProfile")
.Should().Be("AppV2Userprofile");
}
}