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.
haoliang-net/tests/CncRepository.Tests/SysConfigRepositoryTests.cs

63 lines
1.8 KiB
C#

This file contains ambiguous Unicode characters!

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);
}
}
}