-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Tests): add Application integration tests and some fix and refactor
- Loading branch information
1 parent
6306929
commit a3b8e99
Showing
19 changed files
with
433 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,11 @@ jobs: | |
- name: Test solution | ||
run: dotnet test --no-build --configuration Release --filter "FullyQualifiedName!~AcceptanceTests" | ||
|
||
- name: Analyze with SonarCloud | ||
uses: sonarsource/[email protected] | ||
env: | ||
SONAR_TOKEN: ${{ secrets.SONARCLOUND_TOKEN }} | ||
|
||
- name: Publish website | ||
if: ${{ inputs.build-artifacts == true }} | ||
run: | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/Application.IntegrationTests/TodoItems/Commands/CreateTodoItemTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.Common.Exceptions; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.CreateTodoItem; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Domain.TodoItems; | ||
using FluentAssertions; | ||
|
||
namespace Application.IntegrationTests.TodoItems.Commands; | ||
|
||
internal sealed class CreateTodoItemTests : BaseIntegrationTest | ||
{ | ||
[Test] | ||
public async Task CreateTodoItem_ShouldThrowValidation_WhenRequireMinimumFields() | ||
{ | ||
// Arrange | ||
var command = new CreateTodoItemCommand(); | ||
|
||
// Act & Assert | ||
await FluentActions.Invoking(() => | ||
Sender.Send(command)).Should().ThrowAsync<ValidationException>(); | ||
} | ||
|
||
[Test] | ||
public async Task CreateTodoItem_ShouldCreateTodoItem_WhenRequestIsValid() | ||
{ | ||
// Arrange | ||
var listId = await Sender.Send(new CreateTodoListCommand() { Title = "New List" }); | ||
|
||
var command = new CreateTodoItemCommand | ||
{ | ||
ListId = listId.Value, | ||
Title = "Tasks" | ||
}; | ||
|
||
// Act | ||
var itemId = await Sender.Send(command); | ||
|
||
// Assert | ||
var item = await FindAsync<TodoItem>(itemId.Value); | ||
|
||
item.Should().NotBeNull(); | ||
item!.ListId.Should().Be(command.ListId); | ||
item.Title.Should().Be(command.Title); | ||
item.CreatedAtUtc.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMilliseconds(10000)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Application.IntegrationTests/TodoItems/Commands/DeleteTodoItemTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.ComponentModel; | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.CreateTodoItem; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.DeleteTodoItem; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Domain.TodoItems; | ||
using FluentAssertions; | ||
using FluentResults; | ||
|
||
namespace Application.IntegrationTests.TodoItems.Commands; | ||
|
||
internal sealed class DeleteTodoItemTests : BaseIntegrationTest | ||
{ | ||
private Result<Guid> _listId; | ||
|
||
[OneTimeSetUp] | ||
public async Task SetUp() => _listId = await Sender.Send(new CreateTodoListCommand | ||
{ | ||
Title = "New lists" | ||
}); | ||
|
||
[TestCase(true)] | ||
[TestCase(false)] | ||
public async Task DeleteTodoItem_ShouldDeleteTodoItem_WhenValidParam(bool itemExists) | ||
{ | ||
// Arrange | ||
var itemId = itemExists ? await Sender.Send(new CreateTodoItemCommand | ||
{ | ||
ListId = _listId.Value, | ||
Title = "New item" | ||
}) : Guid.NewGuid(); | ||
|
||
// Act | ||
await Sender.Send(new DeleteTodoItemCommand(itemId.Value)); | ||
|
||
// Assert | ||
var item = await FindAsync<TodoItem>(itemId.Value); | ||
item.Should().BeNull(); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
tests/Application.IntegrationTests/TodoItems/Commands/UpdateTodoItemDetailTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.CreateTodoItem; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.UpdateTodoItemDetail; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Domain.TodoItems; | ||
using FastCleanArchitecture.Domain.TodoItems.Enums; | ||
using FluentAssertions; | ||
|
||
namespace Application.IntegrationTests.TodoItems.Commands; | ||
|
||
internal sealed class UpdateTodoItemDetailTests : BaseIntegrationTest | ||
{ | ||
[Test] | ||
public async Task UpdateTodoItemDetail_ShouldReturnFailure_WhenItemNotFound() | ||
{ | ||
// Arrange | ||
var command = new UpdateTodoItemDetailCommand | ||
{ | ||
Id = Guid.NewGuid(), | ||
Body = new UpdateTodoItemDetailCommand.BodyItemDetailRequest { } | ||
}; | ||
|
||
// Act | ||
var result = await Sender.Send(command); | ||
|
||
// Assert | ||
result.IsFailed.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public async Task UpdateTodoItemDetail_ShouldUpdateDetail_WhenValidParam() | ||
{ | ||
// Arrange | ||
var listId = await Sender.Send(new CreateTodoListCommand { Title = "New list" }); | ||
var itemId = await Sender.Send(new CreateTodoItemCommand | ||
{ | ||
ListId = listId.Value, | ||
Title = "New Item" | ||
}); | ||
|
||
var command = new UpdateTodoItemDetailCommand | ||
{ | ||
Id = itemId.Value, | ||
Body = new UpdateTodoItemDetailCommand.BodyItemDetailRequest | ||
{ | ||
ListId = listId.Value, | ||
Note = "A nother note...", | ||
Priority = PriorityLevel.High | ||
} | ||
}; | ||
|
||
// Act | ||
await Sender.Send(command); | ||
|
||
// Assert | ||
var item = await FindAsync<TodoItem>(itemId.Value); | ||
|
||
item.Should().NotBeNull(); | ||
item!.ListId.Should().Be(listId.Value); | ||
item.Note.Should().Be(command.Body.Note); | ||
item.Priority.Should().Be(command.Body.Priority); | ||
item.ModifiedAtUtc.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMilliseconds(10000)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/Application.IntegrationTests/TodoItems/Commands/UpdateTodoItemTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.CreateTodoItem; | ||
using FastCleanArchitecture.Application.TodoItems.Commands.UpdateTodoItem; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Domain.TodoItems; | ||
using FluentAssertions; | ||
|
||
namespace Application.IntegrationTests.TodoItems.Commands; | ||
|
||
internal sealed class UpdateTodoItemTests : BaseIntegrationTest | ||
{ | ||
[Test] | ||
public async Task UpdateTodoItem_ShouldReturnFailure_WhenItemNotFound() | ||
{ | ||
// Arrange | ||
var command = new UpdateTodoItemCommand | ||
{ | ||
Id = Guid.NewGuid(), | ||
Body = new UpdateTodoItemCommand.BodyItemRequest() { Title = "New Title" } | ||
}; | ||
|
||
// Act | ||
var result = await Sender.Send(command); | ||
|
||
// Assert | ||
result.IsFailed.Should().BeTrue(); | ||
} | ||
|
||
[Test] | ||
public async Task UpdateTodoItem_ShouldUpdate_WhenValidParams() | ||
{ | ||
// Arrange | ||
var listId = await Sender.Send(new CreateTodoListCommand | ||
{ | ||
Title = "New list", | ||
}); | ||
|
||
var itemId = await Sender.Send(new CreateTodoItemCommand | ||
{ | ||
ListId = listId.Value, | ||
Title = "New item" | ||
}); | ||
|
||
var command = new UpdateTodoItemCommand | ||
{ | ||
Id = itemId.Value, | ||
Body = new UpdateTodoItemCommand.BodyItemRequest { Title = "Updated item title" } | ||
}; | ||
|
||
// Act | ||
await Sender.Send(command); | ||
|
||
// Assert | ||
var item = await FindAsync<TodoItem>(itemId.Value); | ||
|
||
item.Should().NotBeNull(); | ||
item!.Title.Should().Be(command.Body.Title); | ||
item.ModifiedAtUtc.Should().BeCloseTo(DateTime.UtcNow, TimeSpan.FromMilliseconds(10000)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/Application.IntegrationTests/TodoLists/Commands/CreateTodoListTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.Common.Exceptions; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Application.TodoLists.Queries.GetTodos; | ||
using FluentAssertions; | ||
|
||
namespace Application.IntegrationTests.TodoLists.Commands; | ||
|
||
internal class CreateTodoListTests : BaseIntegrationTest | ||
{ | ||
[Test] | ||
public async Task CreateTodoList_ShouldThrowValidationException_WhenRequireAMinimunFields() | ||
{ | ||
// Act | ||
var act = () => Sender.Send(new CreateTodoListCommand()); | ||
|
||
// Assert | ||
await act.Should().ThrowAsync<ValidationException>(); | ||
} | ||
|
||
[Test] | ||
public async Task CreatTodoList_ShouldThrowValidationException_WhenRequireUniqueTitle() | ||
{ | ||
// Arrange | ||
var command = new CreateTodoListCommand { Title = "Homeworks" }; | ||
await Sender.Send(command); | ||
|
||
// Act and Assert | ||
await FluentActions | ||
.Invoking(() => Sender | ||
.Send(command)) | ||
.Should() | ||
.ThrowAsync<ValidationException>(); | ||
} | ||
|
||
[Test] | ||
public async Task CreateTodoList_ShouldCreateTodoList_WhenRequestIsValidAndSuccessful() | ||
{ | ||
// Arrange | ||
var command = new CreateTodoListCommand { Title = "Participate in a daily meeting." }; | ||
|
||
// Act | ||
var result = await Sender.Send(command); | ||
|
||
// Assert | ||
var lists = await Sender.Send(new GetTodosQuery()); | ||
var list = lists.Value.Lists.FirstOrDefault(x => x.Id!.Equals(result.Value)); | ||
|
||
result.Value.Should().NotBeEmpty(); | ||
list!.Title.Should().Be(command.Title); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/Application.IntegrationTests/TodoLists/Commands/DeleteTodoListTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Application.IntegrationTests.Infrastructure; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Create; | ||
using FastCleanArchitecture.Application.TodoLists.Commands.Delete; | ||
using FastCleanArchitecture.Domain.TodoLists; | ||
using FluentAssertions; | ||
|
||
namespace Application.IntegrationTests.TodoLists.Commands; | ||
|
||
internal class DeleteTodoListTests : BaseIntegrationTest | ||
{ | ||
[Test] | ||
public async Task DeleteTodoList_ShouldDeleteTodoList_WhenRequestIsSuccessful() | ||
{ | ||
var listId = await Sender.Send(new CreateTodoListCommand { Title = "New list" }); | ||
|
||
// Act | ||
await Sender.Send(new DeleteTodoListCommand(listId.Value)); | ||
|
||
// Assert | ||
var list = await FindAsync<TodoList>(listId.Value); | ||
list.Should().BeNull(); | ||
} | ||
} |
Oops, something went wrong.