예제 #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);
        }
예제 #2
0
        public async Task <LimitCustomer> GetLimitAsync(string companyKey, string documentNumber)
        {
            var limitCompany = await _companyQuery.GetAsync(companyKey);

            if (limitCompany is null)
            {
                return(null);
            }

            var limitCustomer = await _customerQuery.GetAsync(LimitCustomer.GetId(companyKey, documentNumber));

            var limitUseds = await _limitUsedQuery.GetResumeAsync(companyKey, documentNumber);


            if (limitCustomer is null)
            {
                limitCustomer = LimitCustomer.Create(companyKey, documentNumber);
            }

            foreach (var limit in limitCompany.Limits)
            {
                foreach (var cycle in limit.Cycles)
                {
                    foreach (var limitLevel in cycle.LimitLevels)
                    {
                        var limitLevelCustomer = limitCustomer.GetLimitLevel(limit.Type, limit.FeatureType, cycle.Type, limitLevel.Type) ?? limitLevel;
                        var limitResume        = GetResume(limitUseds, limit.Type, limit.FeatureType, cycle.Type, limitLevel.Type);

                        if (!(limitResume is null))
                        {
                            limitLevelCustomer.DecreaseMaxValue(limitResume.Amount);
                        }
                        limitCustomer.AddLimitLevel(limit.Type, limit.FeatureType, cycle.Type, limitLevelCustomer);
                    }
                }
            }


            return(limitCustomer);
        }
        public async Task GetLimitJoinWithLimitCustomerWithLimitUsed()
        {
            //arrange
            var company        = Fixture.GetLimitCompanyValid();
            var documentNumber = "document123";
            var limitType      = LimitType.CashIn;
            var featureType    = FeatureType.TED;
            var cycleType      = CycleType.Monthly;
            var levelType      = LevelType.Account;
            var limitUsedMax   = 600;
            var limitMaxValue  = 80000;

            var limitLevel = LimitLevel.Create(levelType, limitMaxValue, 6000);
            var customer   = Fixture.CreateLimitCustomer(limitType, featureType, cycleType, limitLevel);

            var limitUsed = new LimitLevelResumeDto()
            {
                CompanyKey = company.CompanyKey, DocumentNumber = documentNumber, LimitType = limitType, FeatureType = featureType, CycleType = cycleType, LevelType = levelType, Amount = limitUsedMax
            };
            var listLimitUsed = new List <LimitLevelResumeDto> {
                limitUsed
            };

            _companyRepositoryQuery.GetAsync(Arg.Any <string>()).Returns(company);
            _customerRepositoryQuery.GetAsync(Arg.Any <string>()).Returns(customer);
            _limitUsedQueryRepository.GetResumeAsync(Arg.Any <string>(), Arg.Any <string>()).Returns(listLimitUsed);

            //act
            var limitCustomer = await _limitService.GetLimitAsync(company.CompanyKey, documentNumber);

            var limitLevelGet = limitCustomer.GetLimitLevel(limitType, featureType, cycleType, levelType);

            //assert
            Assert.NotNull(limitLevelGet);
            Assert.Equal(limitLevel.Type, limitLevelGet.Type);
            Assert.Equal(limitMaxValue - limitUsedMax, limitLevelGet.MaxValue);
            Assert.Equal(limitLevel.MinValue, limitLevelGet.MinValue);
        }