Ejemplo n.º 1
0
        public void user_aggregate_create()
        {
            var fixture = new Fixture();

            fixture.Register <EntityId>(() => EntityId.From(fixture.Create <Guid>()));
            fixture.Register <Name>(() => Name.From(fixture.Create <string>()));
            fixture.Register <SocialSecurityId>(() => SocialSecurityId.From(fixture.Create <string>()));
            fixture.Register <Email>(() => Email.From(string.Format($"{fixture.Create<string>()}@teste.com")));

            fixture.Register <UserAggregationRoot>(
                () => UserAggregationRoot.CreateFrom(fixture.Create <Name>(),
                                                     fixture.Create <SocialSecurityId>(),
                                                     fixture.Create <Email>()));

            var agg = fixture.Create <UserAggregationRoot>();

            Assert.True(agg.ValidationResults.IsValid);
        }
Ejemplo n.º 2
0
        protected override async Task <CommandResult <Guid> > ExecuteCommand(AddUserCommand command, CancellationToken cancellationToken)
        {
            var agg = UserAggregationRoot.CreateFrom(command.Name);

            var isSucceed = false;
            var okId      = Guid.Empty;

            if (agg.IsValid)
            {
                _dbSession.Repository.Add(agg.GetChange());

                await _dbSession.SaveChangesAsync();

                agg.GetEvents().ToImmutableList()
                .ForEach(ev => Publisher.Publish(ev));

                isSucceed = true;
                okId      = agg.GetChange().Identity.Value;
            }

            return(await Task.FromResult(new CommandResult <Guid>(isSucceed, okId, agg.Failures)));
        }
Ejemplo n.º 3
0
        protected override CommandResult <Guid> ExecuteCommand(AddUserCommand command)
        {
            var agg = UserAggregationRoot.CreateFrom(
                Name.From(command.Name),
                SocialSecurityId.From(command.Cnpj),
                Email.From(command.CommercialEmail));

            var isSucceed = false;
            var okId      = Guid.Empty;

            if (agg.ValidationResults.IsValid)
            {
                _dbSession.Repository.Add(agg.GetChange());
                _dbSession.SaveChanges();

                agg.GetEvents().ToImmutableList()
                .ForEach(ev => Publisher.Publish(ev));

                isSucceed = true;
                okId      = agg.GetChange().Id.Value;
            }

            return(new CommandResult <Guid>(isSucceed, okId, agg.ValidationResults.Errors.ToImmutableList()));
        }