public void given_new_account_should_show_balance_and_beginning_if_deposit_made()
        {
            // assemble
            const decimal AMOUNT_TO_DEPOSIT = 10;

            var newAgg = AccountAggregate.StartNewAccount();

            // apply
            newAgg.Deposit(AMOUNT_TO_DEPOSIT);

            // assert
            var changes = newAgg.GetUncommittedChanges();

            Assert.Equal(2, changes.Count());
            Assert.Collection(changes,
                              (e) =>
            {
                Assert.IsType <AccountCreated>(e);
            },
                              (e) =>
            {
                Assert.IsType <AmountDeposited>(e);
                var @event = (AmountDeposited)e;
                Assert.Equal(AMOUNT_TO_DEPOSIT, @event.Amount);
            });

            Assert.Equal(AMOUNT_TO_DEPOSIT, newAgg.StartingBalance);
            Assert.Equal(AMOUNT_TO_DEPOSIT, newAgg.CurrentAccountBalance);
        }
示例#2
0
        public async Task HandleAsync(AggregateInOutOfSyncState @event)
        {
            AccountAggregate aggregate = await _aggregateStore.GetByIdOrDefaultAsync <AccountAggregate>(@event.AggregateId);

            var doesExist = await _map.ProbeAsync(aggregate);

            if (doesExist && aggregate.IsNull())
            {
                await _map.DeleteAsync(new AccountAggregate()
                {
                    Id = @event.AggregateId
                });

                return;
            }

            if (!doesExist && aggregate.Version >= 0)
            {
                await _map.CreateAsync(aggregate);
            }

            if (@event.Version < aggregate.Version)
            {
                return;
            }

            if (doesExist && aggregate.Version >= 0)
            {
                await _map.UpdateAsync(aggregate);
            }
        }
示例#3
0
文件: ResetSetup.cs 项目: FWTL/Auth
            public async Task <IAggregateRoot> ExecuteAsync(Command command)
            {
                AccountAggregate account = await _aggregateStore.GetByIdAsync <AccountAggregate>(command.AccountId);

                account.Reset();
                return(account);
            }
示例#4
0
        public void Handle(CreateAccountCommand command)
        {
            var accountOwner = _accountOwnerService.GetAccountOwner(command.OwnerId);
            var account      = new AccountAggregate(accountOwner);

            _accountAggregateRepository.Save(account);
        }
示例#5
0
        public async Task <IActionResult> Post(Guid AccountId, OpenAccount openAccount)
        {
            var account = new AccountAggregate(AccountId);

            await _accountRepository.Load(account);

            account.Issue(openAccount);
        }
示例#6
0
        private void Commit(AccountAggregate aggregate)
        {
            var changes = _repository.Save(aggregate);

            foreach (var change in changes)
            {
                _publisher.Publish(change);
            }
        }
示例#7
0
        public void TestEmptyAccount()
        {
            var accountAggregate = new AccountAggregate();

            accountAggregate.From(new List <IEvent>());

            Assert.Equal(Guid.Empty, accountAggregate.Guid);
            Assert.Null(accountAggregate.Name);
        }
示例#8
0
        public void Handle(OpenAccount c)
        {
            var aggregate = new AccountAggregate {
                AggregateIdentifier = c.AggregateIdentifier
            };

            aggregate.OpenAccount(c.Owner, c.Code);
            Commit(aggregate);
        }
示例#9
0
        public Account GetById(Guid accountId)
        {
            AccountAggregate account = new AccountAggregate();

            try
            {
                account = _repo.GetById <AccountAggregate>(accountId);
            }
            catch (Exception)
            {}

            return(account.ToAccount());
        }
示例#10
0
文件: SendCode.cs 项目: FWTL/Auth
            public async Task <IAggregateRoot> ExecuteAsync(Command command)
            {
                AccountAggregate account = await _aggregateStore.GetByIdAsync <AccountAggregate>(command.AccountId);

                ResponseWrapper response = await _telegramClient.UserService.PhoneLoginAsync(account.Id.ToString(), account.ExternalAccountId);

                if (response.IsSuccess)
                {
                    account.SendCode();
                    return(account);
                }

                account.FailSetup(response.Errors.Select(e => e.Message));
                return(account);
            }
示例#11
0
            public async Task <IAggregateRoot> ExecuteAsync(Command command)
            {
                AccountAggregate account = await _aggregateStore.GetByIdAsync <AccountAggregate>(command.AccountId);

                var response = await _telegramClient.SystemService.AddSessionAsync(account.Id.ToString());

                if (response.IsSuccess)
                {
                    account.CreateSession();
                    return(account);
                }

                account.FailSetup(response.Errors.Select(e => e.Message));
                return(account);
            }
示例#12
0
        public void TestCreateAccountEvent()
        {
            var accountGuid        = Guid.NewGuid();
            var accountName        = "TestName";
            var createAccountEvent = new CreateAccountEvent {
                EventGuid   = Guid.NewGuid(),
                ItemGuid    = accountGuid,
                AccountName = accountName
            };
            var accountAggregate = new AccountAggregate();

            accountAggregate.From(new List <IEvent>()
            {
                createAccountEvent
            });

            Assert.Equal(accountGuid, accountAggregate.Guid);
            Assert.Equal(accountName, accountAggregate.Name);
        }
