80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using Heimdall.Domain.Entities;
|
|||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.Domain.Tests.Entities;
|
||
|
|
|
||
|
|
public class AppSettingTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void Create_appsetting_should_set_properties()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("heartbeat.interval", "30", "Heartbeat", "Heartbeat interval in seconds");
|
||
|
|
|
||
|
|
setting.Key.ShouldBe("heartbeat.interval");
|
||
|
|
setting.Value.ShouldBe("30");
|
||
|
|
setting.Category.ShouldBe("Heartbeat");
|
||
|
|
setting.Description.ShouldBe("Heartbeat interval in seconds");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Create_without_description_should_default()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("log.level", "info", "Logging");
|
||
|
|
|
||
|
|
setting.Description.ShouldBeNull();
|
||
|
|
setting.ValueType.ShouldBe("string");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Key_should_be_lowercased_and_trimmed()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting(" HeartBeat.Interval ", "30");
|
||
|
|
|
||
|
|
setting.Key.ShouldBe("heartbeat.interval");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Empty_key_should_throw()
|
||
|
|
{
|
||
|
|
Should.Throw<ArgumentException>(() => new AppSetting("", "value"));
|
||
|
|
Should.Throw<ArgumentException>(() => new AppSetting(" ", "value"));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void UpdateValue_should_change_value_and_timestamp()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("key", "old");
|
||
|
|
var before = setting.UpdatedAt;
|
||
|
|
|
||
|
|
setting.UpdateValue("new");
|
||
|
|
|
||
|
|
setting.Value.ShouldBe("new");
|
||
|
|
setting.UpdatedAt.ShouldBeGreaterThanOrEqualTo(before);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void UpdateMetadata_should_update_fields()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("key", "val");
|
||
|
|
|
||
|
|
setting.UpdateMetadata("New desc", "NewCat", "int", "1,2,3");
|
||
|
|
|
||
|
|
setting.Description.ShouldBe("New desc");
|
||
|
|
setting.Category.ShouldBe("NewCat");
|
||
|
|
setting.ValueType.ShouldBe("int");
|
||
|
|
setting.AllowedValues.ShouldBe("1,2,3");
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void UpdateMetadata_null_fields_should_not_override()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("key", "val", "OriginalCat", "Original desc");
|
||
|
|
setting.UpdateValue("newval");
|
||
|
|
|
||
|
|
setting.UpdateMetadata(null, null, null, null);
|
||
|
|
|
||
|
|
setting.Description.ShouldBe("Original desc");
|
||
|
|
setting.Category.ShouldBe("OriginalCat");
|
||
|
|
setting.ValueType.ShouldBe("string");
|
||
|
|
}
|
||
|
|
}
|