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); }
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); } }
public async Task <IAggregateRoot> ExecuteAsync(Command command) { AccountAggregate account = await _aggregateStore.GetByIdAsync <AccountAggregate>(command.AccountId); account.Reset(); return(account); }
public void Handle(CreateAccountCommand command) { var accountOwner = _accountOwnerService.GetAccountOwner(command.OwnerId); var account = new AccountAggregate(accountOwner); _accountAggregateRepository.Save(account); }
public async Task <IActionResult> Post(Guid AccountId, OpenAccount openAccount) { var account = new AccountAggregate(AccountId); await _accountRepository.Load(account); account.Issue(openAccount); }
private void Commit(AccountAggregate aggregate) { var changes = _repository.Save(aggregate); foreach (var change in changes) { _publisher.Publish(change); } }
public void TestEmptyAccount() { var accountAggregate = new AccountAggregate(); accountAggregate.From(new List <IEvent>()); Assert.Equal(Guid.Empty, accountAggregate.Guid); Assert.Null(accountAggregate.Name); }
public void Handle(OpenAccount c) { var aggregate = new AccountAggregate { AggregateIdentifier = c.AggregateIdentifier }; aggregate.OpenAccount(c.Owner, c.Code); Commit(aggregate); }
public Account GetById(Guid accountId) { AccountAggregate account = new AccountAggregate(); try { account = _repo.GetById <AccountAggregate>(accountId); } catch (Exception) {} return(account.ToAccount()); }
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); }
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); }
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); }
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(); }
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); }
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; } }
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); }
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); }
public void Save(AccountAggregate accountAggregate) { session.Save(accountAggregate); }
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); }
public Task Save(AccountAggregate accountAggregate) { throw new NotImplementedException(); }