public void ValidateTrue()
        {
            _policy1.OwnerName    = "S";
            _policy1.PolicyNumber = "AB7D";

            var result = _policyValidator.Validate(_policy1);

            Assert.AreEqual(true, result);
        }
Exemplo n.º 2
0
        public void Validate()
        {
            var resultTrue = _policyValidator.Validate(_policyTrue);

            Assert.AreEqual(true, resultTrue);

            var resultFalse = _policyValidator.Validate(_policyFalse);

            Assert.AreEqual(false, resultFalse);
        }
Exemplo n.º 3
0
        public void TestForeignKeyConstraintIsValidated()
        {
            // Arrange
            var assignments = new List <PolicyByUser>()
            {
                new PolicyByUser(),
                new PolicyByUser(),
                new PolicyByUser(),
            };

            // We define the data that will be returned by the repository
            var mockRepository = new Mock <IPolicyByUserRepository>();
            var mockICoverageTypeByPolicyRepository = new Mock <ICoverageTypeByPolicyRepository>();

            mockRepository.Setup(x => x.GetPolicyAssignations(It.IsAny <int>())).Returns(assignments.AsQueryable());

            var validator = new PolicyValidator(mockRepository.Object, mockICoverageTypeByPolicyRepository.Object);

            var policy = new Policy();

            // Act
            var result = validator.Validate(policy, ruleSet: "delete");

            // Assert
            Assert.Contains(result.Errors, x => x.ErrorMessage == "The policy is already assigned to a user, please delete the relationship first");
        }
Exemplo n.º 4
0
        public async Task <Result> UpdatePolicy(ScopeOptions scope, PolicyEdit policy)
        {
            var validator = new PolicyValidator(_context, scope, false);
            var result    = validator.Validate(policy, ruleSet: "default,availability").GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var entity = await GetPolicyEntityQuery(scope).FirstOrDefaultAsync(p => p.Id == policy.Id);

            if (entity == null)
            {
                return(new Result());
            }

            var clientEntity = MapModelToEntity(policy, entity);

            await _context.SaveChangesAsync();

            await _auditService.InsertAuditLog(scope, AuditLog.ACTION_UPDATE, "Policy", entity.Id, policy);

            return(result);
        }
        public ActionResult <Policy> Create(Policy policy)
        {
            ValidationResult result = _validations.Validate(policy);

            if (!result.IsValid)
            {
                foreach (var err in result.Errors)
                {
                    Console.WriteLine(err.PropertyName + ": " + err.ErrorMessage);
                    return(BadRequest());
                }
            }
            _policyService.Create(policy);
            //return CreatedAtRoute("GetPolicies", new { id = policy.Id }, policy);
            return(null);
        }
Exemplo n.º 6
0
        public void TestNoErrorIsReturnedIfPorcentageIsBelowOrEquals50AndTheRiskIsHigh()
        {
            // Arrange
            var mockRepository = new Mock <IPolicyByUserRepository>();
            var mockICoverageTypeByPolicyRepository = new Mock <ICoverageTypeByPolicyRepository>();

            var validator = new PolicyValidator(mockRepository.Object, mockICoverageTypeByPolicyRepository.Object);

            var policy = new Policy()
            {
                Coverage   = 50,
                RiskTypeId = (int)DataAccess.Enums.RiskType.High
            };

            // Act
            var result = validator.Validate(policy);

            // Assert
            Assert.DoesNotContain(result.Errors, x => x.ErrorMessage == "The coverage percentage can go above 50% because the risk is High");
        }
        public virtual Response Process(SessionActivity sessionActivity)
        {
            var policy     = _policyMiner.Mine(sessionActivity);
            var validation = _policyValidator.Validate(policy);

            if (validation == false)
            {
                return(new Response
                {
                    Message = "Failed validation",
                    Successful = false
                });
            }

            var policyModel   = _policyMapper.Map(policy);
            var responseModel = _policySender.Send(policyModel);
            var response      = _responseMapper.Map(responseModel);

            return(response);
        }
        public virtual Response Process(SessionActivity sessionActivity)
        {
            var policy = _policyMiner.Mine(sessionActivity);
            var valid  = _policyValidator.Validate(policy);

            if (!valid)
            {
                Response failedResponse = new Response
                {
                    Successful = false,
                    Message    = "This response is not valid"
                };

                return(failedResponse);
            }

            var policyModel   = _policyMapper.Map(policy);
            var responseModel = _policySender.Send(policyModel);
            var response      = _responseMapper.Map(responseModel);

            return(response);
        }
