Files
Heimdall/tests/Heimdall.Application.Tests/Handlers/Persons/CreatePersonHandlerTests.cs
T

42 lines
1.5 KiB
C#

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<IApplicationDbContext>();
context.Persons.Returns(MockDbSetHelper.CreateFor<Person>());
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<int>(), Arg.Any<CancellationToken>());
}
[Fact]
public async Task Create_person_default_category_should_be_null()
{
var context = Substitute.For<IApplicationDbContext>();
context.Persons.Returns(MockDbSetHelper.CreateFor<Person>());
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");
}
}