GFramework/GFramework.Core.Tests/architecture/ArchitectureConfigurationTests.cs
GeWuYou b49079de3e style(coding-style): 统一代码风格并优化文档格式
- 移除多余using语句和空行,统一代码缩进格式
- 优化注释文档中的缩进和对齐格式
- 简化条件语句和方法实现,提升代码可读性
- 重构协程系统相关类的字段和方法定义格式
- 更新架构服务中容器访问方式的实现
- 调整异步操作类的属性和方法组织结构
- [skip ci]
2026-01-27 20:30:04 +08:00

192 lines
6.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 GFramework.Core.Abstractions.architecture;
using GFramework.Core.Abstractions.logging;
using GFramework.Core.Abstractions.properties;
using GFramework.Core.architecture;
using GFramework.Core.logging;
using NUnit.Framework;
namespace GFramework.Core.Tests.architecture;
/// <summary>
/// ArchitectureConfiguration类的单元测试
/// 测试内容包括:
/// - 构造函数默认值
/// - LoggerProperties默认配置ConsoleLoggerFactoryProvider + Info级别
/// - ArchitectureProperties默认配置AllowLateRegistration=false, StrictPhaseValidation=true
/// - 自定义配置替换
/// - LoggerProperties独立修改
/// - ArchitectureProperties独立修改
/// - IArchitectureConfiguration接口实现验证
/// </summary>
[TestFixture]
public class ArchitectureConfigurationTests
{
[SetUp]
public void SetUp()
{
_configuration = new ArchitectureConfiguration();
}
private ArchitectureConfiguration? _configuration;
/// <summary>
/// 测试构造函数是否正确初始化LoggerProperties
/// </summary>
[Test]
public void Constructor_Should_Initialize_LoggerProperties_With_Default_Values()
{
Assert.That(_configuration, Is.Not.Null);
Assert.That(_configuration!.LoggerProperties, Is.Not.Null);
}
/// <summary>
/// 测试LoggerProperties默认使用ConsoleLoggerFactoryProvider
/// </summary>
[Test]
public void LoggerProperties_Should_Use_ConsoleLoggerFactoryProvider_By_Default()
{
Assert.That(_configuration!.LoggerProperties.LoggerFactoryProvider,
Is.InstanceOf<ConsoleLoggerFactoryProvider>());
}
/// <summary>
/// 测试LoggerProperties默认使用Info日志级别
/// </summary>
[Test]
public void LoggerProperties_Should_Use_Info_LogLevel_By_Default()
{
var consoleProvider = _configuration!.LoggerProperties.LoggerFactoryProvider
as ConsoleLoggerFactoryProvider;
Assert.That(consoleProvider, Is.Not.Null);
Assert.That(consoleProvider!.MinLevel, Is.EqualTo(LogLevel.Info));
}
/// <summary>
/// 测试ArchitectureProperties的AllowLateRegistration默认为false
/// </summary>
[Test]
public void ArchitectureProperties_Should_Have_AllowLateRegistration_Set_To_False_By_Default()
{
Assert.That(_configuration!.ArchitectureProperties.AllowLateRegistration,
Is.False);
}
/// <summary>
/// 测试ArchitectureProperties的StrictPhaseValidation默认为true
/// </summary>
[Test]
public void ArchitectureProperties_Should_Have_StrictPhaseValidation_Set_To_True_By_Default()
{
Assert.That(_configuration!.ArchitectureProperties.StrictPhaseValidation,
Is.True);
}
/// <summary>
/// 测试LoggerProperties可以被自定义配置替换
/// </summary>
[Test]
public void LoggerProperties_Should_Be_Replaced_With_Custom_Configuration()
{
var customProvider = new ConsoleLoggerFactoryProvider { MinLevel = LogLevel.Debug };
var customLoggerProperties = new LoggerProperties
{
LoggerFactoryProvider = customProvider
};
_configuration!.LoggerProperties = customLoggerProperties;
Assert.That(_configuration.LoggerProperties, Is.SameAs(customLoggerProperties));
Assert.That(_configuration.LoggerProperties.LoggerFactoryProvider,
Is.InstanceOf<ConsoleLoggerFactoryProvider>());
var currentProvider = _configuration.LoggerProperties.LoggerFactoryProvider
as ConsoleLoggerFactoryProvider;
Assert.That(currentProvider!.MinLevel, Is.EqualTo(LogLevel.Debug));
}
/// <summary>
/// 测试ArchitectureProperties可以被自定义配置替换
/// </summary>
[Test]
public void ArchitectureProperties_Should_Be_Replaced_With_Custom_Configuration()
{
var customProperties = new ArchitectureProperties
{
AllowLateRegistration = true,
StrictPhaseValidation = false
};
_configuration!.ArchitectureProperties = customProperties;
Assert.That(_configuration.ArchitectureProperties, Is.SameAs(customProperties));
Assert.That(_configuration.ArchitectureProperties.AllowLateRegistration,
Is.True);
Assert.That(_configuration.ArchitectureProperties.StrictPhaseValidation,
Is.False);
}
/// <summary>
/// 测试LoggerProperties可以独立修改
/// </summary>
[Test]
public void LoggerProperties_Should_Be_Modifiable_Independently()
{
var originalProvider = _configuration!.LoggerProperties.LoggerFactoryProvider
as ConsoleLoggerFactoryProvider;
originalProvider!.MinLevel = LogLevel.Debug;
var modifiedProvider = _configuration.LoggerProperties.LoggerFactoryProvider
as ConsoleLoggerFactoryProvider;
Assert.That(modifiedProvider!.MinLevel, Is.EqualTo(LogLevel.Debug));
}
/// <summary>
/// 测试ArchitectureProperties可以独立修改
/// </summary>
[Test]
public void ArchitectureProperties_Should_Be_Modifiable_Independently()
{
_configuration!.ArchitectureProperties.AllowLateRegistration = true;
_configuration.ArchitectureProperties.StrictPhaseValidation = false;
Assert.That(_configuration.ArchitectureProperties.AllowLateRegistration,
Is.True);
Assert.That(_configuration.ArchitectureProperties.StrictPhaseValidation,
Is.False);
}
/// <summary>
/// 测试ArchitectureConfiguration实现IArchitectureConfiguration接口
/// </summary>
[Test]
public void ArchitectureConfiguration_Should_Implement_IArchitectureConfiguration_Interface()
{
Assert.That(_configuration, Is.InstanceOf<IArchitectureConfiguration>());
}
/// <summary>
/// 测试新实例不与其他实例共享LoggerProperties
/// </summary>
[Test]
public void New_Instance_Should_Not_Share_LoggerProperties_With_Other_Instance()
{
var config1 = new ArchitectureConfiguration();
var config2 = new ArchitectureConfiguration();
Assert.That(config1.LoggerProperties, Is.Not.SameAs(config2.LoggerProperties));
}
/// <summary>
/// 测试新实例不与其他实例共享ArchitectureProperties
/// </summary>
[Test]
public void New_Instance_Should_Not_Share_ArchitectureProperties_With_Other_Instance()
{
var config1 = new ArchitectureConfiguration();
var config2 = new ArchitectureConfiguration();
Assert.That(config1.ArchitectureProperties,
Is.Not.SameAs(config2.ArchitectureProperties));
}
}