Example #1
0
        public async Task GetRusumeLimitsUsed()
        {
            //arrange
            var random         = new Random();
            var company        = "ACESSO";
            var documentNumber = $"{random.Next(10000, 100000)}";

            long resumeAmount = 0;

            for (var i = 0; i < random.Next(5, 15); i++)
            {
                var limitUsed = LimitUsed.Create(company, documentNumber, LimitType.CashIn, FeatureType.TED, CycleType.Daily, LevelType.Account, random.Next(100, 500));
                await _commandRepository.SaveAsync(limitUsed);

                resumeAmount += limitUsed.Amount;
            }

            //act
            var resumes = await _queryRepository.GetResumeAsync(company, documentNumber);

            //assert
            Assert.NotNull(resumes);
            Assert.True(resumes.Count() == 1);
            Assert.Equal(resumeAmount, resumes.FirstOrDefault().Amount);
        }
        public async Task <ResultOfCommandData <LimitAvaliableDto> > Handle(ReserveLimitCommand request, CancellationToken cancellationToken)
        {
            var result        = new ResultOfCommandData <LimitAvaliableDto>();
            var limitCustomer = await _limitService.GetLimitAsync(request.CompanyKey, request.DocumentNumber);

            var limitLevel = limitCustomer.GetLimitLevel(request.LimitType, request.FeatureType, request.CycleType, request.LevelType);

            if (limitLevel.MaxValue >= request.Amount)
            {
                var limitUsed = LimitUsed.Create(request.CompanyKey,
                                                 request.DocumentNumber,
                                                 request.LimitType,
                                                 request.FeatureType,
                                                 request.CycleType,
                                                 request.LevelType,
                                                 request.Amount);

                await _limitUsedCommand.SaveAsync(limitUsed);

                result.Data = new LimitAvaliableDto {
                    AmountUsed = request.Amount, LimitAvaliable = limitLevel.MaxValue - request.Amount
                };
            }
            else
            {
                result.AddErrorMessage(MessageOfDomain.DontHaveLimit);
            }

            return(result);
        }
Example #3
0
        public async Task AddLimitUsed()
        {
            //arrange
            var limitUsed = LimitUsed.Create("ACESSO", "document123", LimitType.CashIn, FeatureType.TED, CycleType.Daily, LevelType.Account, 50);

            //act
            await _commandRepository.SaveAsync(limitUsed);

            var limitUserFound = await _queryRepository.GetAsync(limitUsed.Id);

            //assert
            Assert.NotNull(limitUserFound);
        }