Exemplo n.º 1
0
        public async Task ImportClient_Insert_WithAlternateIdNumber()
        {
            var options = TestHelper.GetDbContext("ImportClient_Insert_WithAlternateIdNumber");

            var user1 = TestHelper.InsertUserDetailed(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber = "123456" //Not a valid id number so should be treated as a passport number
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.AlternateIdNumber == data.IdNumber);

                Assert.Null(actual.IdNumber);
            }
        }
Exemplo n.º 2
0
        public async Task ImportClient_Update_LastNameAndDateOfBirth()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update_LastNameAndDateOfBirth");

            var user1 = TestHelper.InsertUserDetailed(options);

            var mem1 = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                OrganisationId = user1.Organisation.Id
            };

            var mem2 = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                FirstName      = "FN 1",
                LastName       = "van Jones",
                IdNumber       = "8210035032082",
                DateOfBirth    = new DateTime(1982, 10, 3),
                OrganisationId = user1.Organisation.Id
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(mem1);
                context.Client.Add(mem2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    FirstName   = "FN 1 Updated",
                    LastName    = mem2.LastName,
                    DateOfBirth = mem2.DateOfBirth
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == mem2.IdNumber);

                Assert.Equal(data.FirstName, actual.FirstName);
            }
        }
        public async Task InsertPolicyTypeCharacteristic()
        {
            var options = TestHelper.GetDbContext("InsertPolicyTypeCharacteristic");

            //Given
            var model = new PolicyTypeCharacteristic()
            {
                Name         = "1",
                DisplayOrder = 1,
                PolicyTypeId = Guid.NewGuid()
            };

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

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

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

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

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.DisplayOrder, actual.DisplayOrder);
                Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId);
            }
        }
        public async Task InsertPolicyProduct()
        {
            var options = TestHelper.GetDbContext("InsertPolicyProduct");

            //Given
            var model = new PolicyProduct()
            {
                Name = "1",
                Code = "one",
                PolicyProductTypeId = Guid.NewGuid(),
                CompanyId           = Guid.NewGuid()
            };

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

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

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

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

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
                Assert.Equal(model.PolicyProductTypeId, actual.PolicyProductTypeId);
                Assert.Equal(model.CompanyId, actual.CompanyId);
            }
        }
Exemplo n.º 5
0
        public async Task ImportClient_Insert_With3MissingZeroOnIdNumber()
        {
            var options = TestHelper.GetDbContext("ImportClient_Insert_With3MissingZeroOnIdNumber");

            var user1 = TestHelper.InsertUserDetailed(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber = "7287372085" //missing leading zero
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == "0007287372085");

                Assert.NotNull(actual);
            }
        }
Exemplo n.º 6
0
        public async Task ImportClient_InsertPolicy_CheckUserAlias()
        {
            var options = TestHelper.GetDbContext("ImportClient_InsertPolicy_CheckUserAlias");

            var organisation = TestHelper.InsertOrganisation(options);

            var user = new UserEdit
            {
                Id        = Guid.NewGuid(),
                FirstName = "Dean",
                LastName  = "van Niekerk",
                Aliases   = new List <string>()
                {
                    "DJVANNiekerk"
                }
            };

            var user1 = TestHelper.InsertUserDetailed(options, organisation, user);

            var company = TestHelper.InsertCompany(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var policyService          = new PolicyService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber           = "12345",
                    LastName           = "LN",
                    PolicyNumber       = "987654",
                    PolicyCompanyId    = company.Id,
                    PolicyUserFullName = "DjvanNiekerk"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Policy.FirstOrDefaultAsync(m => m.Number == data.PolicyNumber);

                Assert.Equal(data.PolicyCompanyId, actual.CompanyId);
                Assert.Equal(user1.User.Id, actual.UserId);
            }
        }
