コード例 #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())));
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        public void Aggregate_reconstruct_a_valid()
        {
            var be  = BusinessEntity.From(EntityTestId.GetNext(), Version.New());
            var agg = BusinessEntityAggregateRoot.ReconstructFrom(be);

            Assert.True(agg.ValidationResults.IsValid);
        }
コード例 #4
0
ファイル: SpecificationTests.cs プロジェクト: zamabraga/dflow
        public void BusinessEntityNotIsNew()
        {
            var buUpdated = BusinessEntity.From(EntityTestId.GetNext(), VersionId.Next(VersionId.New()));
            var isNew     = new BusinessEntityIsNew();

            Assert.False(isNew.IsSatisfiedBy(buUpdated));
        }
コード例 #5
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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
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);
        }
コード例 #11
0
        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())));
        }
コード例 #12
0
ファイル: EntityAddedEvent.cs プロジェクト: zamabraga/dflow
 private EntityAddedEvent(EntityTestId clientId, VersionId version)
     : base(DateTime.Now, version)
 {
     Id = clientId;
 }
コード例 #13
0
 public void EntityTestIdCreateFrom()
 {
     var entity = EntityTestId.From(_id);
 }
コード例 #14
0
        public void EntityId_create_an_empty()
        {
            var entityId = EntityTestId.Empty();

            Assert.True(entityId.ValidationStatus.IsValid);
        }
コード例 #15
0
 public static BusinessEntity New()
 {
     return(From(EntityTestId.GetNext(), Version.New()));
 }
コード例 #16
0
 public void EntityTestIdCreateEmpty()
 {
     var entity = EntityTestId.Empty();
 }
コード例 #17
0
 private BusinessEntity(EntityTestId businessTestId, Version version)
 {
     BusinessTestId = businessTestId;
     Version        = version;
 }