Пример #1
0
        public async Task CanSetDailyTransfertLimit()
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "Miled",
                OverdraftLimit    = 0
            };

            var cmd = new SetDailyWireTransfertLimit
            {
                AccountId = AccountId,
                Limit     = 350
            };

            var ev = new DailyWireTransfertLimitSet(cmd)
            {
                AccountId = AccountId,
                Limit     = 350
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Then(ev)
                );
        }
Пример #2
0
        public async Task CannotSetLimitOnInvalidAccount()
        {
            var cmd = new SetDailyWireTransfertLimit
            {
                AccountId = AccountId,
                Limit     = Convert.ToInt32(100m)
            };

            await Runner.Run(
                def => def.Given().When(cmd).Throws(new InvalidOperationException("No Account is already exist"))
                );
        }
Пример #3
0
        public async Task CannotSetNegativeLimit()
        {
            var created = new AccountCreated(CorrelatedMessage.NewRoot())
            {
                AccountId         = AccountId,
                AccountHolderName = "NNN"
            };

            var cmd = new SetDailyWireTransfertLimit
            {
                AccountId = AccountId,
                Limit     = -1
            };

            await Runner.Run(
                def => def.Given(created).When(cmd).Throws(new InvalidOperationException("Daily transfert limit should be positve"))
                );
        }
        public CommandResponse Handle(SetDailyWireTransfertLimit command)
        {
            try
            {
                if (!_repository.TryGetById <Account>(command.AccountId, out var account))
                {
                    throw new InvalidOperationException("No Account is already exist");
                }

                account.SetDailyWireTransfertLimit(command.AccountId, command.Limit, command);

                _repository.Save(account);
                return(command.Succeed());
            }
            catch (Exception e)
            {
                return(command.Fail(e));
            }
        }