Removed todos and added User endpoint combined with register. Id changed to guid

This commit is contained in:
Dominic Villemure
2024-04-03 23:57:01 -04:00
parent df8b42bdf1
commit 1f795c53bb
67 changed files with 1750 additions and 1895 deletions

View File

@@ -1,49 +0,0 @@
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));
}
}

View File

@@ -1,41 +0,0 @@
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
using Hutopy.Application.TodoItems.Commands.DeleteTodoItem;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoItems.Commands;
using static Testing;
public class DeleteTodoItemTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireValidTodoItemId()
{
var command = new DeleteTodoItemCommand(99);
await FluentActions.Invoking(() =>
SendAsync(command)).Should().ThrowAsync<NotFoundException>();
}
[Test]
public async Task ShouldDeleteTodoItem()
{
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
var itemId = await SendAsync(new CreateTodoItemCommand
{
ListId = listId,
Title = "New Item"
});
await SendAsync(new DeleteTodoItemCommand(itemId));
var item = await FindAsync<TodoItem>(itemId);
item.Should().BeNull();
}
}

View File

@@ -1,57 +0,0 @@
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
using Hutopy.Application.TodoItems.Commands.UpdateTodoItem;
using Hutopy.Application.TodoItems.Commands.UpdateTodoItemDetail;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Domain.Entities;
using Hutopy.Domain.Enums;
namespace Hutopy.Application.FunctionalTests.TodoItems.Commands;
using static Testing;
public class UpdateTodoItemDetailTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireValidTodoItemId()
{
var command = new UpdateTodoItemCommand { Id = 99, Title = "New Title" };
await FluentActions.Invoking(() => SendAsync(command)).Should().ThrowAsync<NotFoundException>();
}
[Test]
public async Task ShouldUpdateTodoItem()
{
var userId = await RunAsDefaultUserAsync();
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
var itemId = await SendAsync(new CreateTodoItemCommand
{
ListId = listId,
Title = "New Item"
});
var command = new UpdateTodoItemDetailCommand
{
Id = itemId,
ListId = listId,
Note = "This is the note.",
Priority = PriorityLevel.High
};
await SendAsync(command);
var item = await FindAsync<TodoItem>(itemId);
item.Should().NotBeNull();
item!.ListId.Should().Be(command.ListId);
item.Note.Should().Be(command.Note);
item.Priority.Should().Be(command.Priority);
item.LastModifiedBy.Should().NotBeNull();
item.LastModifiedBy.Should().Be(userId);
item.LastModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
}
}

View File

@@ -1,51 +0,0 @@
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
using Hutopy.Application.TodoItems.Commands.UpdateTodoItem;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoItems.Commands;
using static Testing;
public class UpdateTodoItemTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireValidTodoItemId()
{
var command = new UpdateTodoItemCommand { Id = 99, Title = "New Title" };
await FluentActions.Invoking(() => SendAsync(command)).Should().ThrowAsync<NotFoundException>();
}
[Test]
public async Task ShouldUpdateTodoItem()
{
var userId = await RunAsDefaultUserAsync();
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
var itemId = await SendAsync(new CreateTodoItemCommand
{
ListId = listId,
Title = "New Item"
});
var command = new UpdateTodoItemCommand
{
Id = itemId,
Title = "Updated Item Title"
};
await SendAsync(command);
var item = await FindAsync<TodoItem>(itemId);
item.Should().NotBeNull();
item!.Title.Should().Be(command.Title);
item.LastModifiedBy.Should().NotBeNull();
item.LastModifiedBy.Should().Be(userId);
item.LastModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
}
}

View File

@@ -1,54 +0,0 @@
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));
}
}

View File

@@ -1,32 +0,0 @@
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Application.TodoLists.Commands.DeleteTodoList;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoLists.Commands;
using static Testing;
public class DeleteTodoListTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireValidTodoListId()
{
var command = new DeleteTodoListCommand(99);
await FluentActions.Invoking(() => SendAsync(command)).Should().ThrowAsync<NotFoundException>();
}
[Test]
public async Task ShouldDeleteTodoList()
{
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
await SendAsync(new DeleteTodoListCommand(listId));
var list = await FindAsync<TodoList>(listId);
list.Should().BeNull();
}
}

View File

