38 lines
1.5 KiB
C#
38 lines
1.5 KiB
C#
using Heimdall.Application.Common;
|
|||
|
|
using Heimdall.Application.Settings.Queries.GetEffectiveAgentConfig;
|
||
|
|
using Heimdall.Application.Tests.Common;
|
||
|
|
using Heimdall.Domain.Entities;
|
||
|
|
using NSubstitute;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Tests.Handlers.Settings;
|
||
|
|
|
||
|
|
public class GetEffectiveAgentConfigHandlerTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public async Task Get_effective_config_should_merge_app_and_agent_settings()
|
||
|
|
{
|
||
|
|
var agentId = Guid.NewGuid();
|
||
|
|
var appSettings = new List<AppSetting>
|
||
|
|
{
|
||
|
|
new("global.key", "global-value", "General"),
|
||
|
|
new("shared.key", "app-value", "General"),
|
||
|
|
};
|
||
|
|
var agentSettings = new List<AgentSetting>
|
||
|
|
{
|
||
|
|
new(agentId, "shared.key", "agent-override"),
|
||
|
|
new(agentId, "agent.only", "agent-value"),
|
||
|
|
};
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.AppSettings.Returns(MockDbSetHelper.CreateFor<AppSetting>(appSettings));
|
||
|
|
context.AgentSettings.Returns(MockDbSetHelper.CreateFor<AgentSetting>(agentSettings));
|
||
|
|
var handler = new GetEffectiveAgentConfigQueryHandler(context);
|
||
|
|
|
||
|
|
var result = await handler.Handle(new GetEffectiveAgentConfigQuery(agentId), CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeTrue();
|
||
|
|
result.Data.ShouldNotBeNull();
|
||
|
|
result.Data["global.key"].ShouldBe("global-value");
|
||
|
|
result.Data["shared.key"].ShouldBe("agent-override");
|
||
|
|
result.Data["agent.only"].ShouldBe("agent-value");
|
||
|
|
}
|
||
|
|
}
|