public async Task CanWithdrawCash()
        {
            Clock.SetCurrent(new LocalDateTime(2018, 1, 1, 9, 0));

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

            var cashDeposited = new CashDeposited(accountCreated)
            {
                AccountId   = AccountId,
                Amount      = 350,
                DepositedAt = Clock.Current
            };

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

            var ev = new CashWithdrawn(cmd)
            {
                AccountId   = AccountId,
                Amount      = 200,
                WithdrawnAt = Clock.Current
            };

            await Runner.Run(
                def => def.Given(accountCreated, cashDeposited).When(cmd).Then(ev)
                );
        }
Exemple #2
0
        public async Task CanWithdrawCash(decimal deposit, decimal withdraw)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

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

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

            var withdrawnEv = new CashWithdrawn(cmd)
            {
                AccountId = _accountId,
                Amount    = cmd.Amount
            };

            await _runner.Run(
                def => def
                .Given(accCreatedEv, depositedEv)
                .When(cmd)
                .Then(withdrawnEv));
        }
Exemple #3
0
 public AtmStateMachine(Money cash)
 {
     _currentState = Initial = new InitialState(this);
     CardInserted  = new CardInserted(this);
     PinEntered    = new PinEntered(this);
     CashWithdrawn = new CashWithdrawn(this);
     CashAmount    = cash;
 }
Exemple #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)
                );
        }
Exemple #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)
                );
        }
Exemple #6
0
        public async Task CashWithdrawalWhenAccountIsBlockedShouldRaiseAccountBlockedEvent()
        {
            decimal withdrawAmount = 10000;
            decimal depositeAmount = 5000;

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

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

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

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

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

            await _runner.Run(
                def => def.Given(accountCreated, evtCashDeposited, evtCashWithdrawn).When(cmdWithdrawCash).Then(evAccountBlocked)
                );
        }
Exemple #7
0
        public async Task CanWithdrawCash(double amount)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

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

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

            await _runner.Run(
                def => def.Given(created).When(cmd).Then(limitSet)
                );
        }
Exemple #8
0
 private void Apply(CashWithdrawn @event)
 {
     this.Debt -= @event.Amount;
 }