Skip to content

Commit

Permalink
aggregate factory based classes
Browse files Browse the repository at this point in the history
  • Loading branch information
drr00t committed Aug 12, 2021
1 parent 9c397a5 commit d1eb68e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
15 changes: 9 additions & 6 deletions tests/DFlow.Tests/Domain/AggregatesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -41,10 +43,10 @@ public void Aggregate_EventBased_create_a_valid()
fixture.Register<Name>(()=> Name.From(fixture.Create<String>()));
fixture.Register<Email>(()=> Email.From("[email protected]"));

var name = fixture.Create<Name>();
var email = fixture.Create<Email>();

var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email);
var addEntity = fixture.Create<AddEntityCommand>();

var factory = new EventBasedAggregateFactory();
var agg = factory.Create(addEntity);
Assert.Equal(nameof(EventStreamBusinessEntityAggregateRoot),agg.GetChange().Name.Value);
Assert.True(agg.IsValid);
}
Expand All @@ -62,7 +64,8 @@ public void Aggregate_EventBased_valid_Entity_create()
{
var fixture = new Fixture()
.Customize(new AutoNSubstituteCustomization{ ConfigureMembers = true });

fixture.Register<string>(()=> "[email protected]");

var name = fixture.Create<string>();
var email = fixture.Create<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,15 +34,18 @@ namespace DFlow.Tests.Supporting
{
public sealed class AddEntityEventBasedCommandHandler : CommandHandler<AddEntityCommand, CommandResult<Guid>>
{
public AddEntityEventBasedCommandHandler(IDomainEventBus publisher)
private IAggregateFactory<EventStreamBusinessEntityAggregateRoot, AddEntityCommand> _aggregateFactory;

public AddEntityEventBasedCommandHandler(IDomainEventBus publisher,
IAggregateFactory<EventStreamBusinessEntityAggregateRoot, AddEntityCommand> aggregateFactory)
:base(publisher)
{
_aggregateFactory = aggregateFactory;
}

protected override Task<CommandResult<Guid>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -33,28 +32,23 @@ namespace DFlow.Tests.Supporting
{
public sealed class UpdateEntityEventBasedCommandHandler : CommandHandler<UpdateEntityCommand, CommandResult<Guid>>
{
private IAggregateReconstructFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>>
_aggregationRoot;
private IAggregateFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>>
_aggregateFactory;

public UpdateEntityEventBasedCommandHandler(IDomainEventBus publisher,
IAggregateReconstructFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>> aggregateFactory)
IAggregateFactory<EventStreamBusinessEntityAggregateRoot, EventStream<EntityTestId>> aggregateFactory)
:base(publisher)
{
_aggregationRoot = aggregateFactory;
_aggregateFactory = aggregateFactory;
}

protected override Task<CommandResult<Guid>> 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("[email protected]"));

// var currentstream = aggOld.GetChange();
// var agg = EventStreamBusinessEntityAggregateRoot.Reconstruct(currentstream);

var agg = _aggregationRoot
.ReconstructFrom(EventStream<EntityTestId>.From(EntityTestId.Empty(),
new AggregationName(), VersionId.Empty(), new ImmutableArray<IDomainEvent>()));
var agg = _aggregateFactory.Create(
EventStream<EntityTestId>.From(EntityTestId.Empty(),
new AggregationName(),
VersionId.Empty(), new ImmutableArray<IDomainEvent>())
);
var isSucceed = agg.IsValid;
var okId = Guid.Empty;

Expand Down

0 comments on commit d1eb68e

Please sign in to comment.