37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Heimdall.Application.Common;
|
|||
|
|
using Heimdall.Application.Settings.Commands.DeleteAppSetting;
|
||
|
|
using Heimdall.Application.Tests.Common;
|
||
|
|
using Heimdall.Domain.Entities;
|
||
|
|
using NSubstitute;
|
||
|
|
|
||
|
|
namespace Heimdall.Application.Tests.Handlers.Settings;
|
||
|
|
|
||
|
|
public class DeleteAppSettingHandlerTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public async Task Delete_setting_should_return_success()
|
||
|
|
{
|
||
|
|
var setting = new AppSetting("test.key", "value");
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.AppSettings.Returns(MockDbSetHelper.CreateFor<AppSetting>([setting]));
|
||
|
|
context.SaveChangesWithRetryAsync(Arg.Any<int>(), Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
|
||
|
|
var handler = new DeleteAppSettingCommandHandler(context);
|
||
|
|
|
||
|
|
var result = await handler.Handle(new DeleteAppSettingCommand("test.key"), CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeTrue();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task Delete_nonexistent_setting_should_return_not_found()
|
||
|
|
{
|
||
|
|
var context = Substitute.For<IApplicationDbContext>();
|
||
|
|
context.AppSettings.Returns(MockDbSetHelper.CreateFor<AppSetting>());
|
||
|
|
var handler = new DeleteAppSettingCommandHandler(context);
|
||
|
|
|
||
|
|
var result = await handler.Handle(new DeleteAppSettingCommand("missing.key"), CancellationToken.None);
|
||
|
|
|
||
|
|
result.IsSuccess.ShouldBeFalse();
|
||
|
|
result.StatusCode.ShouldBe(404);
|
||
|
|
}
|
||
|
|
}
|