You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System ;
using CncModels.Entity ;
using CncRepository.Impl ;
using Xunit ;
namespace CncRepository.Tests
{
/// <summary>
/// 系统配置仓储测试
/// </summary>
[Collection("Database")]
public class SysConfigRepositoryTests : IDisposable
{
private readonly SysConfigRepository _repo ;
public SysConfigRepositoryTests ( )
{
_repo = new SysConfigRepository ( TestDb . ConnectionString ) ;
TestDb . TruncateAll ( ) ;
// TruncateAll已插入admin_username/admin_password_hash, 这里只需加test_key
TestDb . Execute ( @"INSERT IGNORE INTO cnc_sys_config (config_key, config_value, value_type, description, updated_at)
VALUES ('test_key', 'test_value', 'string', '测试配置', NOW())" ) ;
}
public void Dispose ( )
{
TestDb . TruncateAll ( ) ;
}
[Fact]
public void GetByKey_ 存 在 的 Key_ 返 回 配 置 ( )
{
var result = _repo . GetByKey ( "test_key" ) ;
Assert . NotNull ( result ) ;
Assert . Equal ( "test_value" , result . ConfigValue ) ;
}
[Fact]
public void GetByKey_ 不 存 在 的 Key_ 返 回 null ( )
{
var result = _repo . GetByKey ( "nonexistent_key" ) ;
Assert . Null ( result ) ;
}
[Fact]
public void GetAll_ 返 回 所 有 配 置 ( )
{
var result = _repo . GetAll ( ) ;
Assert . NotNull ( result ) ;
Assert . True ( result . Count > = 2 ) ;
}
[Fact]
public void UpdateValue_ 修 改 配 置 值 _ 返 回 true ( )
{
var cfg = _repo . GetByKey ( "test_key" ) ;
var result = _repo . UpdateValue ( cfg . Id , "new_value" ) ;
Assert . True ( result ) ;
Assert . Equal ( "new_value" , _repo . GetByKey ( "test_key" ) . ConfigValue ) ;
}
}
}