Exemplo n.º 1
0
        public void WhenBalanceAmountIsSufficient_ShouldAllowWithdrawingMoney()
        {
            _balanceMock.Setup(b => b.Amount).Returns(20.50m);
            var moneyToWithdraw = 10.99m;

            var result = _target.CanWithdrawMoney(_balanceMock.Object, moneyToWithdraw);

            Assert.IsTrue(result);
        }
Exemplo n.º 2
0
        protected async override Task Handle(WithdrawMoneyCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            var account = await _accountRepository.GetById(command.AccountId);

            if (_statusValidator.IsUnverifiedOrClosed(account.Status) ||
                !_balanceValidator.CanWithdrawMoney(account.Balance, command.MoneyAmount))
            {
                throw new ForbiddenCommandException();
            }
            account.Balance.SubtractMoney(command.MoneyAmount);

            if (_statusValidator.IsFrozen(account.Status))
            {
                account.Status.ChangeStatus(AccountStatusValues.Verified);
            }
        }