コード例 #1
0
        public async Task InsertCommissionType()
        {
            var options = TestHelper.GetDbContext("InsertCommissionType");

            //Given
            var model = new CommissionType()
            {
                Name                     = "1",
                Code                     = "one",
                PolicyTypeId             = Guid.NewGuid(),
                CommissionEarningsTypeId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                var service = new CommissionLookupService(context);

                //When
                var result = await service.InsertCommissionType(model);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionType.FindAsync(((CommissionType)result.Tag).Id);

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
                Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(model.CommissionEarningsTypeId, actual.CommissionEarningsTypeId);
            }
        }
コード例 #2
0
        public async Task GetCommissionTypes()
        {
            var options = TestHelper.GetDbContext("GetCommissionTypes");

            //Given
            var lkp1 = new CommissionTypeEntity {
                Id = Guid.NewGuid(), Name = "A", Code = "aa", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid()
            };
            var lkp2 = new CommissionTypeEntity {
                Id = Guid.NewGuid(), Name = "B", Code = "bb", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid()
            };
            var lkp3 = new CommissionTypeEntity {
                Id = Guid.NewGuid(), Name = "C", Code = "cc", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                //Jumbled order
                context.CommissionType.Add(lkp2);
                context.CommissionType.Add(lkp1);
                context.CommissionType.Add(lkp3);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new CommissionLookupService(context);

                //When
                var actual = await service.GetCommissionTypes();

                //Then
                Assert.Equal(3, actual.Count);

                var actual1 = actual[0];
                Assert.Equal(lkp1.Id, actual1.Id);
                Assert.Equal(lkp1.Name, actual1.Name);
                Assert.Equal(lkp1.Code, actual1.Code);
                Assert.Equal(lkp1.PolicyTypeId, actual1.PolicyTypeId);
                Assert.Equal(lkp1.CommissionEarningsTypeId, actual1.CommissionEarningsTypeId);

                var actual2 = actual[1];
                Assert.Equal(lkp2.Id, actual2.Id);

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
コード例 #3
0
        public async Task UpdateCommissionType()
        {
            var options = TestHelper.GetDbContext("UpdateCommissionType");

            //Given
            var lkp1 = new CommissionTypeEntity {
                Id = Guid.NewGuid(), Name = "1", Code = "aa", PolicyTypeId = Guid.NewGuid(), CommissionEarningsTypeId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                context.CommissionType.Add(lkp1);

                context.SaveChanges();
            }

            var model = new CommissionType()
            {
                Id                       = lkp1.Id,
                Name                     = "1 Updated",
                Code                     = "aa Updated",
                PolicyTypeId             = Guid.NewGuid(),
                CommissionEarningsTypeId = Guid.NewGuid()
            };

            using (var context = new DataContext(options))
            {
                var service = new CommissionLookupService(context);

                //When
                var result = await service.UpdateCommissionType(model);

                //Then
                Assert.True(result.Success);

                var actual = await context.CommissionType.FindAsync(model.Id);

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
                Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(model.CommissionEarningsTypeId, actual.CommissionEarningsTypeId);
            }
        }
コード例 #4
0
        public async Task ImportCommission_NoMapping_SetCommisionType()
        {
            var options = TestHelper.GetDbContext("ImportCommission_SetCommisionType");

            var user1     = TestHelper.InsertUserDetailed(options);
            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var commissionType = new CommissionTypeEntity
            {
                Id   = Guid.NewGuid(),
                Code = "gap_cover"
            };

            using (var context = new DataContext(options))
            {
                context.CommissionType.Add(commissionType);
                context.SaveChanges();

                var auditService                     = new AuditServiceMock();
                var statementService                 = new CommissionStatementService(context, null, auditService);
                var lookupService                    = new DirectoryLookupService(context);
                var commissionLookupService          = new CommissionLookupService(context);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var policyService                    = new PolicyService(context, auditService);

                var bulkActions    = new Mock <IBulkActions>(MockBehavior.Strict);
                var insertedErrors = new List <CommissionErrorEntity>();
                bulkActions.Setup(c => c.BulkInsertCommissionErrorsAsync(It.IsAny <DataContext>(), It.IsAny <IList <CommissionErrorEntity> >()))
                .Callback((DataContext c, IList <CommissionErrorEntity> l) => insertedErrors = l.ToList())
                .Returns(Task.CompletedTask);

                var service = new CommissionImportService(
                    context,
                    bulkActions.Object,
                    statementService,
                    policyService,
                    lookupService,
                    commissionLookupService,
                    commissionSplitService,
                    commissionSplitRulePolicyService,
                    auditService);

                //When
                var import1 = new ImportCommission
                {
                    PolicyNumber       = "123  456",  // has spaces, should be removed
                    CommissionTypeCode = "gap_cover", //existing cover
                    AmountIncludingVAT = "100",
                    VAT = "14"
                };

                var scope        = TestHelper.GetScopeOptions(user1);
                var importResult = (await service.ImportCommissions(scope, statement.Id, new List <ImportCommission>()
                {
                    import1
                }));

                var result = importResult.Results.Single();

                //Then
                Assert.True(result.Success);
                Assert.Empty(result.ValidationFailures);

                //Check error record
                var actual = insertedErrors.Single();

                Assert.Null(actual.ClientId);
                Assert.Null(actual.PolicyId);
                Assert.Equal(commissionType.Id, actual.CommissionTypeId);

                Assert.Equal(statement.Id, actual.CommissionStatementId);

                import1.PolicyNumber = import1.PolicyNumber.TrimWhiteSpace();
                Assert.Equal(import1, actual.Data);
            }
        }
コード例 #5
0
        public async Task ImportCommission_InsertCommission_Split_Specific()
        {
            var options = TestHelper.GetDbContext("ImportCommission_InsertCommission_Split_Specific");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);
            var user2   = TestHelper.InsertUserDetailed(options, user1.Organisation);
            var user3   = TestHelper.InsertUserDetailed(options, user1.Organisation);

            var company   = TestHelper.InsertCompany(options);
            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id);

            var commissionType = new CommissionTypeEntity
            {
                Id   = Guid.NewGuid(),
                Code = "gap_cover"
            };

            var policy1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = Guid.NewGuid().ToString(),
                CompanyId     = company.Id,
                ClientId      = client1.Client.Id,
                UserId        = user1.User.Id,
                NumberAliases = new List <string>(),
            };

            var csr1 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "75/25 split",
                IsDefault = true, //Default
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user2.User.Id,
                        Percentage = 75
                    },
                    new CommissionSplit()
                    {
                        UserId     = user3.User.Id,
                        Percentage = 25
                    }
                }
            };

            var csr2 = new CommissionSplitRuleEntity
            {
                Id        = Guid.NewGuid(),
                UserId    = user1.User.Id,
                Name      = "50/50 split",
                IsDefault = false, //Not Default
                Split     = new List <CommissionSplit>()
                {
                    new CommissionSplit()
                    {
                        UserId     = user2.User.Id,
                        Percentage = 50
                    },
                    new CommissionSplit()
                    {
                        UserId     = user3.User.Id,
                        Percentage = 50
                    }
                }
            };

            var csrp1 = new CommissionSplitRulePolicyEntity
            {
                Id       = Guid.NewGuid(),
                PolicyId = policy1.Id,
                CommissionSplitRuleId = csr2.Id
            };

            using (var context = new DataContext(options))
            {
                context.CommissionType.Add(commissionType);

                context.Policy.Add(policy1);

                context.CommissionSplitRule.Add(csr1);
                context.CommissionSplitRule.Add(csr2);

                context.CommissionSplitRulePolicy.Add(csrp1);

                context.SaveChanges();

                var auditService                     = new AuditServiceMock();
                var statementService                 = new CommissionStatementService(context, null, auditService);
                var lookupService                    = new DirectoryLookupService(context);
                var commissionLookupService          = new CommissionLookupService(context);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var commissionService                = new CommissionService(context, auditService);

                var bulkActions         = new Mock <IBulkActions>(MockBehavior.Strict);
                var insertedCommissions = new List <CommissionEntity>();
                bulkActions.Setup(c => c.BulkInsertCommissionsAsync(It.IsAny <DataContext>(), It.IsAny <IList <CommissionEntity> >()))
                .Callback((DataContext c, IList <CommissionEntity> l) => insertedCommissions = l.ToList())
                .Returns(Task.CompletedTask);

                var service = new CommissionImportService(
                    context,
                    bulkActions.Object,
                    statementService,
                    policyService,
                    lookupService,
                    commissionLookupService,
                    commissionSplitService,
                    commissionSplitRulePolicyService,
                    auditService);

                //When
                var import1 = new ImportCommission
                {
                    PolicyNumber       = policy1.Number,
                    CommissionTypeCode = commissionType.Code,
                    AmountIncludingVAT = "120",
                    VAT = "12"
                };

                var scope        = TestHelper.GetScopeOptions(user1);
                var importResult = (await service.ImportCommissions(scope, statement.Id, new List <ImportCommission>()
                {
                    import1
                }));

                var result = importResult.Results.Single();

                //Then
                Assert.True(result.Success);

                Assert.Equal(2, insertedCommissions.Count);

                var actual = insertedCommissions[0];
                Assert.Equal(policy1.Id, actual.PolicyId);
                Assert.Equal(commissionType.Id, actual.CommissionTypeId);
                Assert.Equal(60, actual.AmountIncludingVAT);
                Assert.Equal(6, actual.VAT);
                Assert.Equal(statement.Id, actual.CommissionStatementId);
                Assert.Equal(import1, actual.SourceData);

                actual = insertedCommissions[1];
                Assert.Equal(policy1.Id, actual.PolicyId);
                Assert.Equal(commissionType.Id, actual.CommissionTypeId);
                Assert.Equal(60, actual.AmountIncludingVAT);
                Assert.Equal(6, actual.VAT);
                Assert.Equal(statement.Id, actual.CommissionStatementId);
                Assert.Equal(import1, actual.SourceData);
            }
        }