Exemplo n.º 7
0
        public async Task ImportClient_Update_MatchOnShortIdNumber()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update_MatchOnShortIdNumber");

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

            var mem = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                LastName       = "LN 1",
                IdNumber       = "8201015800184",
                OrganisationId = user1.Organisation.Id
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(mem);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber = "8201015800085",
                    LastName = "LN updated",
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.Id == mem.Id);

                Assert.Equal(user1.Organisation.Id, actual.OrganisationId);
                Assert.Equal(data.LastName, actual.LastName);
            }
        }
        public async Task InsertPolicyProductType()
        {
            var options = TestHelper.GetDbContext("InsertPolicyProductType");

            var policyType = TestHelper.InsertPolicyType(options);

            var char1 = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "A", DisplayOrder = 0, PolicyTypeId = policyType.Id
            };
            var charDesc1 = new PolicyTypeCharacteristicDescription()
            {
                PolicyTypeCharacteristicId = char1.Id, Description = "Description 1"
            };

            using (var context = new DataContext(options))
            {
                context.PolicyTypeCharacteristic.Add(char1);
                context.SaveChanges();
            }

            //Given
            var model = new PolicyProductType()
            {
                Name         = "1",
                Code         = "one",
                PolicyTypeId = policyType.Id,
                PolicyTypeCharacteristics = new List <PolicyTypeCharacteristicDescription>()
                {
                    charDesc1
                }
            };

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

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

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

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

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
                Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId);
                Assert.Equal(model.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId, actual.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId);
            }
        }
Exemplo n.º 9
0
        public async Task ImportClient_Update_WithAlternateIdNumber()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update_WithAlternateIdNumber");

            var user1 = TestHelper.InsertUserDetailed(options);

            var mem = new ClientEntity
            {
                Id                = Guid.NewGuid(),
                FirstName         = "FN 1",
                LastName          = "LN 1",
                AlternateIdNumber = "123456",
                OrganisationId    = user1.Organisation.Id
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(mem);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber = "123456", //Not a valid id number so should be treated as a passport number
                    LastName = "LN updated"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.AlternateIdNumber == data.IdNumber);

                Assert.Equal(data.LastName, actual.LastName);
            }
        }
