using Heimdall.Application.Common; using Heimdall.Application.Persons.Commands.CreatePerson; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Persons; public class CreatePersonHandlerTests { [Fact] public async Task Create_person_should_return_success() { var context = Substitute.For(); context.Persons.Returns(MockDbSetHelper.CreateFor()); var handler = new CreatePersonCommandHandler(context); var result = await handler.Handle( new CreatePersonCommand("New Person", "family", null, false), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data.ShouldNotBeNull(); result.Data.DisplayName.ShouldBe("New Person"); result.Data.Category.ShouldBe("family"); await context.Received(1).SaveChangesWithRetryAsync(Arg.Any(), Arg.Any()); } [Fact] public async Task Create_person_default_category_should_be_null() { var context = Substitute.For(); context.Persons.Returns(MockDbSetHelper.CreateFor()); var handler = new CreatePersonCommandHandler(context); var result = await handler.Handle( new CreatePersonCommand("Minimal Person", null, null), CancellationToken.None); result.IsSuccess.ShouldBeTrue(); result.Data!.DisplayName.ShouldBe("Minimal Person"); } }