Пример #1
0
        public void RuleRepositoryTest_Rules_AddRule_validModel()
        {
            var model = new RuleModel
            {
                RuleId   = 0,
                Category = "newcategory",
                Text     = "textnew",
                Title    = "newtitle"
            };
            var result = rep.Add(model);

            Assert.AreEqual(true, result, string.Format("result != expected"));
        }
        public void RuleApplicationService_Remove()
        {
            var rule = new RuleBuilder().Builder();

            _ruleRepository.Add(rule);
            _unitOfWork.Commit();

            _ruleApplicationService.Remove(rule.Id);

            var result = _ruleRepository.Get(new Filter());

            result.entities.Should().HaveCount(0);
        }
Пример #3
0
        public static void CreateRule(IRuleRepository ruleRepository, string name, RuleType ruleType, int ruleOrder, string ruleText)
        {
            var rule = new Rule(new RuleId(ruleRepository.GetNextId()), name, ruleText, ruleType, ruleOrder);

            ruleRepository.Add(rule);
            rules.Add(rule);
        }
Пример #4
0
 public bool Add(RuleModel rule)
 {
     if (!rule.Validate())
     {
         throw new Exception("Invalid model");
     }
     return(rep.Add(rule));
 }
Пример #5
0
        public Rule Add(RuleViewModel Vm)
        {
            var entity = _mapper.Map <Rule>(Vm);

            _ruleRepository.Add(entity);
            SaveChanges();
            return(entity);
        }
Пример #6
0
        public void AccountApplicationService_Add()
        {
            var model = new AccountModel
            {
                OriginalValue = 10,
                PaymentDate   = DateTime.Now.Date,
                DueDate       = DateTime.Now.AddDays(-2).Date,
                Name          = "test"
            };

            var rule = new RuleBuilder().WithDays(3).WithType(RuleType.UpUntil).WithPenalty(2).WithInterestPerDay(0.2m).Builder();

            _ruleRepository.Add(rule);
            _unitOfWork.Commit();

            _accountApplicationService.Add(model);

            var result = _accountRepository.Get(new Filter());

            result.entities.Should().HaveCount(1);

            var entity = result.entities.First();

            entity.OriginalValue.Should().Be(10);
            entity.RuleId.Should().Be(rule.Id);
            entity.CorrectedValue.Should().Be(10.24m);
            entity.NumberOfDaysLate.Should().Be(2);
        }
Пример #7
0
        public Task Handle(DefineGlobalRuleCommand command)
        {
            var activePeriod      = new DateRange(command.StartDate, command.EndDate);
            var calculationMethod = CalculationMethodFactory.Create(command.Increasing, command.Points);
            var rule = new Rule(command.Title, activePeriod, calculationMethod);

            _ruleRepository.Add(rule);
            return(Task.CompletedTask);
        }
Пример #8
0
 public void AddRule(string name, string text)
 {
     var rule = ruleRepository.Add(new Rules()
     {
         Id   = Guid.NewGuid(),
         Name = name,
         Text = text
     });
 }
Пример #9
0
        public async Task <int> DefineRule(DefineRuleCommand command)
        {
            var id       = 1; //TODO: remove hard-coded id
            var criteria = CriteriaMapper.Map(command.Criteria);
            var rule     = new Rule(1, command.Title, criteria);
            await _repository.Add(rule);

            return(id);
        }
Пример #10
0
        public void Rule_test()
        {
            var rule = new RuleBuilder().Builder();

            _ruleRepository.Add(rule);
            _unitOfWork.Commit();

            var result = _ruleRepository.GetById(rule.Id);

            result.Should().NotBeNull();
            result.Should().Be(rule);
        }
Пример #11
0
        public void RuleRepository_Get()
        {
            var rule_1 = new RuleBuilder().Builder();
            var rule_2 = new RuleBuilder().Builder();
            var rule_3 = new RuleBuilder().Builder();

            _ruleRepository.Add(rule_1);
            _ruleRepository.Add(rule_2);
            _ruleRepository.Add(rule_3);

            _unitOfWork.Commit();

            var filter = new Filter();

            var result = _ruleRepository.Get(filter);

            result.totalItems.Should().Be(3);
            result.entities.Should().HaveCount(3);


            filter.Search       = string.Empty;
            filter.CurrentPage  = 1;
            filter.ItemsPerPage = 2;

            result = _ruleRepository.Get(filter);

            result.totalItems.Should().Be(3);
            result.entities.Should().HaveCount(2);
        }
Пример #12
0
        public void Add(RuleDto dto)
        {
            if (!dto.IsValid())
            {
                NotifyValidationError(dto);
                return;
            }

            var entity = new Rule(days: dto.Days.Value, type: dto.Type.Value, interestPerDay: dto.InterestPerDay.Value, penalty: dto.Penalty.Value);

            _ruleRepository.Add(entity);

            Commit();
        }
Пример #13
0
        public void Account_test()
        {
            var rule    = new RuleBuilder().Builder();
            var account = new AccountBuilder().WithRule(rule).Builder();

            _ruleRepository.Add(rule);
            _accountRepository.Add(account);
            _unitOfWork.Commit();

            var result = _accountRepository.GetById(account.Id);

            result.Should().NotBeNull();
            result.Should().Be(account);
        }
