Beispiel #1
0
        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 CanDepositChequeInToValidAccount()
        {
            decimal  depositeAmount = 5000;
            DateTime depositeDate   = System.DateTime.Now;
            var      accountCreated = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Tushar"
            };
            var cmd = new DepositCheque
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount,
                DepositDate   = depositeDate
            };

            var ev = new ChequeDeposited(cmd)
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount,
                DepositDate   = depositeDate
            };

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

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

            await _runner.Run(
                def => def
                .Given()
                .When(cmd)
                .Throws(new SystemException("The cheque cannot be deposited to the inexistent account."))
                );
        }
        public async Task ChequeDepositShouldThrowExceptionWhenAccountIsNotPresent()
        {
            decimal  depositeAmount = 5000;
            DateTime depositeDate   = System.DateTime.Now;

            var cmd = new DepositCheque
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount,
                DepositDate   = depositeDate
            };

            await _runner.Run(
                def => def.Given().When(cmd).Throws(new ValidationException("No account with this ID exists"))
                );
        }
Beispiel #6
0
        public async Task CannotDepositCashWithNonPositiveAmount(double amount)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

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

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

                account.DepositCheque(command.ChequeId, command.Amount, _clock, command);

                _repository.Save(account);
                return(command.Succeed());
            }
            catch (Exception e)
            {
                return(command.Fail(e));
            }
        }
Beispiel #8
0
        public async Task CannotDepositCheque(decimal amount)
        {
            var accCreatedEv = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId = _accountId,
                Name      = "Jake Sanders"
            };

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

            await _runner.Run(
                def => def
                .Given(accCreatedEv)
                .When(cmd)
                .Throws(new SystemException("The deposited cheque amount should be greater than 0."))
                );
        }
        public async Task ChequeDepositAmountCannotBeNegative()
        {
            decimal  depositeAmount = -5000;
            DateTime depositeDate   = System.DateTime.Now;

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

            var cmd = new DepositCheque
            {
                AccountId     = _accountId,
                DepositAmount = depositeAmount,
                DepositDate   = depositeDate
            };

            await _runner.Run(
                def => def.Given(accountCreated).When(cmd).Throws(new ValidationException("Cheque deposit amount cannot be negative"))
                );
        }
Beispiel #10
0
        public async Task CanDepositCheque(double amount)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

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

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

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

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

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

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