Exemplo n.º 10
0
        public async Task ImportClient_InsertPolicy()
        {
            var options = TestHelper.GetDbContext("ImportClient_InsertPolicy");

            var user1 = TestHelper.InsertUserDetailed(options);

            var policyType1 = TestHelper.InsertPolicyType(options);
            var policyType2 = TestHelper.InsertPolicyType(options);

            var company = TestHelper.InsertCompany(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var policyService          = new PolicyService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber           = "12345",
                    LastName           = "LN",
                    PolicyNumber       = "987654",
                    PolicyCompanyId    = company.Id,
                    PolicyTypeCode     = policyType2.Code,
                    PolicyPremium      = 5000,
                    PolicyStartDate    = DateTime.Now,
                    PolicyUserFullName = $"{user1.User.FirstName} {user1.User.LastName}"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Policy.FirstOrDefaultAsync(m => m.Number == data.PolicyNumber);

                Assert.Equal(data.PolicyCompanyId, actual.CompanyId);
                Assert.Equal(user1.User.Id, actual.UserId);
                Assert.Equal(data.PolicyPremium, actual.Premium);
                Assert.Equal(data.PolicyStartDate, actual.StartDate);
                Assert.Equal(policyType2.Id, actual.PolicyTypeId);
            }
        }
        public async Task GetPolicyProducts()
        {
            var options = TestHelper.GetDbContext("GetPolicyProducts");

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

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

                context.SaveChanges();
            }

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

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

                //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.PolicyProductTypeId, actual1.PolicyProductTypeId);
                Assert.Equal(lkp1.CompanyId, actual1.CompanyId);

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

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
        public async Task GetPolicyTypeCharacteristics()
        {
            var options = TestHelper.GetDbContext("GetPolicyTypeCharacteristics");

            //Given
            var policyTypeId = Guid.NewGuid();
            var lkp1         = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "A", DisplayOrder = 0, PolicyTypeId = policyTypeId
            };
            var lkp2 = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "B", DisplayOrder = 1, PolicyTypeId = policyTypeId
            };
            var lkp3 = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "C", DisplayOrder = 2, PolicyTypeId = policyTypeId
            };

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

                context.SaveChanges();
            }

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

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

                //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.DisplayOrder, actual1.DisplayOrder);
                Assert.Equal(lkp1.PolicyTypeId, actual1.PolicyTypeId);

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

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
Exemplo n.º 13
0
        public async Task ImportClient_Update_MatchOnPolicyNumber()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update_MatchOnPolicyNumber");

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

            var client2 = TestHelper.InsertClient(options, user1.Organisation);
            var client1 = TestHelper.InsertClient(options, user1.Organisation, "8210035032082");

            var company = TestHelper.InsertCompany(options);

            var policy2 = TestHelper.InsertPolicy(options, client2, user1, company.Id);
            var policy1 = TestHelper.InsertPolicy(options, client1, user1, company.Id);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var policyService          = new PolicyService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber           = "",
                    LastName           = "LN updated",
                    PolicyNumber       = policy1.Number,
                    PolicyCompanyId    = company.Id,
                    PolicyUserFullName = user1.User.FirstName + " " + user1.User.LastName
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.Id == client1.Client.Id);

                Assert.Equal(user1.Organisation.Id, actual.OrganisationId);
                Assert.Equal(data.LastName, actual.LastName);
            }
        }
        public async Task GetMarrialStatus()
        {
            var options = TestHelper.GetDbContext("GetMarrialStatus");

            //Given
            var lkp1 = new MarritalStatusEntity {
                Id = Guid.NewGuid(), Name = "A"
            };
            var lkp2 = new MarritalStatusEntity {
                Id = Guid.NewGuid(), Name = "B"
            };
            var lkp3 = new MarritalStatusEntity {
                Id = Guid.NewGuid(), Name = "C"
            };

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

                context.SaveChanges();
            }

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

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

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

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

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

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
Exemplo n.º 15
0
        public async Task ImportClient_Insert()
        {
            var options = TestHelper.GetDbContext("ImportClient_Insert");

            var user1 = TestHelper.InsertUserDetailed(options);

            var clientType = TestHelper.InsertClientTypeIndividual(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber       = "821003 5032 082",
                    FirstName      = "FN",
                    LastName       = "LN",
                    TaxNumber      = "987654",
                    DateOfBirth    = DateTime.Now,
                    ClientTypeCode = clientType.Code
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == "8210035032082");

                Assert.Null(actual.AlternateIdNumber);
                Assert.Equal(clientType.Id, actual.ClientTypeId);
                Assert.Equal(user1.Organisation.Id, actual.OrganisationId);
                Assert.Equal(data.LastName, actual.LastName);
                Assert.Equal(data.FirstName, actual.FirstName);
                Assert.Equal(data.TaxNumber, actual.TaxNumber);
                Assert.Equal(data.DateOfBirth, actual.DateOfBirth);
            }
        }
        public async Task UpdatePolicyProduct()
        {
            var options = TestHelper.GetDbContext("UpdatePolicyProduct");

            //Given
            var lkp1 = new PolicyProductEntity {
                Id = Guid.NewGuid(), Name = "1", Code = "aa", PolicyProductTypeId = Guid.NewGuid(), CompanyId = Guid.NewGuid()
            };

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

                context.SaveChanges();
            }

            var model = new PolicyProduct()
            {
                Id   = lkp1.Id,
                Name = "1 Updated",
                Code = "aa Updated",
                PolicyProductTypeId = Guid.NewGuid(),
                CompanyId           = Guid.NewGuid()
            };

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

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

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

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

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
                Assert.Equal(model.PolicyProductTypeId, actual.PolicyProductTypeId);
                Assert.Equal(model.CompanyId, actual.CompanyId);
            }
        }
Exemplo n.º 17
0
        public async Task ImportClient_Insert_NoIdButHasPolicyNumber_UnknowClientType()
        {
            var options = TestHelper.GetDbContext("ImportClient_Insert_NoIdButHasPolicyNumber_UnknowClientType");

            var user1 = TestHelper.InsertUserDetailed(options);

            var company = TestHelper.InsertCompany(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var policyService          = new PolicyService(context, auditService);
                var contactService         = new ContactService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, policyService, contactService, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber           = "",
                    PolicyNumber       = "123456798",
                    LastName           = "Some Business",
                    PolicyCompanyId    = company.Id,
                    PolicyUserFullName = user1.User.FirstName + " " + user1.User.LastName
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync();

                Assert.Null(actual.IdNumber);
                Assert.Equal(data.LastName, actual.LastName);
                Assert.Equal(ClientType.CLIENT_TYPE_UNKNOWN_ENTITY, actual.ClientTypeId);
            }
        }
        public async Task UpdatePolicyTypeCharacteristic()
        {
            var options = TestHelper.GetDbContext("UpdatePolicyTypeCharacteristic");

            //Given
            var lkp1 = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "1", DisplayOrder = 1, PolicyTypeId = Guid.NewGuid()
            };

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

                context.SaveChanges();
            }

            var model = new PolicyTypeCharacteristic()
            {
                Id           = lkp1.Id,
                Name         = "1 Updated",
                DisplayOrder = 2,
                PolicyTypeId = Guid.NewGuid()
            };

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

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

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

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

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.DisplayOrder, actual.DisplayOrder);
                Assert.Equal(model.PolicyTypeId, actual.PolicyTypeId);
            }
        }
