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 aggOld = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), Name.From("My name"), Email.From("*****@*****.**")); var currentstream = aggOld.GetChange(); var agg = EventStreamBusinessEntityAggregateRoot.ReconstructFrom(currentstream); var isSucceed = agg.ValidationResults.IsValid; var okId = Guid.Empty; if (isSucceed) { agg.UpdateName(EntityTestId.From(command.AggregateId), Name.From(command.Name)); isSucceed = agg.ValidationResults.IsValid; agg.GetEvents().ToImmutableList() .ForEach(ev => Publisher.Publish(ev)); okId = agg.GetChange().AggregationId.Value; } return(Task.FromResult(new CommandResult <Guid>(isSucceed, okId, agg.ValidationResults.Errors.ToImmutableList()))); }
protected override Task <CommandResult <Guid> > ExecuteCommand(UpdateEntityCommand command, CancellationToken cancellationToken) { var agg = _aggregateFactory.Create( EventStream <EntityTestId> .From(EntityTestId.Empty(), new AggregationName(), VersionId.Empty(), new ImmutableArray <IDomainEvent>()) ); var isSucceed = agg.IsValid; var okId = Guid.Empty; if (isSucceed) { agg.UpdateName(EntityTestId.From(command.AggregateId), Name.From(command.Name)); isSucceed = agg.IsValid; agg.GetEvents().ToImmutableList() .ForEach(ev => Publisher.Publish(ev)); okId = agg.GetChange().AggregationId.Value; } return(Task.FromResult(new CommandResult <Guid>(isSucceed, okId, agg.Failures))); }
public void Aggregate_reconstruct_a_valid() { var be = BusinessEntity.From(EntityTestId.GetNext(), Version.New()); var agg = BusinessEntityAggregateRoot.ReconstructFrom(be); Assert.True(agg.ValidationResults.IsValid); }
public void BusinessEntityNotIsNew() { var buUpdated = BusinessEntity.From(EntityTestId.GetNext(), VersionId.Next(VersionId.New())); var isNew = new BusinessEntityIsNew(); Assert.False(isNew.IsSatisfiedBy(buUpdated)); }
public void Aggregate_reconstruct_a_valid() { var be = BusinessEntity.From(EntityTestId.GetNext(), VersionId.New()); var factory = new ObjectBasedAggregateFactory(); var agg = factory.Create(be); Assert.True(agg.IsValid); }
public static BusinessEntity From(EntityTestId testId, Version version) { var bobj = new BusinessEntity(testId, version); var validator = new BusinessEntityValidator(); bobj.SetValidationResult(validator.Validate(bobj)); return(bobj); }
public void EntityId_create_an_invalid() { var fixture = new Fixture(); fixture.Register <EntityTestId>(() => EntityTestId.From(Guid.Empty)); var entityId = fixture.Create <EntityTestId>(); Assert.True(entityId.ValidationStatus.IsValid); }
public void EntityId_create_a_valid() { var fixture = new Fixture(); fixture.Register <EntityTestId>(() => EntityTestId.From(fixture.Create <Guid>())); var entityId = fixture.Create <EntityTestId>(); Assert.True(entityId.ValidationResults.IsValid); }
public void EntityId_create_an_empty() { var fixture = new Fixture(); fixture.Register <EntityTestId>(() => EntityTestId.Empty()); var entityId = fixture.Create <EntityTestId>(); Assert.False(entityId.ValidationResults.IsValid); }
public void Aggregate_EventBased_create_a_valid_one() { var fixture = new Fixture() .Customize(new AutoNSubstituteCustomization { ConfigureMembers = true }); var name = fixture.Create <Name>(); var email = fixture.Create <Email>(); var agg = EventStreamBusinessEntityAggregateRoot.Create(EntityTestId.GetNext(), name, email); var change = agg.GetChange(); Assert.Equal(1, change.Events.Count); Assert.Equal(nameof(EventStreamBusinessEntityAggregateRoot), change.Name.Value); }
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 isSucceed = false; var okId = Guid.Empty; //validation is not working nice yet if (agg.ValidationResults.IsValid) { isSucceed = true; agg.GetEvents().ToImmutableList() .ForEach(ev => Publisher.Publish(ev)); okId = agg.GetChange().AggregationId.Value; } return(Task.FromResult(new CommandResult <Guid>(isSucceed, okId, agg.ValidationResults.Errors.ToImmutableList()))); }
private EntityAddedEvent(EntityTestId clientId, VersionId version) : base(DateTime.Now, version) { Id = clientId; }
public void EntityTestIdCreateFrom() { var entity = EntityTestId.From(_id); }
public void EntityId_create_an_empty() { var entityId = EntityTestId.Empty(); Assert.True(entityId.ValidationStatus.IsValid); }
public static BusinessEntity New() { return(From(EntityTestId.GetNext(), Version.New())); }
public void EntityTestIdCreateEmpty() { var entity = EntityTestId.Empty(); }
private BusinessEntity(EntityTestId businessTestId, Version version) { BusinessTestId = businessTestId; Version = version; }