protected override ExecutionResult ExecuteCommand(RemoveUserCommand command) { var user = _userDb.Repository.Get(EntityId.From(command.Id)); var agg = UserAggregationRoot.ReconstructFrom(user); var isSucceed = false; if (agg.ValidationResults.IsValid) { agg.Remove(); _userDb.Repository.Remove(agg.GetChange()); _userDb.SaveChanges(); agg.GetEvents().ToImmutableList().ForEach(ev => Publisher.Publish(ev)); isSucceed = true; } return(new ExecutionResult(isSucceed, agg.ValidationResults.Errors.ToImmutableList())); }
public void user_aggregate_reconstruct() { var fixture = new Fixture(); fixture.Register <EntityId>(() => EntityId.From(fixture.Create <Guid>())); fixture.Register <Version>(() => Version.From(fixture.Create <int>())); 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 <User>(() => User.From(fixture.Create <EntityId>(), fixture.Create <Name>(), fixture.Create <SocialSecurityId>(), fixture.Create <Email>(), fixture.Create <Version>())); fixture.Register <UserAggregationRoot>( () => UserAggregationRoot.ReconstructFrom(fixture.Create <User>())); var agg = fixture.Create <UserAggregationRoot>(); Assert.True(agg.ValidationResults.IsValid); }