public async Task CashWithdrawalGreaterThanAllowedLimit() { 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 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).When(cmdWithdrawCash).Then(evAccountBlocked) ); }
public async Task CanUnblockAccountOnNextBusinessDay() { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; var depositedEv = new ChequeDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = 1000m }; var cmd = new StartNewBusinessDay() { AccountId = _accountId }; var accUnblockedEv = new AccountUnblocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; await _runner.Run( def => def .Given(accCreatedEv, accBlockedEv, depositedEv) .When(cmd) .Then(accUnblockedEv)); }
public async Task CannotUnblockAccountAfterDepositCheque() { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; var cmd = new DepositCheque() { AccountId = _accountId, Amount = 1000 }; var amountSetEv = new ChequeDeposited(CorrelatedMessage.NewRoot()) { AccountId = cmd.AccountId, Amount = cmd.Amount }; await _runner.Run( def => def .Given(accCreatedEv, accBlockedEv) .When(cmd) .Then(amountSetEv)); }
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) ); }
public async Task CannotWireTransferMultipleTimesIfLimitExceeded( decimal deposit, decimal limit, decimal transfer) { var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var cashDepositedEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var dailyLimitSetEv = new DailyWireTransferLimitSet(CorrelatedMessage.NewRoot()) { AccountId = _accountId, DailyLimit = limit }; var transferedEv = new WireTransferHappened(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = transfer }; var cmd = new TryWireTransfer() { AccountId = _accountId, Amount = transfer }; var transferFailedEv = new WireTransferFailed(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = transfer }; var accBlockedEv = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; await _runner.Run( def => def .Given(accCreatedEv, cashDepositedEv, dailyLimitSetEv, transferedEv, transferedEv) .When(cmd) .Then(transferFailedEv, accBlockedEv)); }
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) ); }
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)); }
public async Task CannotWireTransferIfAccountIsBlocked() { var deposit = 5000m; var transfer = 100m; var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Name = "Jake Sanders" }; var cashDepositedEv = new CashDeposited(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = deposit }; var accBlocked = new AccountBlocked(CorrelatedMessage.NewRoot()) { AccountId = _accountId }; var cmd = new TryWireTransfer() { AccountId = _accountId, Amount = transfer }; var transferFailedEv = new WireTransferFailed(CorrelatedMessage.NewRoot()) { AccountId = _accountId, Amount = cmd.Amount }; await _runner.Run( def => def .Given(accCreatedEv, cashDepositedEv, accBlocked) .When(cmd) .Then(transferFailedEv)); }
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)); }
private void Apply(AccountBlocked @event) { AccountState = State.blocked; }