Exemplo n.º 19
0
        public async Task ImportClient_InsertUnknownEntity()
        {
            var options = TestHelper.GetDbContext("ImportClient_InsertUnknownEntity");

            var user1 = TestHelper.InsertUserDetailed(options);

            var clientType = TestHelper.InsertClientTypeUnknown(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    LastName       = "Unknown Here",
                    ClientTypeCode = clientType.Code
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync();

                Assert.Null(actual.AlternateIdNumber);
                Assert.Null(actual.FirstName);
                Assert.Equal(clientType.Id, actual.ClientTypeId);
                Assert.Equal(user1.Organisation.Id, actual.OrganisationId);
                Assert.Equal(data.LastName, actual.LastName);
            }
        }
Exemplo n.º 20
0
        public async Task ImportClient_Insert_WithCellphone()
        {
            var options = TestHelper.GetDbContext("ImportClient_Insert_WithCellphone");

            var user1 = TestHelper.InsertUserDetailed(options);

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var contactService         = new ContactService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, contactService, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber  = "8210035032082",
                    Cellphone = "082-572 8997"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var client = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == data.IdNumber);

                var actual = await context.Contact.SingleOrDefaultAsync(c => c.ClientId == client.Id);

                Assert.Equal("0825728997", actual.Value);
                Assert.Equal(ContactType.CONTACT_TYPE_CELLPHONE, actual.ContactTypeId);
            }
        }
        public async Task GetPolicyProductTypes()
        {
            var options = TestHelper.GetDbContext("GetPolicyProductTypes");

            var policyType = TestHelper.InsertPolicyType(options);

            var char1 = new PolicyTypeCharacteristicEntity {
                Id = Guid.NewGuid(), Name = "A", DisplayOrder = 0, PolicyTypeId = policyType.Id
            };
            var charDesc1 = new PolicyTypeCharacteristicDescription()
            {
                PolicyTypeCharacteristicId = char1.Id, Description = "Description 1"
            };

            //Given
            var lkp1 = new PolicyProductTypeEntity
            {
                Id           = Guid.NewGuid(),
                Name         = "A",
                Code         = "aa",
                PolicyTypeId = policyType.Id,
                PolicyTypeCharacteristics = new List <PolicyTypeCharacteristicDescription>()
                {
                    charDesc1
                }
            };
            var lkp2 = new PolicyProductTypeEntity {
                Id = Guid.NewGuid(), Name = "B", Code = "bb", PolicyTypeId = policyType.Id
            };
            var lkp3 = new PolicyProductTypeEntity {
                Id = Guid.NewGuid(), Name = "C", Code = "cc", PolicyTypeId = policyType.Id
            };

            using (var context = new DataContext(options))
            {
                context.PolicyTypeCharacteristic.Add(char1);

                //Jumbled order
                context.PolicyProductType.Add(lkp2);
                context.PolicyProductType.Add(lkp1);
                context.PolicyProductType.Add(lkp3);

                context.SaveChanges();
            }

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

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

                //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.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId, actual1.PolicyTypeCharacteristics.Single().PolicyTypeCharacteristicId);

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

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
Exemplo n.º 22
0
        public async Task ImportClient_UpdatePolicy()
        {
            var options = TestHelper.GetDbContext("ImportClient_UpdatePolicy");

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

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

            var policyType1 = TestHelper.InsertPolicyType(options);
            var policyType2 = TestHelper.InsertPolicyType(options);

            var company = TestHelper.InsertCompany(options);

            //Given
            var policyEntity1 = new PolicyEntity
            {
                Id           = Guid.NewGuid(),
                CompanyId    = company.Id,
                ClientId     = client1.Client.Id,
                UserId       = user2.User.Id,
                PolicyTypeId = policyType2.Id,
                Premium      = 2000,
                StartDate    = DateTime.Now,
                Number       = "123465"
            };

            using (var context = new DataContext(options))
            {
                context.Policy.Add(policyEntity1);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var policyService          = new PolicyService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber           = client1.Client.IdNumber,
                    LastName           = "LN",
                    PolicyNumber       = policyEntity1.Number,
                    PolicyCompanyId    = policyEntity1.CompanyId,
                    PolicyTypeCode     = policyType1.Code,
                    PolicyPremium      = 6000,
                    PolicyStartDate    = DateTime.Now.AddDays(-100),
                    PolicyUserFullName = $"{user1.User.FirstName} {user1.User.LastName}"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Policy.FirstOrDefaultAsync(m => m.Number == data.PolicyNumber);

                Assert.Equal(data.PolicyCompanyId, actual.CompanyId);
                Assert.Equal(user1.User.Id, actual.UserId);
                Assert.Equal(data.PolicyPremium, actual.Premium);
                Assert.Equal(data.PolicyStartDate, actual.StartDate);
                Assert.Equal(policyType1.Id, actual.PolicyTypeId);
            }
        }
Exemplo n.º 23
0
        public async Task ImportClient_Update()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update");

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

            var mem = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                FirstName      = "FN 1",
                LastName       = "LN 1",
                TaxNumber      = "987654",
                DateOfBirth    = DateTime.Now,
                IdNumber       = "8210035032082",
                OrganisationId = user1.Organisation.Id
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(mem);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber    = mem.IdNumber,
                    FirstName   = "FN updated",
                    LastName    = "LN updated",
                    TaxNumber   = "456789",
                    DateOfBirth = DateTime.Now.AddDays(-20),
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == data.IdNumber);

                Assert.Equal(user1.Organisation.Id, actual.OrganisationId);
                Assert.Equal(mem.ClientTypeId, actual.ClientTypeId); //Should not have changed
                Assert.Equal(data.FirstName, actual.FirstName);
                Assert.Equal(data.LastName, actual.LastName);
                Assert.Equal(data.TaxNumber, actual.TaxNumber);
                Assert.Equal(data.DateOfBirth, actual.DateOfBirth);
            }
        }
