First commit. Include junk from template to remove
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user