示例#13
0
        public void TestCommandHandleAccountGuidExistsInDb()
        {
            var accountName        = "testName";
            var accountServiceMock = new Mock <IAggregateService <AccountAggregate> >();
            var counter            = 0;
            var accountGuid        = Guid.Empty;

            accountServiceMock.Setup(m => m.Load(It.IsAny <Guid>())).Returns((Guid guid) =>
            {
                var aggregate = new AccountAggregate();
                if (counter > 3)
                {
                    accountGuid = guid;
                    return(aggregate);
                }
                counter++;
                aggregate.Apply(new CreateAccountEvent {
                    ItemGuid = guid
                });
                return(aggregate);
            });
            var eventPublisherMock = new Mock <IEventPublisher>();

            eventPublisherMock.Setup(m => m.Publish(It.IsAny <CreateAccountEvent>())).Callback((IEvent e) =>
            {
                Assert.NotEqual(Guid.Empty, accountGuid);
                Assert.IsType <CreateAccountEvent>(e);
                CreateAccountEvent createAccountEvent = (CreateAccountEvent)e;
                Assert.Equal(accountName, createAccountEvent.AccountName);
                Assert.Equal(accountGuid, createAccountEvent.ItemGuid);
                Assert.Equal(Guid.Empty, createAccountEvent.EventGuid);
            });
            var      commandHandler = new CreateAccountCommandHandler(accountServiceMock.Object, eventPublisherMock.Object);
            ICommand command        = new CreateAccountCommand {
                Name = accountName
            };

            commandHandler.Handle((CreateAccountCommand)command);

            accountServiceMock.VerifyAll();
            eventPublisherMock.VerifyAll();
        }
示例#14
0
            public async Task <IAggregateRoot> ExecuteAsync(Command command)
            {
                AccountAggregate account = await _aggregateStore.GetByIdAsync <AccountAggregate>(command.AccountId);

                if (account.State != AccountAggregate.AccountState.WaitForCode)
                {
                    throw new ValidationException("Not waiting for a code");
                }

                ResponseWrapper response = await _telegramClient.UserService.CompletePhoneLoginAsync(account.Id.ToString(), command.Code);

                if (response.IsSuccess)
                {
                    account.Verify();
                    return(account);
                }

                account.FailSetup(response.Errors.Select(e => e.Message));
                return(account);
            }
示例#15
0
        public static async Task <AccountAggregate> GetOrCreateAccount(this ISession session, Guid accountId, CancellationToken token)
        {
            try
            {
                var account = await session.Get <AccountAggregate>(accountId, cancellationToken : token);

                return(account);
            }
            catch (AggregateNotFoundException ex)
            {
                var account = AccountAggregate.OpenNewAccount(accountId);
                await session.Add(account, token);

                return(account);
            }
            catch
            {
                throw;
            }
        }
示例#16
0
        public void TestAddDepositToAccountEvent()
        {
            var accountGuid = Guid.NewGuid();
            var depositId   = Guid.NewGuid();
            var eventGuid   = Guid.NewGuid();
            var addDepositToAccountEvent = new AddDepositToAccountEvent {
                EventGuid = eventGuid,
                ItemGuid  = accountGuid,
                DepositId = depositId
            };
            var accountAggregate = new AccountAggregate();

            accountAggregate.From(new List <IEvent>()
            {
                addDepositToAccountEvent
            });

            Assert.Single(accountAggregate.DepositsGuides);
            Assert.Equal(depositId, accountAggregate.DepositsGuides.First());
        }
        public void given_new_account_should_have_create_event_with_non_empty_id()
        {
            // assemble

            // apply
            var newAgg = AccountAggregate.StartNewAccount();

            // assert
            var changes = newAgg.GetUncommittedChanges();

            Assert.Single(changes);
            Assert.Collection(changes, (e) =>
            {
                Assert.IsType <AccountCreated>(e);
                var @event = (AccountCreated)e;
                Assert.Equal(0, @event.DepositAmount);
            });

            Assert.NotEqual(Guid.Empty, newAgg.Id);
            Assert.Equal(0, newAgg.StartingBalance);
        }
示例#18
0
        public static AccountRecordResult ToResult(AccountAggregate account, IEnumerable <AccountAccessConsentPermission> permissions)
        {
            var result = new AccountRecordResult
            {
                AccountId            = account.AggregateId,
                AccountSubType       = account.AccountSubType?.Name,
                AccountType          = account.AccountType?.Name,
                Currency             = account.Currency,
                Description          = account.Description,
                MaturityDate         = account.MaturityDate,
                Nickname             = account.Nickname,
                OpeningDate          = account.OpeningDate,
                StatusUpdateDateTime = account.StatusUpdateDateTime,
                SwitchStatus         = account.SwitchStatus?.Name
            };

            if (permissions.Contains(AccountAccessConsentPermission.ReadAccountsDetail))
            {
                result.Servicer = account.Servicer == null ? null : ServicerResult.ToResult(account.Servicer);
                result.Accounts = account.Accounts.Select(a => CashAccountResult.ToResult(a)).ToList();
            }

            return(result);
        }
示例#19
0
 public void Save(AccountAggregate accountAggregate)
 {
     session.Save(accountAggregate);
 }
示例#20
0
 public async Task Handle(CreateAccountCommand command)
 {
     var accountNumber = accountNumberGenerator.GenerateNumber(command.OwnerId, command.AccountType);
     var account       = new AccountAggregate(command.OwnerId, command.AccountType, accountNumber);
     await accountRepository.Save(account);
 }
示例#21
0
 public Task Save(AccountAggregate accountAggregate)
 {
     throw new NotImplementedException();
 }