コード例 #6
0
        public async Task ImportCommission_InsertCommission_NegitiveAmmount()
        {
            var options = TestHelper.GetDbContext("ImportCommission_InsertCommission_NegitiveAmmount");

            var user1   = TestHelper.InsertUserDetailed(options);
            var client1 = TestHelper.InsertClient(options, user1.Organisation);

            var company   = TestHelper.InsertCompany(options);
            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation, company.Id);

            var commissionType = new CommissionTypeEntity
            {
                Id   = Guid.NewGuid(),
                Code = "gap_cover"
            };

            var policy1 = new PolicyEntity
            {
                Id            = Guid.NewGuid(),
                Number        = Guid.NewGuid().ToString(),
                CompanyId     = company.Id,
                ClientId      = client1.Client.Id,
                UserId        = user1.User.Id,
                NumberAliases = new List <string>(),
            };

            using (var context = new DataContext(options))
            {
                context.CommissionType.Add(commissionType);
                context.Policy.Add(policy1);
                context.SaveChanges();

                var auditService                     = new AuditServiceMock();
                var statementService                 = new CommissionStatementService(context, null, auditService);
                var lookupService                    = new DirectoryLookupService(context);
                var commissionLookupService          = new CommissionLookupService(context);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var commissionService                = new CommissionService(context, auditService);

                var bulkActions         = new Mock <IBulkActions>(MockBehavior.Strict);
                var insertedCommissions = new List <CommissionEntity>();
                bulkActions.Setup(c => c.BulkInsertCommissionsAsync(It.IsAny <DataContext>(), It.IsAny <IList <CommissionEntity> >()))
                .Callback((DataContext c, IList <CommissionEntity> l) => insertedCommissions = l.ToList())
                .Returns(Task.CompletedTask);

                var service = new CommissionImportService(
                    context,
                    bulkActions.Object,
                    statementService,
                    policyService,
                    lookupService,
                    commissionLookupService,
                    commissionSplitService,
                    commissionSplitRulePolicyService,
                    auditService);

                //When
                var import1 = new ImportCommission
                {
                    PolicyNumber       = policy1.Number,
                    CommissionTypeCode = commissionType.Code,
                    AmountIncludingVAT = "-100",
                    VAT = "-14"
                };

                var scope        = TestHelper.GetScopeOptions(user1);
                var importResult = (await service.ImportCommissions(scope, statement.Id, new List <ImportCommission>()
                {
                    import1
                }));

                var result = importResult.Results.Single();

                //Then
                Assert.True(result.Success);

                var actual = insertedCommissions.Single();
                Assert.Equal(policy1.Id, actual.PolicyId);
                Assert.Equal(commissionType.Id, actual.CommissionTypeId);
                Assert.Equal(-100, actual.AmountIncludingVAT);
                Assert.Equal(-14, actual.VAT);
                Assert.Equal(statement.Id, actual.CommissionStatementId);
                Assert.Equal(import1, actual.SourceData);
                Assert.Equal(policy1.UserId, actual.UserId);
                Assert.Null(actual.SplitGroupId);
            }
        }