@@ -1,75 +0,0 @@
using Hutopy.Application.Common.Exceptions;
using Hutopy.Application.Common.Security;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Application.TodoLists.Commands.PurgeTodoLists;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoLists.Commands;
using static Testing;
public class PurgeTodoListsTests : BaseTestFixture
{
[Test]
public async Task ShouldDenyAnonymousUser()
{
var command = new PurgeTodoListsCommand();
command.GetType().Should().BeDecoratedWith<AuthorizeAttribute>();
var action = () => SendAsync(command);
await action.Should().ThrowAsync<UnauthorizedAccessException>();
}
[Test]
public async Task ShouldDenyNonAdministrator()
{
await RunAsDefaultUserAsync();
var command = new PurgeTodoListsCommand();
var action = () => SendAsync(command);
await action.Should().ThrowAsync<ForbiddenAccessException>();
}
[Test]
public async Task ShouldAllowAdministrator()
{
await RunAsAdministratorAsync();
var command = new PurgeTodoListsCommand();
var action = () => SendAsync(command);
await action.Should().NotThrowAsync<ForbiddenAccessException>();
}
[Test]
public async Task ShouldDeleteAllLists()
{
await RunAsAdministratorAsync();
await SendAsync(new CreateTodoListCommand
{
Title = "New List #1"
});
await SendAsync(new CreateTodoListCommand
{
Title = "New List #2"
});
await SendAsync(new CreateTodoListCommand
{
Title = "New List #3"
});
await SendAsync(new PurgeTodoListsCommand());
var count = await CountAsync<TodoList>();
count.Should().Be(0);
}
}

View File

@@ -1,70 +0,0 @@
using Hutopy.Application.Common.Exceptions;
using Hutopy.Application.TodoLists.Commands.CreateTodoList;
using Hutopy.Application.TodoLists.Commands.UpdateTodoList;
using Hutopy.Domain.Entities;
namespace Hutopy.Application.FunctionalTests.TodoLists.Commands;
using static Testing;
public class UpdateTodoListTests : BaseTestFixture
{
[Test]
public async Task ShouldRequireValidTodoListId()
{
var command = new UpdateTodoListCommand { Id = 99, Title = "New Title" };
await FluentActions.Invoking(() => SendAsync(command)).Should().ThrowAsync<NotFoundException>();
}
[Test]
public async Task ShouldRequireUniqueTitle()
{
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
await SendAsync(new CreateTodoListCommand
{
Title = "Other List"
});
var command = new UpdateTodoListCommand
{
Id = listId,
Title = "Other List"
};
(await FluentActions.Invoking(() =>
SendAsync(command))
.Should().ThrowAsync<ValidationException>().Where(ex => ex.Errors.ContainsKey("Title")))
.And.Errors["Title"].Should().Contain("'Title' must be unique.");
}
[Test]
public async Task ShouldUpdateTodoList()
{
var userId = await RunAsDefaultUserAsync();
var listId = await SendAsync(new CreateTodoListCommand
{
Title = "New List"
});
var command = new UpdateTodoListCommand
{
Id = listId,
Title = "Updated List Title"
};
await SendAsync(command);
var list = await FindAsync<TodoList>(listId);
list.Should().NotBeNull();
list!.Title.Should().Be(command.Title);
list.LastModifiedBy.Should().NotBeNull();
list.LastModifiedBy.Should().Be(userId);
list.LastModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMilliseconds(10000));
}
}

View File

@@ -1,61 +0,0 @@
using Hutopy.Application.TodoLists.Queries.GetTodos;
using Hutopy.Domain.Entities;
using Hutopy.Domain.ValueObjects;
namespace Hutopy.Application.FunctionalTests.TodoLists.Queries;
using static Testing;
public class GetTodosTests : BaseTestFixture
{
[Test]
public async Task ShouldReturnPriorityLevels()
{
await RunAsDefaultUserAsync();
var query = new GetTodosQuery();
var result = await SendAsync(query);
result.PriorityLevels.Should().NotBeEmpty();
}
[Test]
public async Task ShouldReturnAllListsAndItems()
{
await RunAsDefaultUserAsync();
await AddAsync(new TodoList
{
Title = "Shopping",
Colour = Colour.Blue,
Items =
{
new TodoItem { Title = "Apples", Done = true },
new TodoItem { Title = "Milk", Done = true },
new TodoItem { Title = "Bread", Done = true },
new TodoItem { Title = "Toilet paper" },
new TodoItem { Title = "Pasta" },
new TodoItem { Title = "Tissues" },
new TodoItem { Title = "Tuna" }
}
});
var query = new GetTodosQuery();
var result = await SendAsync(query);
result.Lists.Should().HaveCount(1);
result.Lists.First().Items.Should().HaveCount(7);
}
[Test]
public async Task ShouldDenyAnonymousUser()
{
var query = new GetTodosQuery();
var action = () => SendAsync(query);
await action.Should().ThrowAsync<UnauthorizedAccessException>();
}
}