Example #1
0
        public async Task CanDepositCashInToValidAccount()
        {
            decimal  depositeAmount = 5000;
            DateTime depositeDate   = System.DateTime.Now;
            var      accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmd = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var ev = new CashDeposited(cmd)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated).When(cmd).Then(ev)
                );
        }
        public async Task CanDepositCash()
        {
            Clock.SetCurrent(new LocalDateTime(2018, 1, 1, 9, 0));

            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "NNN"
            };

            var cmd = new DepositCash
            {
                AccountId = AccountId,
                Amount    = 350
            };

            var ev = new CashDeposited(cmd)
            {
                AccountId   = AccountId,
                Amount      = cmd.Amount,
                DepositedAt = Clock.Current
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Then(ev)
                );
        }
Example #3
0
        public async Task CannotDepositCashIntoInvalidAccount()
        {
            var cmd = new DepositCash
            {
                AccountId = _accountId,
                Amount    = Convert.ToDecimal(100m)
            };

            await _runner.Run(
                def => def.Given().When(cmd).Throws(new ValidationException("No account with this ID exists"))
                );
        }
Example #4
0
        public async Task ShouldUnblockOnCashDepositWhenAccountIsAlreadyBlocked()
        {
            decimal depositeAmount = 5000;
            decimal overdraftLimit = 1000;
            decimal withdrawAmount = 7000;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };

            var evtCashDeposited = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evOverdraftLimitConfigured = new OverdraftLimitConfigured(CorrelatedMessage.NewRoot())
            {
                AccountId      = _accountId,
                OverdraftLimit = overdraftLimit
            };

            var evtCashWithdrawn = new CashWithdrawn(CorrelatedMessage.NewRoot())
            {
                AccountId      = _accountId,
                WithdrawAmount = withdrawAmount
            };

            var evAccountBlocked = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = withdrawAmount
            };

            var cmd = new DepositCash()
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evAccountUnblocked = new AccountUnblocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = depositeAmount
            };

            //Yet to decide how to tackle this.
            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited, evOverdraftLimitConfigured, evtCashWithdrawn, evAccountBlocked).When(cmd).Then(evAccountUnblocked)
                );
        }
Example #5
0
        public async Task CanWithdrawCashWithOverdraftLimitFromValidAccount()
        {
            decimal depositeAmount = 5000;
            decimal overdraftLimit = 2000;
            decimal withdrawAmount = 7000;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmdDepositCash = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evtCashDeposited = new CashDeposited(cmdDepositCash)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var cmdConfigureOverdraftLimit = new ConfigureOverdraftLimit
            {
                AccountId      = _accountId,
                OverdraftLimit = overdraftLimit
            };

            var evOverdraftLimitConfigured = new OverdraftLimitConfigured(cmdConfigureOverdraftLimit)
            {
                AccountId      = cmdConfigureOverdraftLimit.AccountId,
                OverdraftLimit = cmdConfigureOverdraftLimit.OverdraftLimit
            };


            var cmd = new WithdrawCash()
            {
                AccountId      = _accountId,
                WithdrawAmount = withdrawAmount
            };

            var ev = new CashWithdrawn(cmd)
            {
                AccountId      = _accountId,
                WithdrawAmount = withdrawAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited, evOverdraftLimitConfigured).When(cmd).Then(ev)
                );
        }
Example #6
0
        public async Task CashDepositShouldThrowExceptionWhenAccountIsNotPresent()
        {
            decimal  depositeAmount = 5000;
            DateTime depositeDate   = System.DateTime.Now;

            var cmd = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            await _runner.Run(
                def => def.Given().When(cmd).Throws(new ValidationException("No account with this ID exists"))
                );
        }
Example #7
0
        public async Task CannotDepositCashIfAccountDoesNotExist()
        {
            var cmd = new DepositCash()
            {
                AccountId = _accountId,
                Amount    = 1000
            };

            await _runner.Run(
                def => def
                .Given()
                .When(cmd)
                .Throws(new SystemException("The cash cannot be deposited to the inexistent account."))
                );
        }
Example #8
0
        public async Task CannotWithdrawCashOutsideBalanceAndWithOverdraftLimit()
        {
            decimal depositeAmount = 5000;
            decimal overdraftLimit = 1000;
            decimal withdrawAmount = 7000;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmdDepositCash = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evtCashDeposited = new CashDeposited(cmdDepositCash)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evOverdraftLimitConfigured = new OverdraftLimitConfigured(CorrelatedMessage.NewRoot())
            {
                AccountId      = _accountId,
                OverdraftLimit = overdraftLimit
            };

            var cmd = new WithdrawCash()
            {
                AccountId      = _accountId,
                WithdrawAmount = withdrawAmount
            };

            var evAccountBlocked = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = withdrawAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited, evOverdraftLimitConfigured).When(cmd).Then(evAccountBlocked)
                );
        }
Example #9
0
        public async Task CannotDepositCashWithNonPositiveAmount(double amount)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

            var cmd = new DepositCash
            {
                AccountId = _accountId,
                Amount    = Convert.ToDecimal(amount)
            };

            await _runner.Run(
                def => def.Given(created).When(cmd).Throws(new ValidationException("Cash deposited must be a positive amount"))
                );
        }
        public CommandResponse Handle(DepositCash command)
        {
            try
            {
                if (!_repository.TryGetById <Account>(command.AccountId, out var account))
                {
                    throw new InvalidOperationException("Account not exisit");
                }

                account.DepositCash(command.AccountId, command.Amount, _clock, command);

                _repository.Save(account);
                return(command.Succeed());
            }
            catch (Exception e)
            {
                return(command.Fail(e));
            }
        }
Example #11
0
        public async Task CashDepositAmountCannotBeNegative()
        {
            decimal  depositeAmount = -5000;
            DateTime depositeDate   = System.DateTime.Now;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };

            var cmd = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            await _runner.Run(
                def => def.Given(accountCreated).When(cmd).Throws(new ValidationException("Cash deposit amount cannot be negative"))
                );
        }
Example #12
0
        public async Task CannotDepositCash(decimal amount)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var cmd = new DepositCash()
            {
                AccountId = _accountId,
                Amount    = amount
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv)
                .When(cmd)
                .Throws(new SystemException("The deposited cash amount should be greater than 0."))
                );
        }
        public async Task CanTransferFundFromValidAccount()
        {
            decimal WireTransferFund = 5000;
            decimal depositeAmount   = 5000;

            var accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmdDepositCash = new DepositCash
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };

            var evtCashDeposited = new CashDeposited(cmdDepositCash)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount
            };
            var cmd = new TransferWireFund()
            {
                AccountId = _accountId,
                WireFund  = WireTransferFund
            };

            var ev = new WireFundTransferred(cmd)
            {
                AccountId = _accountId,
                WireFund  = WireTransferFund
            };

            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited).When(cmd).Then(ev)
                );
        }
Example #14
0
        public async Task CanDepositCash(double amount)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

            var cmd = new DepositCash
            {
                AccountId = _accountId,
                Amount    = Convert.ToDecimal(amount)
            };

            var limitSet = new CashDeposited(cmd)
            {
                AccountId = _accountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def.Given(created).When(cmd).Then(limitSet)
                );
        }
Example #15
0
        public async Task CanDepositCash(decimal amount)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var cmd = new DepositCash()
            {
                AccountId = _accountId,
                Amount    = amount
            };

            var amountSetEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = cmd.AccountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def.Given(accCreatedEv).When(cmd).Then(amountSetEv)
                );
        }