Exemplo n.º 1
0
        public async Task CannnotWithdrawCashIfOverdrafdIsExceeded(decimal deposit, decimal overdraft, decimal withdraw)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var overdraftSetEv = new OverdraftLimitSet(CorrelatedMessage.NewRoot())
            {
                AccountId      = _accountId,
                OverdraftLimit = overdraft
            };

            var cmd = new WithdrawCash()
            {
                AccountId = _accountId,
                Amount    = withdraw
            };

            var withdrawalFailedEv = new WithdrawalFailed(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = cmd.Amount
            };

            var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, depositSetEv, overdraftSetEv)
                .When(cmd)
                .Then(withdrawalFailedEv, accBlockedEv));
        }
Exemplo n.º 2
0
        public async Task CannnotWithdrawCashFromBlockedAccount()
        {
            var deposit  = 1000m;
            var withdraw = 500m;

            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

            var depositSetEv = new CashDeposited(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = deposit
            };

            var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId
            };

            var cmd = new WithdrawCash()
            {
                AccountId = _accountId,
                Amount    = withdraw
            };

            var transferFailedEv = new WithdrawalFailed(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, depositSetEv, accBlockedEv)
                .When(cmd)
                .Then(transferFailedEv));
        }