Beispiel #1
0
        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())));
        }
Beispiel #2
0
        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())));
        }