Пример #14
0
        public void RuleServiceTest_Add_valid()
        {
            var model = new RuleModel
            {
                RuleId   = 1,
                Category = "Category",
                Text     = "Text",
                Title    = "Title"
            };
            var expected = rep.Add(model);
            var actual   = service.Add(model);

            Assert.AreEqual(expected, actual);
        }
        public RuleNameResource Add(EditRuleNameResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException();
            }

            var rulename = _mapper.Map <RuleName>(resource);

            _ruleRepo.Add(rulename);
            _ruleRepo.SaveChanges();

            return(_mapper.Map <RuleNameResource>(rulename));
        }
Пример #16
0
        public IActionResult CreateRule(string code, string group, string source)
        {
            RuleGroup rgroup = _groupRepository.GetFor(group);

            if (rgroup == null)
            {
                return(StatusCode(400, "Invalid Group Code"));
            }

            Rule rule = Rule.CreateRule().Named(code).WithGroup(rgroup).WithSource(source).Build();

            _ruleRepository.Add(rule);

            return(CurrentRules());
        }
Пример #17
0
        public void AccountRepository_Get()
        {
            var rule      = new RuleBuilder().Builder();
            var account_1 = new AccountBuilder().WithName("conta do banco").Builder();
            var account_2 = new AccountBuilder().WithName("conta do cartao").Builder();
            var account_3 = new AccountBuilder().WithName("conta da casa").Builder();

            _ruleRepository.Add(rule);
            _accountRepository.Add(account_1);
            _accountRepository.Add(account_2);
            _accountRepository.Add(account_3);
            _unitOfWork.Commit();

            var filter = new Filter();

            var result = _accountRepository.Get(filter);

            result.totalItems.Should().Be(3);
            result.entities.Should().HaveCount(3);

            filter.Search = "conta do banco";
            result        = _accountRepository.Get(filter);

            result.totalItems.Should().Be(1);
            result.entities.Should().HaveCount(1);
            result.entities.First().Should().Be(account_1);

            filter.Search       = string.Empty;
            filter.CurrentPage  = 1;
            filter.ItemsPerPage = 2;

            result = _accountRepository.Get(filter);

            result.totalItems.Should().Be(3);
            result.entities.Should().HaveCount(2);
        }
Пример #18
0
        public IHttpActionResult Put([FromUri] int id, [FromBody] RuleTypeModel command)
        {
            if (command == null)
            {
                return(BadRequest("Entity can not be null"));
            }

            if (command.Id != id)
            {
                return(BadRequest("Model id does not match"));
            }

            if (!ModelState.IsValid || command.Rules == null || !command.Rules.Any())
            {
                return(this.Error().InvalidParameters("Invalid rule type parameters"));
            }

            var targetRuleType = _ruleTypeRepository.Get(id);

            if (targetRuleType is null)
            {
                return(NotFound());
            }

            // Update rule type
            targetRuleType.Name = command.Name;

            _ruleTypeRepository.Update(targetRuleType);
            _ruleTypeRepository.SaveChanges();

            var rules = _ruleRepository.FindByRuleTypeId(targetRuleType.Id);

            var deletedRuleIds = rules.Where(r => command.Rules.All(cr => r.Id != cr.Id))
                                 .Select(r => new { r.Id, r.RuleId })
                                 .ToList();

            var maxRuleId = command.Rules.Max(r => r.RuleId) + 1;

            var newRuleIds = new List <int>();

            // Upsert rules per rule type
            foreach (var ruleItem in command.Rules)
            {
                var rule = _ruleRepository.Get(ruleItem.Id);
                if (rule != null)
                {
                    rule.Description  = ruleItem.Description;
                    rule.InternalType = ruleItem.InternalType;
                    rule.Type         = ruleItem.Type;
                    _ruleRepository.Update(rule);
                }
                else
                {
                    rule            = _mapper.Map <Rule>(ruleItem);
                    rule.Id         = 0;
                    rule.RuleTypeId = id;
                    rule.RuleId     = maxRuleId++;
                    _ruleRepository.Add(rule);

                    if (targetRuleType.AllowedForAutopilot && !targetRuleType.IsCustom)
                    {
                        newRuleIds.Add(rule.RuleId);
                    }
                }
            }
            _ruleRepository.SaveChanges();

            // Delete rules only for custom rule types
            if (deletedRuleIds.Any())
            {
                deletedRuleIds.ForEach(r => _ruleRepository.Delete(r.Id));
            }

            _ruleRepository.SaveChanges();

            if (targetRuleType.AllowedForAutopilot && !targetRuleType.IsCustom)
            {
                UpdateAutopilotRulesRepository(targetRuleType.Id, newRuleIds, deletedRuleIds.Select(r => r.RuleId).ToList());
            }

            var ruleType = _ruleTypeRepository.Get(id);

            return(Ok(Mappings.MapToRuleTypeModel(ruleType, _ruleRepository, _mapper)));
        }
Пример #19
0
 public bool AddRule(Rule rule)
 {
     _ruleRepository.Add(rule);
     return(true);
 }
Пример #20
0
 public Rule Add(Rule model)
 {
     _repository.Add(model);
     return(model);
 }