コード例 #7
0
        public async Task ImportCommissions_ScopeCheck()
        {
            var options = TestHelper.GetDbContext("ImportCommissions_ScopeCheck");

            var user1     = TestHelper.InsertUserDetailed(options);
            var statement = TestHelper.InsertCommissionStatement(options, user1.Organisation);

            var user2 = TestHelper.InsertUserDetailed(options);

            using (var context = new DataContext(options))
            {
                var auditService                     = new AuditServiceMock();
                var lookupService                    = new DirectoryLookupService(context);
                var commissionLookupService          = new CommissionLookupService(context);
                var policyService                    = new PolicyService(context, auditService);
                var commissionSplitService           = new CommissionSplitService(context, auditService);
                var commissionSplitRulePolicyService = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService);
                var statementService                 = new CommissionStatementService(context, null, auditService);

                var bulkActions = new Mock <IBulkActions>(MockBehavior.Strict);
                bulkActions.Setup(c => c.BulkInsertCommissionErrorsAsync(It.IsAny <DataContext>(), It.IsAny <IList <CommissionErrorEntity> >()))
                .Returns(Task.CompletedTask);

                var service = new CommissionImportService(
                    context,
                    bulkActions.Object,
                    statementService,
                    policyService,
                    lookupService,
                    commissionLookupService,
                    commissionSplitService,
                    commissionSplitRulePolicyService,
                    auditService);

                //When
                var import1 = new ImportCommission
                {
                    PolicyNumber       = "123456",
                    CommissionTypeCode = "gap_cover",
                    AmountIncludingVAT = "abc",
                    VAT = "zzz"
                };

                var imports = new List <ImportCommission>()
                {
                    import1
                };

                var scope  = TestHelper.GetScopeOptions(user2);
                var result = await service.ImportCommissions(scope, statement.Id, imports);

                //Then
                Assert.Equal(0, result.ImportCount);
                Assert.Equal(0, result.ErrorCount);
                Assert.Empty(result.Results);

                scope  = TestHelper.GetScopeOptions(user1);
                result = await service.ImportCommissions(scope, statement.Id, imports);

                //Then
                Assert.Equal(0, result.ImportCount);
                Assert.Equal(1, result.ErrorCount);
                Assert.Single(result.Results);
            }
        }
        public async Task GetDefaultConfig()
        {
            var options = TestHelper.GetDbContext("GetDefaultConfig");

            var ct1 = new CommissionTypeEntity
            {
                Id   = Guid.NewGuid(),
                Name = "Type 1",
                Code = "type_1"
            };

            var ct2 = new CommissionTypeEntity
            {
                Id   = Guid.NewGuid(),
                Name = "Type 2",
                Code = "type_2"
            };

            using (var context = new DataContext(options))
            {
                context.CommissionType.Add(ct1);
                context.CommissionType.Add(ct2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var lookupService = new CommissionLookupService(context);
                var service       = new CommissionStatementTemplateService(context, lookupService, null);

                //When
                var config = await service.GetDefaultConfig();

                var sheetConfig = config.Sheets.Single().Config;

                //Then
                Assert.Equal("", sheetConfig.HeaderIdentifier.Column);
                Assert.Equal("", sheetConfig.HeaderIdentifier.Value);

                var importCommissionProps = typeof(ImportCommission).GetProperties();
                var fields = sheetConfig.Fields.ToList();
                Assert.Equal(importCommissionProps.Count() - 4, fields.Count()); //minus 4 for Id, Currency, CommissionTypeValue and CommissionTypeCode
                Assert.Equal("PolicyNumber", fields[0].Name);
                Assert.Equal("A", fields[0].Column);
                Assert.Equal("AmountIncludingVAT", fields[1].Name);
                Assert.Equal("B", fields[1].Column);
                Assert.Equal("VAT", fields[2].Name);
                Assert.Equal("C", fields[2].Column);
                Assert.Equal("LastName", fields[3].Name);
                Assert.Equal("E", fields[3].Column);
                Assert.Equal("DateOfBirth", fields[4].Name);
                Assert.Equal("F", fields[4].Column);
                Assert.Equal("FirstName", fields[5].Name);
                Assert.Equal("G", fields[5].Column);
                Assert.Equal("IdNumber", fields[6].Name);
                Assert.Equal("H", fields[6].Column);
                Assert.Equal("Initials", fields[7].Name);
                Assert.Equal("I", fields[7].Column);
                Assert.Equal("FullName", fields[8].Name);
                Assert.Equal("J", fields[8].Column);
                Assert.Equal("BrokerFullName", fields[9].Name);
                Assert.Equal("K", fields[9].Column);

                Assert.Equal("D", sheetConfig.CommissionTypes.MappingTemplate);
                Assert.Equal("unknown", sheetConfig.CommissionTypes.DefaultCommissionTypeCode);
                var types = sheetConfig.CommissionTypes.Types.ToList();
                Assert.Equal("type_1", types[0].CommissionTypeCode);
                Assert.Equal("type_1", types[0].Value);
                Assert.Equal("type_2", types[1].CommissionTypeCode);
                Assert.Equal("type_2", types[1].Value);
            }
        }