Files
social-media/tests/Application.FunctionalTests/TodoItems/Commands/CreateTodoItemTests.cs
2024-03-09 20:25:30 -05:00

50 lines
1.4 KiB
C#

using Hutopy.Application.Common.Exceptions;
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoItems.Commands;
using static Testing;
public class CreateTodoItemTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireMinimumFields()
{
var command = new CreateTodoItemCommand();
await FluentActions.Invoking(() =>
SendAsync(command)).Should().ThrowAsync<ValidationException>();
}
[Test]
public async Task ShouldCreateTodoItem()
{
var userId = await RunAsDefaultUserAsync();
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
var command = new CreateTodoItemCommand
{
ListId = listId,
Title = "Tasks"
};
var itemId = await SendAsync(command);
var item = await FindAsync<TodoItem>(itemId);
item.Should().NotBeNull();
item!.ListId.Should().Be(command.ListId);
item.Title.Should().Be(command.Title);
item.CreatedBy.Should().Be(userId);
item.Created.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
item.LastModifiedBy.Should().Be(userId);
item.LastModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
}
}