Removed todos and added User endpoint combined with register. Id changed to guid
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using Hutopy.Application.Common.Behaviours;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.TodoItems.Commands.CreateTodoItem;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -9,37 +8,13 @@ namespace Hutopy.Application.UnitTests.Common.Behaviours;
|
||||
|
||||
public class RequestLoggerTests
|
||||
{
|
||||
private Mock<ILogger<CreateTodoItemCommand>> _logger = null!;
|
||||
private Mock<IUser> _user = null!;
|
||||
private Mock<IIdentityService> _identityService = null!;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_logger = new Mock<ILogger<CreateTodoItemCommand>>();
|
||||
_user = new Mock<IUser>();
|
||||
_identityService = new Mock<IIdentityService>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ShouldCallGetUserNameAsyncOnceIfAuthenticated()
|
||||
{
|
||||
_user.Setup(x => x.Id).Returns(Guid.NewGuid().ToString());
|
||||
|
||||
var requestLogger = new LoggingBehaviour<CreateTodoItemCommand>(_logger.Object, _user.Object, _identityService.Object);
|
||||
|
||||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, new CancellationToken());
|
||||
|
||||
_identityService.Verify(i => i.GetUserNameAsync(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ShouldNotCallGetUserNameAsyncOnceIfUnauthenticated()
|
||||
{
|
||||
var requestLogger = new LoggingBehaviour<CreateTodoItemCommand>(_logger.Object, _user.Object, _identityService.Object);
|
||||
|
||||
await requestLogger.Process(new CreateTodoItemCommand { ListId = 1, Title = "title" }, new CancellationToken());
|
||||
|
||||
_identityService.Verify(i => i.GetUserNameAsync(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ using System.Runtime.CompilerServices;
|
||||
using AutoMapper;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Application.TodoItems.Queries.GetTodoItemsWithPagination;
|
||||
using Hutopy.Application.TodoLists.Queries.GetTodos;
|
||||
using Hutopy.Domain.Entities;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -17,7 +15,7 @@ public class MappingTests
|
||||
|
||||
public MappingTests()
|
||||
{
|
||||
_configuration = new MapperConfiguration(config =>
|
||||
_configuration = new MapperConfiguration(config =>
|
||||
config.AddMaps(Assembly.GetAssembly(typeof(IApplicationDbContext))));
|
||||
|
||||
_mapper = _configuration.CreateMapper();
|
||||
@@ -29,19 +27,6 @@ public class MappingTests
|
||||
_configuration.AssertConfigurationIsValid();
|
||||
}
|
||||
|
||||
[Test]
|
||||
[TestCase(typeof(TodoList), typeof(TodoListDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(TodoItemDto))]
|
||||
[TestCase(typeof(TodoList), typeof(LookupDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(LookupDto))]
|
||||
[TestCase(typeof(TodoItem), typeof(TodoItemBriefDto))]
|
||||
public void ShouldSupportMappingFromSourceToDestination(Type source, Type destination)
|
||||
{
|
||||
var instance = GetInstanceOf(source);
|
||||
|
||||
_mapper.Map(instance, source, destination);
|
||||
}
|
||||
|
||||
private object GetInstanceOf(Type type)
|
||||
{
|
||||
if (type.GetConstructor(Type.EmptyTypes) != null)
|
||||
|
||||
Reference in New Issue
Block a user