40 lines
1.5 KiB
C#
40 lines
1.5 KiB
C#
using Heimdall.Application.Common;
|
|||
|
|
using Heimdall.Application.Settings.Commands.RemoveAgentSetting;
|
||
|
|
using Heimdall.Application.Tests.Common;
|
||
|
|
using Heimdall.Domain.Entities;
|
||
|
|
using NSubstitute;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Tests.Handlers.Settings;
|
||
|
|
|
||
|
|
public class RemoveAgentSettingHandlerTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public async Task Remove_agent_setting_should_return_success()
|
||
|
|
{
|
||
|
|
var agentId = Guid.NewGuid();
|
||
|
|
var setting = new AgentSetting(agentId, "agent.key", "value");
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.AgentSettings.Returns(MockDbSetHelper.CreateFor<AgentSetting>([setting]));
|
||
|
|
context.SaveChangesWithRetryAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||
|
|
var handler = new RemoveAgentSettingCommandHandler(context);
|
||
|
|
|
||
|
|
var result = await handler.Handle(
|
||
|
|
new RemoveAgentSettingCommand(agentId, "agent.key"), CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeTrue();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Remove_nonexistent_agent_setting_should_return_not_found()
|
||
|
|
{
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.AgentSettings.Returns(MockDbSetHelper.CreateFor<AgentSetting>());
|
||
|
|
var handler = new RemoveAgentSettingCommandHandler(context);
|
||
|
|
|
||
|
|
var result = await handler.Handle(
|
||
|
|
new RemoveAgentSettingCommand(Guid.NewGuid(), "missing.key"), CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeFalse();
|
||
|
|
result.StatusCode.ShouldBe(404);
|
||
|
|
}
|
||
|
|
}
|