Exemplo n.º 24
0
        public async Task ImportClient_Update_WithContacts()
        {
            var options = TestHelper.GetDbContext("ImportClient_Update_WithContacts");

            var user1 = TestHelper.InsertUserDetailed(options);

            var mem = new ClientEntity
            {
                Id             = Guid.NewGuid(),
                ClientTypeId   = ClientType.CLIENT_TYPE_INDIVIDUAL,
                IdNumber       = "8210035032082",
                OrganisationId = user1.Organisation.Id
            };

            var contact1 = new ContactEntity
            {
                ClientId      = mem.Id,
                ContactTypeId = ContactType.CONTACT_TYPE_EMAIL,
                Value         = "*****@*****.**"
            };

            var contact2 = new ContactEntity
            {
                ClientId      = mem.Id,
                ContactTypeId = ContactType.CONTACT_TYPE_CELLPHONE,
                Value         = "0825728997"
            };

            using (var context = new DataContext(options))
            {
                context.Client.Add(mem);
                context.Contact.Add(contact1);
                context.Contact.Add(contact2);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var auditService           = new AuditServiceMock();
                var clientService          = new ClientService(context, auditService);
                var contactService         = new ContactService(context, auditService);
                var lookupService          = new ClientLookupService(context);
                var directoryLookupService = new DirectoryLookupService(context);
                var service = new ClientImportService(context, clientService, null, contactService, lookupService, directoryLookupService);

                //When
                var data = new ImportClient()
                {
                    IdNumber  = "8210035032082",
                    Email     = contact1.Value,
                    Cellphone = "082 572-8997"
                };

                var scope = TestHelper.GetScopeOptions(user1);

                var result = await service.ImportClient(scope, data);

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

                var client = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == data.IdNumber);

                var contacts = await context.Contact.Where(c => c.ClientId == client.Id).ToListAsync();

                Assert.Equal(2, contacts.Count);
                var actual = contacts.First();
                Assert.Equal(data.Email, actual.Value);
                Assert.Equal(ContactType.CONTACT_TYPE_EMAIL, actual.ContactTypeId);

                actual = contacts.Last();
                Assert.Equal(contact2.Value, actual.Value);
                Assert.Equal(ContactType.CONTACT_TYPE_CELLPHONE, actual.ContactTypeId);
            }
        }