Exemplo n.º 9
0
        public async Task <Result> InsertPolicy(ScopeOptions scope, PolicyEdit policy)
        {
            var validator = new PolicyValidator(_context, scope, true);
            var result    = validator.Validate(policy, ruleSet: "default,availability").GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var entity = MapModelToEntity(policy);
            await _context.Policy.AddAsync(entity);

            await _context.SaveChangesAsync();

            policy.Id  = entity.Id;
            result.Tag = policy;

            await _auditService.InsertAuditLog(scope, AuditLog.ACTION_INSERT, "Policy", entity.Id, policy);

            return(result);
        }
Exemplo n.º 10
0
        public async Task <Result> MergePolicies(ScopeOptions scope, MergePolicies merge)
        {
            var clientValidator = new PolicyValidator(_context, scope, true);
            var result          = clientValidator.Validate(merge.TargetPolicy, ruleSet: "default").GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var mergeValidator = new MergePoliciesValidator(_context, scope);

            result = mergeValidator.Validate(merge).GetResult();

            if (!result.Success)
            {
                return(result);
            }

            var strategy = _context.Database.CreateExecutionStrategy();

            result = await strategy.ExecuteAsync <Result>(async() =>
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        //Insert the 'new' policy
                        var entity = MapModelToEntity(merge.TargetPolicy);
                        await _context.Policy.AddAsync(entity);
                        await _context.SaveChangesAsync();

                        merge.TargetPolicy.Id = entity.Id;

                        //Move dependancies to the new policy ----------------------------------------------------

                        //1. Commissions
                        var commmissions = await _context.Commission.Where(p => merge.SourcePolicyIds.Contains(p.PolicyId)).ToListAsync();
                        foreach (var commmission in commmissions)
                        {
                            commmission.PolicyId = merge.TargetPolicy.Id.Value;
                        }

                        //2. Commission Errors
                        var commissionErrors = await _context.CommissionError.Where(c => merge.SourcePolicyIds.Contains(c.PolicyId.Value)).ToListAsync();
                        foreach (var commissionError in commissionErrors)
                        {
                            commissionError.PolicyId = merge.TargetPolicy.Id.Value;
                        }

                        //3. Commission Split Rule Policies
                        var commissionSplitRulePolicies = await _context.CommissionSplitRulePolicy.Where(c => merge.SourcePolicyIds.Contains(c.PolicyId)).ToListAsync();
                        foreach (var commissionSplitRulePolicy in commissionSplitRulePolicies)
                        {
                            commissionSplitRulePolicy.PolicyId = merge.TargetPolicy.Id.Value;
                        }

                        //4. Commission Allocation Policies
                        var commissionAllocationPolicies = await _context.CommissionAllocationPolicy.Where(c => merge.SourcePolicyIds.Contains(c.PolicyId)).ToListAsync();
                        foreach (var commissionAllocationPolicy in commissionAllocationPolicies)
                        {
                            commissionAllocationPolicy.PolicyId = merge.TargetPolicy.Id.Value;
                        }

                        await _context.SaveChangesAsync();
                        //----------------------------------------------------------------------------------------

                        //Delete 'old' policies
                        var policiesToDelete = await _context.Policy.Where(m => merge.SourcePolicyIds.Contains(m.Id)).ToListAsync();
                        foreach (var policyToDelete in policiesToDelete)
                        {
                            _context.Remove(policyToDelete);
                        }
                        await _context.SaveChangesAsync();

                        //Commit
                        await transaction.CommitAsync();

                        return(new Result(true));
                    }
                    catch
                    {
                        transaction.Rollback();
                        return(new Result(false));
                    }
                }
            });

            result.Tag = merge.TargetPolicy;

            await _auditService.InsertAuditLog(scope, "Merge", "Policy", merge.TargetPolicy.Id, merge);

            return(result);
        }