55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using Hutopy.Application.Common.Exceptions;
|
|
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
|
|
using Hutopy.Domain.Entities;
|
|
|
|
namespace Hutopy.Application.FunctionalTests.TodoLists.Commands;
|
|
|
|
using static Testing;
|
|
|
|
public class CreateTodoListTests : BaseTestFixture
|
|
{
|
|
[Test]
|
|
public async Task ShouldRequireMinimumFields()
|
|
{
|
|
var command = new CreateTodoListCommand();
|
|
await FluentActions.Invoking(() => SendAsync(command)).Should().ThrowAsync<ValidationException>();
|
|
}
|
|
|
|
[Test]
|
|
public async Task ShouldRequireUniqueTitle()
|
|
{
|
|
await SendAsync(new CreateTodoListCommand
|
|
{
|
|
Title = "Shopping"
|
|
});
|
|
|
|
var command = new CreateTodoListCommand
|
|
{
|
|
Title = "Shopping"
|
|
};
|
|
|
|
await FluentActions.Invoking(() =>
|
|
SendAsync(command)).Should().ThrowAsync<ValidationException>();
|
|
}
|
|
|
|
[Test]
|
|
public async Task ShouldCreateTodoList()
|
|
{
|
|
var userId = await RunAsDefaultUserAsync();
|
|
|
|
var command = new CreateTodoListCommand
|
|
{
|
|
Title = "Tasks"
|
|
};
|
|
|
|
var id = await SendAsync(command);
|
|
|
|
var list = await FindAsync<TodoList>(id);
|
|
|
|
list.Should().NotBeNull();
|
|
list!.Title.Should().Be(command.Title);
|
|
list.CreatedBy.Should().Be(userId);
|
|
list.Created.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
|
|
}
|
|
}
|