Exemple #1
0
        public async Task CannotSetLimitOnInvalidAccount()
        {
            var cmd = new SetODLimit
            {
                AccountId = _accountId,
                ODLimit   = Convert.ToDecimal(100m)
            };

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

            var cmd = new SetODLimit
            {
                AccountId = _accountId,
                ODLimit   = Convert.ToDecimal(limit)
            };

            await _runner.Run(
                def => def.Given(created).When(cmd).Throws(new ValidationException("Overdraft limit must be a Positive amount"))
                );
        }
Exemple #3
0
        public CommandResponse Handle(SetODLimit command)
        {
            try
            {
                if (!_repository.TryGetById <Account>(command.AccountId, out var account))
                {
                    throw new ValidationException("No account with this ID exists");
                }

                account.SetODLimit(command.ODLimit, command);

                _repository.Save(account);
                return(command.Succeed());
            }
            catch (Exception e)
            {
                return(command.Fail(e));
            }
        }
Exemple #4
0
        public async Task CanSetOverdraftLimit(double limit)
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = _accountId,
                AccountHolderName = "Parth Sheth"
            };

            var cmd = new SetODLimit
            {
                AccountId = _accountId,
                ODLimit   = Convert.ToDecimal(limit)
            };

            var limitSet = new ODLimitSet(cmd)
            {
                AccountId = _accountId,
                ODLimit   = cmd.ODLimit
            };

            await _runner.Run(
                def => def.Given(created).When(cmd).Then(limitSet)
                );
        }