From bf00b38d93212e95f079ccc04723dbbdde8de820 Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 15:31:23 +0200 Subject: [PATCH 1/8] NuGet updates --- .../Prodot.Patterns.Cqrs.Abstractions.csproj | 7 +++++++ ...t.Patterns.Cqrs.EfCore.Abstractions.csproj | 7 +++++++ .../Prodot.Patterns.Cqrs.EfCore.csproj | 11 ++++++++-- ...rosoftExtensionsDependencyInjection.csproj | 9 +++++++- .../Prodot.Patterns.Cqrs.csproj | 7 +++++++ .../Prodot.Patterns.Cqrs.EfCore.Tests.csproj | 21 ++++++++++++------- ...ExtensionsDependencyInjection.Tests.csproj | 17 ++++++++++----- .../Prodot.Patterns.Cqrs.Tests.csproj | 19 +++++++++++------ 8 files changed, 77 insertions(+), 21 deletions(-) diff --git a/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj b/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj index 450d9d3..972b82e 100644 --- a/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj +++ b/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj @@ -9,4 +9,11 @@ prodot GmbH + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj b/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj index 8328f87..433529d 100644 --- a/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj +++ b/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj @@ -16,5 +16,12 @@ + + + + all + runtime; build; native; contentfiles; analyzers + + diff --git a/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj b/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj index 71275f7..475482f 100644 --- a/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj +++ b/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj @@ -10,12 +10,19 @@ - - + + + + + + all + runtime; build; native; contentfiles; analyzers + + diff --git a/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj b/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj index 5d5866d..0e8b899 100644 --- a/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj +++ b/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj @@ -1,4 +1,4 @@ - + Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection @@ -18,4 +18,11 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj b/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj index c257148..425579b 100644 --- a/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj +++ b/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj @@ -17,4 +17,11 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj index a9d1054..50fa05c 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj @@ -8,19 +8,19 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -30,4 +30,11 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj b/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj index 7292ef7..196bd1c 100644 --- a/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj @@ -9,14 +9,14 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -26,4 +26,11 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + diff --git a/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj b/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj index f3f4a0e..04941a9 100644 --- a/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj @@ -8,16 +8,16 @@ - - + + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -27,4 +27,11 @@ + + + all + runtime; build; native; contentfiles; analyzers + + + From f259a12ecf114e116d0d8b3e29dc3c60edf1518f Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 15:31:32 +0200 Subject: [PATCH 2/8] Version bump to 7.0.0 --- Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index b3f3079..e2c48b8 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,8 +2,8 @@ $(MSBuildThisFileDirectory)prodot-Default.ruleset - 6.0.0 - 6.0.0.0 + 7.0.0 + 7.0.0.0 net6.0 true 10.0 From b0671bc21772dc2daaca182b2329ba1ea1e8d70e Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 18:32:46 +0200 Subject: [PATCH 3/8] More NuGet updates and update to preview C# --- Directory.Build.props | 2 +- .../Prodot.Patterns.Cqrs.Abstractions.csproj | 4 ++++ .../Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj | 4 ++++ .../Prodot.Patterns.Cqrs.EfCore.csproj | 6 +++++- ...ns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj | 6 +++++- Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj | 4 ++++ .../Prodot.Patterns.Cqrs.EfCore.Tests.csproj | 9 +++++++-- ...s.MicrosoftExtensionsDependencyInjection.Tests.csproj | 6 +++++- .../Prodot.Patterns.Cqrs.Tests.csproj | 6 +++++- 9 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index e2c48b8..c06abe4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -6,7 +6,7 @@ 7.0.0.0 net6.0 true - 10.0 + preview enable enable bin\docs\$(MSBuildProjectName).xml diff --git a/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj b/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj index 972b82e..f168464 100644 --- a/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj +++ b/Prodot.Patterns.Cqrs.Abstractions/Prodot.Patterns.Cqrs.Abstractions.csproj @@ -14,6 +14,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj b/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj index 433529d..58e67b4 100644 --- a/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj +++ b/Prodot.Patterns.Cqrs.EfCore.Abstractions/Prodot.Patterns.Cqrs.EfCore.Abstractions.csproj @@ -22,6 +22,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj b/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj index 475482f..33b1688 100644 --- a/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj +++ b/Prodot.Patterns.Cqrs.EfCore/Prodot.Patterns.Cqrs.EfCore.csproj @@ -11,7 +11,7 @@ - + @@ -24,5 +24,9 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj b/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj index 0e8b899..54ee6b8 100644 --- a/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj +++ b/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.csproj @@ -10,7 +10,7 @@ - + @@ -23,6 +23,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj b/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj index 425579b..ab58a8a 100644 --- a/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj +++ b/Prodot.Patterns.Cqrs/Prodot.Patterns.Cqrs.csproj @@ -22,6 +22,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj index 50fa05c..d1f3a00 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Prodot.Patterns.Cqrs.EfCore.Tests.csproj @@ -9,12 +9,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + runtime; build; native; contentfiles; analyzers; buildtransitive @@ -35,6 +36,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj b/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj index 196bd1c..423fc35 100644 --- a/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests/Prodot.Patterns.Cqrs.MicrosoftExtensionsDependencyInjection.Tests.csproj @@ -8,7 +8,7 @@ - + @@ -31,6 +31,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + diff --git a/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj b/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj index 04941a9..90b9b43 100644 --- a/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj +++ b/tests/Prodot.Patterns.Cqrs.Tests/Prodot.Patterns.Cqrs.Tests.csproj @@ -10,7 +10,7 @@ - + @@ -32,6 +32,10 @@ all runtime; build; native; contentfiles; analyzers + + all + runtime; build; native; contentfiles; analyzers + From 5737c16fc826c6a4b31698f4899e55276e3ff4d6 Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 18:33:39 +0200 Subject: [PATCH 4/8] Added support for strongly typed entity ids --- .../CountQueryHandlerBase.cs | 4 +- .../CreateQueryHandlerBase.cs | 6 +- .../DeleteCommandHandlerBase.cs | 12 ++- .../ListOfModelQueryHandlerBase.cs | 6 +- .../SingleModelQueryHandlerBase.cs | 7 +- .../UpdateCommandHandlerBase.cs | 7 +- .../CountQueryHandlerTests.cs | 2 +- .../CreateQueryHandlerTests.cs | 2 +- .../DeleteCommandHandlerTests.cs | 4 +- .../ListOfModelQueryHandlerTests.cs | 2 +- .../SingleModelQueryHandlerTests.cs | 2 +- .../UpdateCommandHandlerTests.cs | 2 +- .../EfCoreTestBase.cs | 7 ++ .../20220826152355_AddStrongIds.Designer.cs | 54 +++++++++++ .../Migrations/20220826152355_AddStrongIds.cs | 33 +++++++ .../Migrations/TestDbContextModelSnapshot.cs | 17 +++- .../StrongIdCountQueryHandlerTests.cs | 44 +++++++++ .../StrongIdCreateQueryHandlerTests.cs | 29 ++++++ .../StrongIdDeleteCommandHandlerTests.cs | 44 +++++++++ .../StrongIdListOfModelQueryHandlerTests.cs | 92 +++++++++++++++++++ .../StrongIdSingleModelQueryHandlerTests.cs | 44 +++++++++ .../StrongIdUpdateCommandHandlerTests.cs | 53 +++++++++++ .../Context/DesignTimeTestDbContextFactory.cs | 15 +++ .../TestHelpers/Context/TestDbContext.cs | 18 ++++ .../TestHelpers/Context/TestEntityStrongId.cs | 17 ++++ .../Handlers/TestModelCountQueryHandler.cs | 6 +- .../Handlers/TestModelCreateQueryHandler.cs | 6 +- .../Handlers/TestModelDeleteCommandHandler.cs | 12 +-- .../Handlers/TestModelQueryHandler.cs | 6 +- .../TestModelStrongIdCountQueryHandler.cs | 11 +++ .../TestModelStrongIdCreateQueryHandler.cs | 14 +++ .../TestModelStrongIdDeleteCommandHandler.cs | 14 +++ .../Handlers/TestModelStrongIdQueryHandler.cs | 14 +++ .../TestModelStrongIdUpdateCommandHandler.cs | 14 +++ .../Handlers/TestModelUpdateCommandHandler.cs | 6 +- .../Handlers/TestModelsQueryHandler.cs | 6 +- .../TestModelsStrongIdQueryHandler.cs | 13 +++ .../Queries/TestModelStrongIdCountQuery.cs | 6 ++ .../Queries/TestModelStrongIdCreateQuery.cs | 5 + .../Queries/TestModelStrongIdDeleteCommand.cs | 6 ++ .../Queries/TestModelStrongIdQuery.cs | 6 ++ .../Queries/TestModelStrongIdUpdateCommand.cs | 6 ++ .../Queries/TestModelsStrongIdQuery.cs | 5 + .../TestHelpers/TestModelStrongId.cs | 12 +++ 44 files changed, 639 insertions(+), 52 deletions(-) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/CountQueryHandlerTests.cs (94%) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/CreateQueryHandlerTests.cs (92%) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/DeleteCommandHandlerTests.cs (92%) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/ListOfModelQueryHandlerTests.cs (97%) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/SingleModelQueryHandlerTests.cs (94%) rename tests/Prodot.Patterns.Cqrs.EfCore.Tests/{ => DirectIdTests}/UpdateCommandHandlerTests.cs (96%) create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.Designer.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCountQueryHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCreateQueryHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdDeleteCommandHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdListOfModelQueryHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdSingleModelQueryHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdUpdateCommandHandlerTests.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/DesignTimeTestDbContextFactory.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestEntityStrongId.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCountQueryHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCreateQueryHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdDeleteCommandHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdQueryHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdUpdateCommandHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsStrongIdQueryHandler.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCountQuery.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCreateQuery.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdDeleteCommand.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdQuery.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdUpdateCommand.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelsStrongIdQuery.cs create mode 100644 tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/TestModelStrongId.cs diff --git a/Prodot.Patterns.Cqrs.EfCore/CountQueryHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/CountQueryHandlerBase.cs index 9037e36..39b65f9 100644 --- a/Prodot.Patterns.Cqrs.EfCore/CountQueryHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/CountQueryHandlerBase.cs @@ -1,11 +1,11 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class CountQueryHandlerBase : IQueryHandler +public abstract class CountQueryHandlerBase : IQueryHandler where TQuery : CountQuery where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; diff --git a/Prodot.Patterns.Cqrs.EfCore/CreateQueryHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/CreateQueryHandlerBase.cs index 5d040ce..5c71279 100644 --- a/Prodot.Patterns.Cqrs.EfCore/CreateQueryHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/CreateQueryHandlerBase.cs @@ -1,11 +1,11 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class CreateQueryHandlerBase : IQueryHandler +public abstract class CreateQueryHandlerBase : IQueryHandler where TQuery : CreateQuery where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; @@ -32,7 +32,7 @@ public async Task> RunQueryAsync(TQuery query, CancellationT await context.Set().AddAsync(entity, cancellationToken).ConfigureAwait(false); await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false); - return Identifier.From(entity.Id); + return _mapper.Map(entity.Id); } } diff --git a/Prodot.Patterns.Cqrs.EfCore/DeleteCommandHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/DeleteCommandHandlerBase.cs index 99dec8a..af828b5 100644 --- a/Prodot.Patterns.Cqrs.EfCore/DeleteCommandHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/DeleteCommandHandlerBase.cs @@ -1,16 +1,18 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class DeleteCommandHandlerBase : IQueryHandler +public abstract class DeleteCommandHandlerBase : IQueryHandler where TQuery : DeleteCommand where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; + private readonly IMapper _mapper; - protected DeleteCommandHandlerBase(IDbContextFactory contextFactory) + protected DeleteCommandHandlerBase(IMapper mapper, IDbContextFactory contextFactory) { + _mapper = mapper; _contextFactory = contextFactory; } @@ -20,8 +22,10 @@ public async Task> RunQueryAsync(TQuery query, CancellationToken ca { using (var context = await _contextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false)) { + var entityId = _mapper.Map(query.Id); + var entity = await context.Set() - .FirstOrDefaultAsync(cp => cp.Id!.Equals(query.Id.Value), cancellationToken) + .FirstOrDefaultAsync(cp => cp.Id!.Equals(entityId), cancellationToken) .ConfigureAwait(false); if (entity == null) diff --git a/Prodot.Patterns.Cqrs.EfCore/ListOfModelQueryHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/ListOfModelQueryHandlerBase.cs index 1476c97..1407900 100644 --- a/Prodot.Patterns.Cqrs.EfCore/ListOfModelQueryHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/ListOfModelQueryHandlerBase.cs @@ -1,11 +1,11 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class ListOfModelQueryHandlerBase : IQueryHandler> +public abstract class ListOfModelQueryHandlerBase : IQueryHandler> where TQuery : ListOfModelQuery where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; @@ -26,7 +26,7 @@ public async Task>> RunQueryAsync(TQuery query, Can if (query.Ids.IsSome) { - var ids = query.Ids.Get().Select(id => id.Value).Distinct().ToList(); + var ids = query.Ids.Get().Select(_mapper.Map).Distinct().ToList(); databaseQuery = databaseQuery .Where(e => ids.Contains(e.Id)); } diff --git a/Prodot.Patterns.Cqrs.EfCore/SingleModelQueryHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/SingleModelQueryHandlerBase.cs index 8f0d7cf..3bda9b7 100644 --- a/Prodot.Patterns.Cqrs.EfCore/SingleModelQueryHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/SingleModelQueryHandlerBase.cs @@ -1,11 +1,11 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class SingleModelQueryHandlerBase : IQueryHandler +public abstract class SingleModelQueryHandlerBase : IQueryHandler where TQuery : SingleModelQuery where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; @@ -22,10 +22,11 @@ public async Task> RunQueryAsync(TQuery query, CancellationToken { using (var context = await _contextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false)) { + var entityId = _mapper.Map(query.Id); var databaseQuery = AddIncludes(context.Set().AsNoTracking()); var entity = await databaseQuery - .FirstOrDefaultAsync(cp => cp.Id!.Equals(query.Id.Value), cancellationToken) + .FirstOrDefaultAsync(cp => cp.Id!.Equals(entityId), cancellationToken) .ConfigureAwait(false); return entity == null ? Option.None : Option.From(_mapper.Map(entity)); diff --git a/Prodot.Patterns.Cqrs.EfCore/UpdateCommandHandlerBase.cs b/Prodot.Patterns.Cqrs.EfCore/UpdateCommandHandlerBase.cs index 99f5e80..bd65187 100644 --- a/Prodot.Patterns.Cqrs.EfCore/UpdateCommandHandlerBase.cs +++ b/Prodot.Patterns.Cqrs.EfCore/UpdateCommandHandlerBase.cs @@ -1,11 +1,11 @@ namespace Prodot.Patterns.Cqrs.EfCore; -public abstract class UpdateCommandHandlerBase : IQueryHandler +public abstract class UpdateCommandHandlerBase : IQueryHandler where TQuery : UpdateCommand where TModel : ModelBase where TIdentifier : Identifier, new() where TContext : DbContext - where TEntity : class, IIdentifiableEntity + where TEntity : class, IIdentifiableEntity { private readonly IDbContextFactory _contextFactory; private readonly IMapper _mapper; @@ -22,10 +22,11 @@ public async Task> RunQueryAsync(TQuery query, CancellationToken ca { using (var context = await _contextFactory.CreateDbContextAsync(cancellationToken).ConfigureAwait(false)) { + var entityId = _mapper.Map(query.UpdatedModel.Id); var entity = _mapper.Map(query.UpdatedModel); var existingEntity = await context.Set() - .FirstOrDefaultAsync(e => e.Id!.Equals(query.UpdatedModel.Id.Value), cancellationToken) + .FirstOrDefaultAsync(e => e.Id!.Equals(entityId), cancellationToken) .ConfigureAwait(false); if (existingEntity == null) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/CountQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CountQueryHandlerTests.cs similarity index 94% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/CountQueryHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CountQueryHandlerTests.cs index 088b933..b3c84f6 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/CountQueryHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CountQueryHandlerTests.cs @@ -1,4 +1,4 @@ -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class CountQueryHandlerTests : EfCoreTestBase { diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/CreateQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CreateQueryHandlerTests.cs similarity index 92% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/CreateQueryHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CreateQueryHandlerTests.cs index afb4e20..f8c997c 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/CreateQueryHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/CreateQueryHandlerTests.cs @@ -1,4 +1,4 @@ -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class CreateQueryHandlerTests : EfCoreTestBase { diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DeleteCommandHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/DeleteCommandHandlerTests.cs similarity index 92% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/DeleteCommandHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/DeleteCommandHandlerTests.cs index 6740ba5..83b8b99 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DeleteCommandHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/DeleteCommandHandlerTests.cs @@ -1,4 +1,4 @@ -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class DeleteCommandHandlerTests : EfCoreTestBase { @@ -31,7 +31,7 @@ public async Task RunQueryAsync_DeletesEntityCorrectly() { Id = TestModelId.From(entity2.Id) }; - var subjectUnderTest = new TestModelDeleteCommandHandler(ContextFactory); + var subjectUnderTest = new TestModelDeleteCommandHandler(Mapper, ContextFactory); // Act var result = await subjectUnderTest.RunQueryAsync(query, default); diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/ListOfModelQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/ListOfModelQueryHandlerTests.cs similarity index 97% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/ListOfModelQueryHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/ListOfModelQueryHandlerTests.cs index 91747ac..4354f31 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/ListOfModelQueryHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/ListOfModelQueryHandlerTests.cs @@ -1,4 +1,4 @@ -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class ListOfModelQueryHandlerTests : EfCoreTestBase { diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/SingleModelQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/SingleModelQueryHandlerTests.cs similarity index 94% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/SingleModelQueryHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/SingleModelQueryHandlerTests.cs index b05fcc8..12d75ab 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/SingleModelQueryHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/SingleModelQueryHandlerTests.cs @@ -1,4 +1,4 @@ -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class SingleModelQueryHandlerTests : EfCoreTestBase { diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/UpdateCommandHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/UpdateCommandHandlerTests.cs similarity index 96% rename from tests/Prodot.Patterns.Cqrs.EfCore.Tests/UpdateCommandHandlerTests.cs rename to tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/UpdateCommandHandlerTests.cs index 308beef..7826e3d 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/UpdateCommandHandlerTests.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/DirectIdTests/UpdateCommandHandlerTests.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; -namespace Prodot.Patterns.Cqrs.EfCore.Tests; +namespace Prodot.Patterns.Cqrs.EfCore.Tests.DirectIdTests; public class UpdateCommandHandlerTests : EfCoreTestBase { diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/EfCoreTestBase.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/EfCoreTestBase.cs index 32bdefe..b68c754 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/EfCoreTestBase.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/EfCoreTestBase.cs @@ -26,6 +26,13 @@ protected EfCoreTestBase() .ConvertUsing((tmid, _) => tmid.Value); o.CreateMap() .ConvertUsing((id, _) => TestModelId.From(id)); + + o.CreateMap().ReverseMap(); + o.CreateMap(); + o.CreateMap() + .ConvertUsing((tmid, _) => new TestEntityStrongId.Identifier(tmid.Value)); + o.CreateMap() + .ConvertUsing((id, _) => TestModelStrongId.Identifier.From(id.Value)); }) .CreateMapper(); diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.Designer.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.Designer.cs new file mode 100644 index 0000000..df8297c --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.Designer.cs @@ -0,0 +1,54 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; + +#nullable disable + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.Migrations +{ + [DbContext(typeof(TestDbContext))] + [Migration("20220826152355_AddStrongIds")] + partial class AddStrongIds + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "7.0.0-preview.7.22376.2"); + + modelBuilder.Entity("Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context.TestEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("StringProperty") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Entities"); + }); + + modelBuilder.Entity("Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context.TestEntityStrongId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("StringProperty") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("StrongIdEntities"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.cs new file mode 100644 index 0000000..57b6f5e --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/20220826152355_AddStrongIds.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.Migrations +{ + /// + public partial class AddStrongIds : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "StrongIdEntities", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false), + StringProperty = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_StrongIdEntities", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "StrongIdEntities"); + } + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/TestDbContextModelSnapshot.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/TestDbContextModelSnapshot.cs index 0fb8131..0b3d380 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/TestDbContextModelSnapshot.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/Migrations/TestDbContextModelSnapshot.cs @@ -14,7 +14,7 @@ partial class TestDbContextModelSnapshot : ModelSnapshot protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 - modelBuilder.HasAnnotation("ProductVersion", "6.0.1"); + modelBuilder.HasAnnotation("ProductVersion", "7.0.0-preview.7.22376.2"); modelBuilder.Entity("Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context.TestEntity", b => { @@ -30,6 +30,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Entities"); }); + + modelBuilder.Entity("Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context.TestEntityStrongId", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("StringProperty") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("StrongIdEntities"); + }); #pragma warning restore 612, 618 } } diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCountQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCountQueryHandlerTests.cs new file mode 100644 index 0000000..f39a4d2 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCountQueryHandlerTests.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdCountQueryHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_ReturnsCorrectCount() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var entities = await Context.Set().CountAsync(); + + var query = new TestModelStrongIdCountQuery(); + var subjectUnderTest = new TestModelStrongIdCountQueryHandler(ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the query should be successful"); + result.Get().Should().Be(3); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCreateQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCreateQueryHandlerTests.cs new file mode 100644 index 0000000..3205526 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdCreateQueryHandlerTests.cs @@ -0,0 +1,29 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdCreateQueryHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_CreatesModelSuccessfully() + { + // Arrange + var model = new TestModelStrongId + { + Id = TestModelStrongId.Identifier.From(0), + StringProperty = "Bla" + }; + var query = new TestModelStrongIdCreateQuery + { + ModelToCreate = model, + }; + var subjectUnderTest = new TestModelStrongIdCreateQueryHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the creation should be successful"); + var entities = Context.StrongIdEntities.ToList(); + entities.Should().HaveCount(1); + entities[0].StringProperty.Should().Be("Bla"); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdDeleteCommandHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdDeleteCommandHandlerTests.cs new file mode 100644 index 0000000..1fd7bdc --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdDeleteCommandHandlerTests.cs @@ -0,0 +1,44 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdDeleteCommandHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_DeletesEntityCorrectly() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var query = new TestModelStrongIdDeleteCommand + { + Id = TestModelStrongId.Identifier.From(entity2.Id.Value) + }; + var subjectUnderTest = new TestModelStrongIdDeleteCommandHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the deletion should be successful"); + var entityCount = Context.StrongIdEntities.Count(); + entityCount.Should().Be(2); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdListOfModelQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdListOfModelQueryHandlerTests.cs new file mode 100644 index 0000000..eb521f4 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdListOfModelQueryHandlerTests.cs @@ -0,0 +1,92 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdListOfModelQueryHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_RetrievesAllEntitiesCorrectly() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var query = new TestModelsStrongIdQuery + { + Ids = Option.None + }; + var subjectUnderTest = new TestModelsStrongIdQueryHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the retrieval should be successful"); + result.Get().Should().HaveCount(3); + } + + [Fact] + public async Task RunQueryAsync_RetrievesSelectedEntitiesCorrectly() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var query = new TestModelsStrongIdQuery + { + Ids = new List + { + TestModelStrongId.Identifier.From(entity2.Id.Value), + TestModelStrongId.Identifier.From(entity3.Id.Value) + } + }; + var subjectUnderTest = new TestModelsStrongIdQueryHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the retrieval should be successful"); + result.Get().Should().HaveCount(2); + + result.Get().First().Id.Should().Be(TestModelStrongId.Identifier.From(entity2.Id.Value)); + result.Get().First().StringProperty.Should().Be("Bla2"); + + result.Get().Last().Id.Should().Be(TestModelStrongId.Identifier.From(entity3.Id.Value)); + result.Get().Last().StringProperty.Should().Be("Bla3"); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdSingleModelQueryHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdSingleModelQueryHandlerTests.cs new file mode 100644 index 0000000..1698eb1 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdSingleModelQueryHandlerTests.cs @@ -0,0 +1,44 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdSingleModelQueryHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_RetrievesEntityCorrectly() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var query = new TestModelStrongIdQuery + { + Id = TestModelStrongId.Identifier.From(entity2.Id.Value) + }; + var subjectUnderTest = new TestModelStrongIdQueryHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the retrieval should be successful"); + result.Get().Id.Should().Be(TestModelStrongId.Identifier.From(entity2.Id.Value)); + result.Get().StringProperty.Should().Be("Bla2"); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdUpdateCommandHandlerTests.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdUpdateCommandHandlerTests.cs new file mode 100644 index 0000000..838b98c --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/StrongIdTests/StrongIdUpdateCommandHandlerTests.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.StrongIdTests; + +public class StrongIdUpdateCommandHandlerTests : EfCoreTestBase +{ + [Fact] + public async Task RunQueryAsync_UpdatesEntityCorrectly() + { + // Arrange + var entity1 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla1" + }; + var entity2 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla2" + }; + var entity3 = new TestEntityStrongId + { + Id = TestEntityStrongId.Identifier.Empty, + StringProperty = "Bla3" + }; + + Context.StrongIdEntities.Add(entity1); + Context.StrongIdEntities.Add(entity2); + Context.StrongIdEntities.Add(entity3); + Context.SaveChanges(); + + var query = new TestModelStrongIdUpdateCommand + { + UpdatedModel = new() + { + Id = TestModelStrongId.Identifier.From(entity2.Id.Value), + StringProperty = "Foo" + } + }; + var subjectUnderTest = new TestModelStrongIdUpdateCommandHandler(Mapper, ContextFactory); + + // Act + var result = await subjectUnderTest.RunQueryAsync(query, default); + + // Assert + result.IsSome.Should().BeTrue("because the update should be successful"); + var entityCount = Context.StrongIdEntities.Count(); + entityCount.Should().Be(3); + + var updatedEntity = Context.StrongIdEntities.AsNoTracking().First(x => x.Id == entity2.Id); + updatedEntity!.StringProperty.Should().Be("Foo"); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/DesignTimeTestDbContextFactory.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/DesignTimeTestDbContextFactory.cs new file mode 100644 index 0000000..ad8de27 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/DesignTimeTestDbContextFactory.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; + +public class DesignTimeTestDbContextFactory : IDesignTimeDbContextFactory +{ + public TestDbContext CreateDbContext(string[] args) + { + var options = new DbContextOptionsBuilder() + .UseSqlite($"DataSource=file:memdbDesignTime?mode=memory&cache=shared") + .Options; + return new TestDbContext(options); + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestDbContext.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestDbContext.cs index e0ef2cf..8d6da52 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestDbContext.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestDbContext.cs @@ -10,4 +10,22 @@ public TestDbContext(DbContextOptions options) } public DbSet Entities { get; set; } = default!; + + public DbSet StrongIdEntities { get; set; } = default!; + + protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) + { + configurationBuilder.Properties() + .HaveConversion(typeof(TestEntityStrongId.Identifier.EfCoreValueConverter)); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasKey(e => e.Id); + + modelBuilder.Entity() + .Property(e => e.Id) + .ValueGeneratedOnAdd(); + } } diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestEntityStrongId.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestEntityStrongId.cs new file mode 100644 index 0000000..fd356ca --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Context/TestEntityStrongId.cs @@ -0,0 +1,17 @@ +using StronglyTypedIds; + +using static Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context.TestEntityStrongId; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; + +public partial class TestEntityStrongId : IIdentifiableEntity +{ + public Identifier Id { get; set; } + + public string StringProperty { get; set; } = string.Empty; + + [StronglyTypedId(StronglyTypedIdBackingType.Int, StronglyTypedIdConverter.EfCoreValueConverter)] + public partial struct Identifier + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCountQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCountQueryHandler.cs index d7ab516..1cb3b73 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCountQueryHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCountQueryHandler.cs @@ -1,11 +1,9 @@ using Microsoft.EntityFrameworkCore; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; - namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelCountQueryHandler : CountQueryHandlerBase +public class TestModelCountQueryHandler + : CountQueryHandlerBase { public TestModelCountQueryHandler(IDbContextFactory contextFactory) : base(contextFactory) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCreateQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCreateQueryHandler.cs index 00e62d1..601f06c 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCreateQueryHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelCreateQueryHandler.cs @@ -2,12 +2,10 @@ using Microsoft.EntityFrameworkCore; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; - namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelCreateQueryHandler : CreateQueryHandlerBase +public class TestModelCreateQueryHandler + : CreateQueryHandlerBase { public TestModelCreateQueryHandler(IMapper mapper, IDbContextFactory contextFactory) : base(mapper, contextFactory) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelDeleteCommandHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelDeleteCommandHandler.cs index efa09de..00567df 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelDeleteCommandHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelDeleteCommandHandler.cs @@ -1,14 +1,14 @@ -using Microsoft.EntityFrameworkCore; +using AutoMapper; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; +using Microsoft.EntityFrameworkCore; namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelDeleteCommandHandler : DeleteCommandHandlerBase +public class TestModelDeleteCommandHandler + : DeleteCommandHandlerBase { - public TestModelDeleteCommandHandler(IDbContextFactory contextFactory) - : base(contextFactory) + public TestModelDeleteCommandHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) { } } diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelQueryHandler.cs index 2474b96..f3a08f1 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelQueryHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelQueryHandler.cs @@ -2,12 +2,10 @@ using Microsoft.EntityFrameworkCore; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; - namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelQueryHandler : SingleModelQueryHandlerBase +public class TestModelQueryHandler + : SingleModelQueryHandlerBase { public TestModelQueryHandler(IMapper mapper, IDbContextFactory contextFactory) : base(mapper, contextFactory) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCountQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCountQueryHandler.cs new file mode 100644 index 0000000..2100303 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCountQueryHandler.cs @@ -0,0 +1,11 @@ +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelStrongIdCountQueryHandler : CountQueryHandlerBase +{ + public TestModelStrongIdCountQueryHandler(IDbContextFactory contextFactory) + : base(contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCreateQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCreateQueryHandler.cs new file mode 100644 index 0000000..7276a05 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdCreateQueryHandler.cs @@ -0,0 +1,14 @@ +using AutoMapper; + +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelStrongIdCreateQueryHandler + : CreateQueryHandlerBase +{ + public TestModelStrongIdCreateQueryHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdDeleteCommandHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdDeleteCommandHandler.cs new file mode 100644 index 0000000..39e72ea --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdDeleteCommandHandler.cs @@ -0,0 +1,14 @@ +using AutoMapper; + +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelStrongIdDeleteCommandHandler + : DeleteCommandHandlerBase +{ + public TestModelStrongIdDeleteCommandHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdQueryHandler.cs new file mode 100644 index 0000000..b827ff4 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdQueryHandler.cs @@ -0,0 +1,14 @@ +using AutoMapper; + +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelStrongIdQueryHandler + : SingleModelQueryHandlerBase +{ + public TestModelStrongIdQueryHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdUpdateCommandHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdUpdateCommandHandler.cs new file mode 100644 index 0000000..91a9a3c --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelStrongIdUpdateCommandHandler.cs @@ -0,0 +1,14 @@ +using AutoMapper; + +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelStrongIdUpdateCommandHandler + : UpdateCommandHandlerBase +{ + public TestModelStrongIdUpdateCommandHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelUpdateCommandHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelUpdateCommandHandler.cs index 7f095d1..f6d66b0 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelUpdateCommandHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelUpdateCommandHandler.cs @@ -2,12 +2,10 @@ using Microsoft.EntityFrameworkCore; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; - namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelUpdateCommandHandler : UpdateCommandHandlerBase +public class TestModelUpdateCommandHandler + : UpdateCommandHandlerBase { public TestModelUpdateCommandHandler(IMapper mapper, IDbContextFactory contextFactory) : base(mapper, contextFactory) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsQueryHandler.cs index 9cc8259..491b777 100644 --- a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsQueryHandler.cs +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsQueryHandler.cs @@ -2,12 +2,10 @@ using Microsoft.EntityFrameworkCore; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Context; -using Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; - namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; -public class TestModelsQueryHandler : ListOfModelQueryHandlerBase +public class TestModelsQueryHandler + : ListOfModelQueryHandlerBase { public TestModelsQueryHandler(IMapper mapper, IDbContextFactory contextFactory) : base(mapper, contextFactory) diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsStrongIdQueryHandler.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsStrongIdQueryHandler.cs new file mode 100644 index 0000000..05b16c6 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Handlers/TestModelsStrongIdQueryHandler.cs @@ -0,0 +1,13 @@ +using AutoMapper; + +using Microsoft.EntityFrameworkCore; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Handlers; + +public class TestModelsStrongIdQueryHandler : ListOfModelQueryHandlerBase +{ + public TestModelsStrongIdQueryHandler(IMapper mapper, IDbContextFactory contextFactory) + : base(mapper, contextFactory) + { + } +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCountQuery.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCountQuery.cs new file mode 100644 index 0000000..c408c8b --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCountQuery.cs @@ -0,0 +1,6 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelStrongIdCountQuery + : CountQuery +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCreateQuery.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCreateQuery.cs new file mode 100644 index 0000000..79758f4 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdCreateQuery.cs @@ -0,0 +1,5 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelStrongIdCreateQuery : CreateQuery +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdDeleteCommand.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdDeleteCommand.cs new file mode 100644 index 0000000..4e9229b --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdDeleteCommand.cs @@ -0,0 +1,6 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelStrongIdDeleteCommand + : DeleteCommand +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdQuery.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdQuery.cs new file mode 100644 index 0000000..f555082 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdQuery.cs @@ -0,0 +1,6 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelStrongIdQuery + : SingleModelQuery +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdUpdateCommand.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdUpdateCommand.cs new file mode 100644 index 0000000..30faa64 --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelStrongIdUpdateCommand.cs @@ -0,0 +1,6 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelStrongIdUpdateCommand + : UpdateCommand +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelsStrongIdQuery.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelsStrongIdQuery.cs new file mode 100644 index 0000000..b42a21c --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/Queries/TestModelsStrongIdQuery.cs @@ -0,0 +1,5 @@ +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.Queries; + +public class TestModelsStrongIdQuery : ListOfModelQuery +{ +} diff --git a/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/TestModelStrongId.cs b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/TestModelStrongId.cs new file mode 100644 index 0000000..6e67e7d --- /dev/null +++ b/tests/Prodot.Patterns.Cqrs.EfCore.Tests/TestHelpers/TestModelStrongId.cs @@ -0,0 +1,12 @@ +using static Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers.TestModelStrongId; + +namespace Prodot.Patterns.Cqrs.EfCore.Tests.TestHelpers; + +public class TestModelStrongId : TestModelBase +{ + public string StringProperty { get; set; } = string.Empty; + + public record Identifier : Identifier + { + } +} From 5526ac64fcb2db2c2dd5f3b36a9de39f2273ba3a Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 18:41:28 +0200 Subject: [PATCH 5/8] Updated Github Actions to support beta versions --- .github/workflows/build-and-release.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 80f9a6e..d44d3db 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -16,13 +16,21 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v2 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Extend PackageVersion with build number in Directory.Build.props shell: pwsh run: | Write-Host New version uses build number $env:GITHUB_RUN_NUMBER $replacement="`$2.$($env:GITHUB_RUN_NUMBER)" (Get-Content Directory.Build.props) -replace '()(\d+\.\d+\.\d+)(\.\d+)()', $replacement | Out-File Directory.Build.props + - name: Extend PackageVersion with beta tag in Directory.Build.props + if: github.ref != 'refs/heads/main' + shell: pwsh + run: | + Write-Host Adding beta tag + $date = Get-Date -Format yyyyMMddHHmmss + $replacement="`$2-beta$($date)" + (Get-Content Directory.Build.props) -replace '()(\d+\.\d+\.\d+.\d+)()', $replacement | Out-File Directory.Build.props - name: Restore dependencies run: dotnet restore - name: Build @@ -37,7 +45,6 @@ jobs: name: packages path: '**/*.nupkg' - name: Push to nuget.org - if: github.ref == 'refs/heads/main' run: dotnet nuget push **/*.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_API_KEY} env: NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} From 701c79f402840325cc35ec16d2ebadea99207141 Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 18:44:01 +0200 Subject: [PATCH 6/8] Update Github Actions --- .github/workflows/build-and-release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index d44d3db..943d16f 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -17,6 +17,7 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: 7.0.x + include-prerelease: true - name: Extend PackageVersion with build number in Directory.Build.props shell: pwsh run: | From 06b0eb5f43c5b75dce318b6cd3cfbfdb0757e70d Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 18:45:19 +0200 Subject: [PATCH 7/8] Support preview dotnet --- .github/workflows/build-and-release.yml | 3 --- global.json | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 943d16f..a79904f 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -15,9 +15,6 @@ jobs: - uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v2 - with: - dotnet-version: 7.0.x - include-prerelease: true - name: Extend PackageVersion with build number in Directory.Build.props shell: pwsh run: | diff --git a/global.json b/global.json index 2ade5ca..839252e 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,7 @@ { "sdk": { - "version": "6.0.100", + "version": "7.0.100", "rollForward": "latestFeature", - "allowPrerelease": false + "allowPrerelease": true } } \ No newline at end of file From 175d96be4976a21a439dba52f9d750deb8f16c1a Mon Sep 17 00:00:00 2001 From: Tim Vinkemeier Date: Fri, 26 Aug 2022 20:24:08 +0200 Subject: [PATCH 8/8] actions --- .github/workflows/build-and-release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index a79904f..24d3659 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -15,6 +15,9 @@ jobs: - uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v2 + with: + dotnet-version: '7.0.x' + include-prerelease: true - name: Extend PackageVersion with build number in Directory.Build.props shell: pwsh run: |