-
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.
Merge pull request #13 from kamil-oberaj/KO/get-by-id
[FEAT]: GetById queries
- Loading branch information
Showing
52 changed files
with
662 additions
and
72 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
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
74 changes: 74 additions & 0 deletions
74
...oManager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Handle.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,74 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using StudioManager.API.Contracts.EquipmentTypes; | ||
using StudioManager.Application.EquipmentTypes.GetById; | ||
using StudioManager.Domain.Common.Results; | ||
using StudioManager.Domain.Entities; | ||
using StudioManager.Infrastructure; | ||
using StudioManager.Tests.Common; | ||
using StudioManager.Tests.Common.DbContextExtensions; | ||
|
||
namespace StudioManager.Application.Tests.EquipmentTypes.GetEquipmentTypeByIdQueryHandlerTests; | ||
|
||
public sealed class Handle : IntegrationTestBase | ||
{ | ||
private static GetEquipmentTypeByIdQueryHandler _testCandidate = null!; | ||
private static TestDbContextFactory<StudioManagerDbContext> _testDbContextFactory = null!; | ||
|
||
[SetUp] | ||
public async Task SetUpAsync() | ||
{ | ||
var connectionString = await DbMigrator.MigrateDbAsync(); | ||
_testDbContextFactory = new TestDbContextFactory<StudioManagerDbContext>(connectionString); | ||
_testCandidate = new GetEquipmentTypeByIdQueryHandler(_testDbContextFactory, Mapper); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_not_found_when_requesting_non_existing_entity_async() | ||
{ | ||
// Arrange | ||
await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) | ||
{ | ||
await ClearTableContentsForAsync<EquipmentType>(dbContext); | ||
} | ||
|
||
var id = Guid.NewGuid(); | ||
|
||
var command = new GetEquipmentTypeByIdQuery(id); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, Cts.Token); | ||
|
||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<QueryResult<EquipmentTypeReadDto>>(); | ||
result.Data.Should().BeNull(); | ||
result.Succeeded.Should().BeFalse(); | ||
result.StatusCode.Should().Be(NotFoundStatusCode); | ||
result.Error.Should().NotBeNullOrWhiteSpace(); | ||
result.Error.Should().Be($"[NOT FOUND] {nameof(EquipmentType)} with id '{id}' does not exist"); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_success_async() | ||
{ | ||
// Arrange | ||
var equipmentType = EquipmentType.Create("Test-Equipment-Type"); | ||
await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) | ||
{ | ||
await AddEntitiesToTable(dbContext, equipmentType); | ||
} | ||
|
||
var command = new GetEquipmentTypeByIdQuery(equipmentType.Id); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, Cts.Token); | ||
|
||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<QueryResult<EquipmentTypeReadDto>>(); | ||
result.Data.Should().NotBeNull(); | ||
result.Data.Should().BeOfType<EquipmentTypeReadDto>(); | ||
result.Succeeded.Should().BeTrue(); | ||
result.StatusCode.Should().Be(OkStatusCode); | ||
result.Error.Should().BeNullOrWhiteSpace(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...nager.Application.Tests/EquipmentTypes/GetEquipmentTypeByIdQueryHandlerTests/Validator.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,38 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using StudioManager.Application.EquipmentTypes.GetById; | ||
|
||
namespace StudioManager.Application.Tests.EquipmentTypes.GetEquipmentTypeByIdQueryHandlerTests; | ||
|
||
public sealed class Validator | ||
{ | ||
[Test] | ||
public async Task should_return_error_when_id_is_empty_async() | ||
{ | ||
// Arrange | ||
var query = new GetEquipmentTypeByIdQuery(Guid.Empty); | ||
var validator = new GetEquipmentTypeByIdQueryValidator(); | ||
|
||
// Act | ||
var result = await validator.ValidateAsync(query, CancellationToken.None); | ||
|
||
// Assert | ||
result.IsValid.Should().BeFalse(); | ||
result.Errors.Should().ContainSingle(e => e.PropertyName == nameof(query.Id) && e.ErrorMessage == "'Id' must not be empty."); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_success_when_query_is_valid_async() | ||
{ | ||
// Arrange | ||
var query = new GetEquipmentTypeByIdQuery(Guid.NewGuid()); | ||
var validator = new GetEquipmentTypeByIdQueryValidator(); | ||
|
||
// Act | ||
var result = await validator.ValidateAsync(query, CancellationToken.None); | ||
|
||
// Assert | ||
result.IsValid.Should().BeTrue(); | ||
result.Errors.Should().BeEmpty(); | ||
} | ||
} |
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
79 changes: 79 additions & 0 deletions
79
StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Handle.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,79 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using StudioManager.API.Contracts.Equipments; | ||
using StudioManager.Application.Equipments.GetById; | ||
using StudioManager.Domain.Common.Results; | ||
using StudioManager.Domain.Entities; | ||
using StudioManager.Infrastructure; | ||
using StudioManager.Tests.Common; | ||
using StudioManager.Tests.Common.DbContextExtensions; | ||
|
||
namespace StudioManager.Application.Tests.Equipments.GetEquipmentByIdQueryHandlerTests; | ||
|
||
public sealed class Handle : IntegrationTestBase | ||
{ | ||
private static GetEquipmentByIdQueryHandler _testCandidate = null!; | ||
private static TestDbContextFactory<StudioManagerDbContext> _testDbContextFactory = null!; | ||
|
||
|
||
[SetUp] | ||
public async Task SetUpAsync() | ||
{ | ||
var connectionString = await DbMigrator.MigrateDbAsync(); | ||
_testDbContextFactory = new TestDbContextFactory<StudioManagerDbContext>(connectionString); | ||
_testCandidate = new GetEquipmentByIdQueryHandler(_testDbContextFactory, Mapper); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_not_found_when_getting_non_existing_entity_async() | ||
{ | ||
// Arrange | ||
await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) | ||
{ | ||
await ClearTableContentsForAsync<Equipment>(dbContext); | ||
} | ||
|
||
var id = Guid.NewGuid(); | ||
|
||
var command = new GetEquipmentByIdQuery(id); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, Cts.Token); | ||
|
||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<QueryResult<EquipmentReadDto>>(); | ||
result.Data.Should().BeNull(); | ||
result.Succeeded.Should().BeFalse(); | ||
result.StatusCode.Should().Be(NotFoundStatusCode); | ||
result.Error.Should().NotBeNullOrWhiteSpace(); | ||
result.Error.Should().Be($"[NOT FOUND] {nameof(Equipment)} with id '{id}' does not exist"); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_success_async() | ||
{ | ||
// Arrange | ||
var equipmentType = EquipmentType.Create("Test-Equipment-Type"); | ||
var equipment = Equipment.Create("Test-Equipment", equipmentType.Id, 1); | ||
await using (var dbContext = await _testDbContextFactory.CreateDbContextAsync(Cts.Token)) | ||
{ | ||
await ClearTableContentsForAsync<EquipmentType>(dbContext); | ||
await ClearTableContentsForAsync<Equipment>(dbContext); | ||
await AddEntitiesToTable(dbContext, equipmentType); | ||
await AddEntitiesToTable(dbContext, equipment); | ||
} | ||
|
||
var command = new GetEquipmentByIdQuery(equipment.Id); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, Cts.Token); | ||
|
||
result.Should().NotBeNull(); | ||
result.Should().BeOfType<QueryResult<EquipmentReadDto>>(); | ||
result.Data.Should().NotBeNull(); | ||
result.Data.Should().BeOfType<EquipmentReadDto>(); | ||
result.Succeeded.Should().BeTrue(); | ||
result.StatusCode.Should().Be(OkStatusCode); | ||
result.Error.Should().BeNullOrWhiteSpace(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
StudioManager.Application.Tests/Equipments/GetEquipmentByIdQueryHandlerTests/Validator.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,42 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using StudioManager.Application.Equipments.GetById; | ||
|
||
namespace StudioManager.Application.Tests.Equipments.GetEquipmentByIdQueryHandlerTests; | ||
|
||
public sealed class Validator | ||
{ | ||
[Test] | ||
public async Task should_return_error_when_id_is_empty_async() | ||
{ | ||
// Arrange | ||
var command = new GetEquipmentByIdQuery(Guid.Empty); | ||
var validator = new GetEquipmentByIdQueryValidator(); | ||
|
||
// Act | ||
var result = await validator.ValidateAsync(command, CancellationToken.None); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.IsValid.Should().BeFalse(); | ||
result.Errors.Should().NotBeNullOrEmpty(); | ||
result.Errors.Should().HaveCount(1); | ||
result.Errors.First().ErrorMessage.Should().Be("'Id' must not be empty."); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_success_when_query_is_valid_async() | ||
{ | ||
// Arrange | ||
var command = new GetEquipmentByIdQuery(Guid.NewGuid()); | ||
var validator = new GetEquipmentByIdQueryValidator(); | ||
|
||
// Act | ||
var result = await validator.ValidateAsync(command, CancellationToken.None); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.IsValid.Should().BeTrue(); | ||
result.Errors.Should().BeEmpty(); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
StudioManager.Application.Tests/Reservations/GetReservationByIdQueryHandlerTests/Handle.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,68 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using StudioManager.API.Contracts.Reservations; | ||
using StudioManager.Application.Reservations.GetById; | ||
using StudioManager.Application.Tests.Reservations.Common; | ||
using StudioManager.Domain.Common.Results; | ||
using StudioManager.Domain.Entities; | ||
using StudioManager.Infrastructure; | ||
using StudioManager.Tests.Common; | ||
using StudioManager.Tests.Common.DbContextExtensions; | ||
|
||
namespace StudioManager.Application.Tests.Reservations.GetReservationByIdQueryHandlerTests; | ||
|
||
public sealed class Handle : IntegrationTestBase | ||
{ | ||
private static TestDbContextFactory<StudioManagerDbContext> _dbContextFactory = null!; | ||
private static GetReservationByIdQueryHandler _testCandidate = null!; | ||
|
||
[SetUp] | ||
public async Task SetUpAsync() | ||
{ | ||
var connectionString = await DbMigrator.MigrateDbAsync(); | ||
_dbContextFactory = new TestDbContextFactory<StudioManagerDbContext>(connectionString); | ||
_testCandidate = new GetReservationByIdQueryHandler(_dbContextFactory, Mapper); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_not_found_when_requesting_non_existing_reservation_async() | ||
{ | ||
// Arrange | ||
var command = new GetReservationByIdQuery(Guid.NewGuid()); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, CancellationToken.None); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Succeeded.Should().BeFalse(); | ||
result.StatusCode.Should().Be(NotFoundStatusCode); | ||
result.Data.Should().BeNull(); | ||
result.Should().BeOfType<QueryResult<ReservationReadDto>>(); | ||
result.Error.Should().NotBeNullOrWhiteSpace(); | ||
result.Error.Should().Be($"[NOT FOUND] {nameof(Reservation)} with id '{command.Id}' does not exist"); | ||
} | ||
|
||
[Test] | ||
public async Task should_return_success_async() | ||
{ | ||
// Arrange | ||
await using var dbContext = await _dbContextFactory.CreateDbContextAsync(); | ||
var reservation = | ||
await ReservationTestHelper.AddReservationAsync(dbContext); | ||
|
||
var command = new GetReservationByIdQuery(reservation.Id); | ||
|
||
// Act | ||
var result = await _testCandidate.Handle(command, CancellationToken.None); | ||
|
||
// Assert | ||
result.Should().NotBeNull(); | ||
result.Succeeded.Should().BeTrue(); | ||
result.StatusCode.Should().Be(OkStatusCode); | ||
result.Data.Should().NotBeNull(); | ||
result.Data.Should().BeOfType<ReservationReadDto>(); | ||
result.Should().BeOfType<QueryResult<ReservationReadDto>>(); | ||
result.Error.Should().BeNullOrWhiteSpace(); | ||
} | ||
} |
Oops, something went wrong.