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 { new("global.key", "global-value", "General"), new("shared.key", "app-value", "General"), }; var agentSettings = new List { new(agentId, "shared.key", "agent-override"), new(agentId, "agent.only", "agent-value"), }; var context = Substitute.For(); context.AppSettings.Returns(MockDbSetHelper.CreateFor(appSettings)); context.AgentSettings.Returns(MockDbSetHelper.CreateFor(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"); } }