From d1eb68edc1643d8379e2b2ce4f7bbe3c8313f74d Mon Sep 17 00:00:00 2001 From: drr00t Date: Wed, 11 Aug 2021 21:34:17 -0300 Subject: [PATCH] aggregate factory based classes --- tests/DFlow.Tests/Domain/AggregatesTests.cs | 15 +++++++----- .../AddEntityEventBasedCommandHandler.cs | 11 ++++++--- .../UpdateEntityEventBasedCommandHandler.cs | 24 +++++++------------ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/tests/DFlow.Tests/Domain/AggregatesTests.cs b/tests/DFlow.Tests/Domain/AggregatesTests.cs index 5411974..35e7019 100644 --- a/tests/DFlow.Tests/Domain/AggregatesTests.cs +++ b/tests/DFlow.Tests/Domain/AggregatesTests.cs @@ -28,7 +28,9 @@ public void Aggregate_create_a_valid() public void Aggregate_reconstruct_a_valid() { var be = BusinessEntity.From(EntityTestId.GetNext(), VersionId.New()); - var agg = BusinessEntityAggregateRoot.ReconstructFrom(be); + + var factory = new ObjectBasedAggregateFactory(); + var agg = factory.Create(be); Assert.True(agg.IsValid); } @@ -41,10 +43,10 @@ public void Aggregate_EventBased_create_a_valid() fixture.Register(()=> Name.From(fixture.Create())); fixture.Register(()=> Email.From("email@de.com")); - var name = fixture.Create(); - var email = fixture.Create(); - - var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email); + var addEntity = fixture.Create(); + + var factory = new EventBasedAggregateFactory(); + var agg = factory.Create(addEntity); Assert.Equal(nameof(EventStreamBusinessEntityAggregateRoot),agg.GetChange().Name.Value); Assert.True(agg.IsValid); } @@ -62,7 +64,8 @@ public void Aggregate_EventBased_valid_Entity_create() { var fixture = new Fixture() .Customize(new AutoNSubstituteCustomization{ ConfigureMembers = true }); - + fixture.Register(()=> "email@de.com"); + var name = fixture.Create(); var email = fixture.Create(); diff --git a/tests/DFlow.Tests/Supporting/AddEntityEventBasedCommandHandler.cs b/tests/DFlow.Tests/Supporting/AddEntityEventBasedCommandHandler.cs index 1e0588d..70fafda 100644 --- a/tests/DFlow.Tests/Supporting/AddEntityEventBasedCommandHandler.cs +++ b/tests/DFlow.Tests/Supporting/AddEntityEventBasedCommandHandler.cs @@ -23,6 +23,8 @@ using System.Threading.Tasks; using DFlow.Business.Cqrs; using DFlow.Business.Cqrs.CommandHandlers; +using DFlow.Domain.Aggregates; +using DFlow.Domain.BusinessObjects; using DFlow.Domain.Events; using DFlow.Tests.Supporting.DomainObjects; using DFlow.Tests.Supporting.DomainObjects.Commands; @@ -32,15 +34,18 @@ namespace DFlow.Tests.Supporting { public sealed class AddEntityEventBasedCommandHandler : CommandHandler> { - public AddEntityEventBasedCommandHandler(IDomainEventBus publisher) + private IAggregateFactory _aggregateFactory; + + public AddEntityEventBasedCommandHandler(IDomainEventBus publisher, + IAggregateFactory aggregateFactory) :base(publisher) { + _aggregateFactory = aggregateFactory; } protected override Task> ExecuteCommand(AddEntityCommand command, CancellationToken cancellationToken) { - var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), - Name.From(command.Name), Email.From(command.Mail)); + var agg = _aggregateFactory.Create(command); var isSucceed = false; var okId = Guid.Empty; diff --git a/tests/DFlow.Tests/Supporting/UpdateEntityEventBasedCommandHandler.cs b/tests/DFlow.Tests/Supporting/UpdateEntityEventBasedCommandHandler.cs index 0553298..99b3707 100644 --- a/tests/DFlow.Tests/Supporting/UpdateEntityEventBasedCommandHandler.cs +++ b/tests/DFlow.Tests/Supporting/UpdateEntityEventBasedCommandHandler.cs @@ -17,7 +17,6 @@ // using System; -using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; @@ -33,28 +32,23 @@ namespace DFlow.Tests.Supporting { public sealed class UpdateEntityEventBasedCommandHandler : CommandHandler> { - private IAggregateReconstructFactory> - _aggregationRoot; + private IAggregateFactory> + _aggregateFactory; public UpdateEntityEventBasedCommandHandler(IDomainEventBus publisher, - IAggregateReconstructFactory> aggregateFactory) + IAggregateFactory> aggregateFactory) :base(publisher) { - _aggregationRoot = aggregateFactory; + _aggregateFactory = aggregateFactory; } protected override Task> ExecuteCommand(UpdateEntityCommand command, CancellationToken cancellationToken) { - // FIXME: remove this after clear my mind, i do need port the persistence event sourcing infrastructure now :) - // var aggNew = _aggregationRoot - // .ReconstructFrom(EntityTestId.GetNext(), Name.From("My name"), Email.From("my@mail.com")); - - // var currentstream = aggOld.GetChange(); - // var agg = EventStreamBusinessEntityAggregateRoot.Reconstruct(currentstream); - - var agg = _aggregationRoot - .ReconstructFrom(EventStream.From(EntityTestId.Empty(), - new AggregationName(), VersionId.Empty(), new ImmutableArray())); + var agg = _aggregateFactory.Create( + EventStream.From(EntityTestId.Empty(), + new AggregationName(), + VersionId.Empty(), new ImmutableArray()) + ); var isSucceed = agg.IsValid; var okId = Guid.Empty;