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));
        }
Exemple #3
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())));
        }
Exemple #4
0
        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 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())));
        }
Exemple #7
0
 public static BusinessEntity New()
 {
     return(From(EntityTestId.GetNext(), Version.New()));
 }