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); } }
public async Task InsertClient_GetDOBFromId_FutureCheck() { var options = TestHelper.GetDbContext("InsertClient_GetDOBFromId_FutureCheck"); var user1 = TestHelper.InsertUserDetailed(options); //Given var client = new ClientEdit() { ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, FirstName = "FN 1", LastName = "LN 1", IdNumber = "2901014800087", //yes this test will break after 2029... }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1, Scope.User); var result = await service.InsertClient(scope, client); //Then Assert.True(result.Success); var actual = await context.Client.FindAsync(((ClientEdit)result.Tag).Id); Assert.Equal(client.Id, actual.Id); Assert.Equal(client.ClientTypeId, actual.ClientTypeId); Assert.Equal(client.IdNumber, actual.IdNumber); Assert.Equal(DateTime.Parse("1929-01-01"), actual.DateOfBirth); } }
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); } }
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 InsertClient_GetDOBFromId() { var options = TestHelper.GetDbContext("InsertClient_GetDOBFromId"); var user1 = TestHelper.InsertUserDetailed(options); //Given var client = new ClientEdit() { ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, FirstName = "FN 1", LastName = "LN 1", IdNumber = "8210035032082", }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1, Scope.User); var result = await service.InsertClient(scope, client); //Then Assert.True(result.Success); var actual = await context.Client.FindAsync(((ClientEdit)result.Tag).Id); Assert.Equal(client.Id, actual.Id); Assert.Equal(client.ClientTypeId, actual.ClientTypeId); Assert.Equal(client.IdNumber, actual.IdNumber); Assert.Equal(DateTime.Parse("1982-10-03"), actual.DateOfBirth); } }
public async Task InsertPolicy() { var options = TestHelper.GetDbContext("InsertPolicy"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); //Given var policy1 = new PolicyEdit { Id = Guid.NewGuid(), CompanyId = Guid.NewGuid(), ClientId = client1.Client.Id, UserId = user1.User.Id, Number = "123465", StartDate = DateTime.Now, Premium = 500, PolicyTypeId = Guid.NewGuid(), PolicyProductTypeId = Guid.NewGuid(), PolicyProductId = Guid.NewGuid(), IsActive = true, }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new PolicyService(context, auditService); //When var scopeOptions = TestHelper.GetScopeOptions(user1); var result = await service.InsertPolicy(scopeOptions, policy1); //Then Assert.True(result.Success); var actual = await context.Policy.FindAsync(((PolicyEdit)result.Tag).Id); Assert.Equal(policy1.Id, actual.Id); Assert.Equal(policy1.ClientId, actual.ClientId); Assert.Equal(policy1.CompanyId, actual.CompanyId); Assert.Equal(policy1.Number, actual.Number); Assert.Equal(policy1.StartDate, actual.StartDate); Assert.Equal(policy1.Premium, actual.Premium); Assert.Equal(policy1.PolicyTypeId, actual.PolicyTypeId); Assert.Equal(policy1.PolicyProductTypeId, actual.PolicyProductTypeId); Assert.Equal(policy1.PolicyProductId, actual.PolicyProductId); Assert.Equal(policy1.IsActive, actual.IsActive); //Out of scope scopeOptions = TestHelper.GetScopeOptions(user2); result = await service.InsertPolicy(scopeOptions, policy1); Assert.False(result.Success); Assert.Equal("'User' does not exist.", result.ValidationFailures.First().ErrorMessage); } }
public async Task GetCommissionSplitRulePolicy() { var options = TestHelper.GetDbContext("GetCommissionSplitRulePolicy"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); var policy1 = new PolicyEntity { Id = Guid.NewGuid(), CompanyId = Guid.NewGuid(), ClientId = client1.Client.Id, UserId = user1.User.Id, Number = "123465", }; var csr1 = new CommissionSplitRulePolicyEntity { Id = Guid.NewGuid(), PolicyId = policy1.Id, CommissionSplitRuleId = Guid.NewGuid() }; using (var context = new DataContext(options)) { context.Policy.Add(policy1); context.CommissionSplitRulePolicy.Add(csr1); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var commissionSplitService = new CommissionSplitService(context, auditService); var service = new CommissionSplitRulePolicyService(context, commissionSplitService, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var actual = await service.GetCommissionSplitRulePolicy(scope, csr1.PolicyId); //Then Assert.Equal(csr1.Id, actual.Id); Assert.Equal(csr1.PolicyId, actual.PolicyId); Assert.Equal(csr1.CommissionSplitRuleId, actual.CommissionSplitRuleId); //Check scope scope = TestHelper.GetScopeOptions(user2); actual = await service.GetCommissionSplitRulePolicy(scope, csr1.PolicyId); Assert.Null(actual.CommissionSplitRuleId); } }
public async Task UpdateBranch() { var options = TestHelper.GetDbContext("UpdateBranch"); var user1 = TestHelper.InsertUserDetailed(options); //Given var branch1 = new BranchEntity { Id = Guid.NewGuid(), Name = "Branch 1", OrganisationId = user1.Organisation.Id }; var branch2 = new BranchEntity { Id = Guid.NewGuid(), Name = "Branch 2", OrganisationId = Guid.NewGuid() }; using (var context = new DataContext(options)) { context.Branch.Add(branch1); context.Branch.Add(branch2); context.SaveChanges(); } var branch = new Branch() { Id = branch1.Id, OrganisationId = branch1.OrganisationId, Name = "Branch 1 Updated" }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new BranchService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.UpdateBranch(scope, branch); //Then Assert.True(result.Success); var actual = await context.Branch.FindAsync(branch.Id); Assert.Equal(branch.OrganisationId, actual.OrganisationId); Assert.Equal(branch.Name, actual.Name); //Scope check branch.Id = branch2.Id; branch.OrganisationId = branch2.OrganisationId; scope = TestHelper.GetScopeOptions(user1); result = await service.UpdateBranch(scope, branch); //Then Assert.False(result.Success); } }
public async Task GetUserSimple() { var options = TestHelper.GetDbContext("GetUserSimple"); var userDetailed1 = TestHelper.InsertUserDetailed(options); var userDetailed2 = TestHelper.InsertUserDetailed(options); var user1 = new UserEntity() { Id = Guid.NewGuid(), BranchId = userDetailed1.Branch.Id }; var user2 = new UserEntity() { Id = Guid.NewGuid(), FirstName = "Jack", LastName = "Reacher", BranchId = userDetailed1.Branch.Id, UserTypeId = Guid.NewGuid(), }; using (var context = new DataContext(options)) { context.Users.Add(user1); context.Users.Add(user2); context.SaveChanges(); } using (var context = new DataContext(options)) { var userManager = TestHelper.MockUserManager(context.Users.ToList()); var auditService = new AuditServiceMock(); var service = new UserService(context, userManager.Object, auditService); //When var scope = TestHelper.GetScopeOptions(userDetailed1, Scope.Organisation); var user = await service.GetUserSimple(scope, user2.Id); //Then Assert.Equal(user2.Id, user.Id); Assert.Equal(user2.FirstName, user.FirstName); Assert.Equal(user2.LastName, user.LastName); Assert.Equal(user2.BranchId, user.BranchId); Assert.Equal(user2.UserTypeId, user.UserTypeId); //Scope check scope = TestHelper.GetScopeOptions(userDetailed2, Scope.Organisation); user = await service.GetUserSimple(scope, user2.Id); Assert.Null(user); } }
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); } }
public async Task InsertClient() { var options = TestHelper.GetDbContext("InsertClient"); var user1 = TestHelper.InsertUserDetailed(options); //Given var client = new ClientEdit() { ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, FirstName = "FN 1", LastName = "LN 1", MaidenName = "MN 1", Initials = "INI 1", PreferredName = "PN 1", IdNumber = "8210035032082", DateOfBirth = new DateTime(1982, 10, 3), TaxNumber = "889977", MarritalStatusId = Guid.NewGuid(), MarriageDate = new DateTime(2009, 11, 13) }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1, Scope.User); var result = await service.InsertClient(scope, client); //Then Assert.True(result.Success); var actual = await context.Client.FindAsync(((ClientEdit)result.Tag).Id); Assert.Equal(client.Id, actual.Id); Assert.Equal(client.ClientTypeId, actual.ClientTypeId); Assert.Equal(user1.Organisation.Id, actual.OrganisationId); Assert.Equal(client.FirstName, actual.FirstName); Assert.Equal(client.LastName, actual.LastName); Assert.Equal(client.MaidenName, actual.MaidenName); Assert.Equal(client.Initials, actual.Initials); Assert.Equal(client.PreferredName, actual.PreferredName); Assert.Equal(client.IdNumber, actual.IdNumber); Assert.Equal(client.DateOfBirth, actual.DateOfBirth); Assert.Equal(client.TaxNumber, actual.TaxNumber); Assert.Equal(client.MarritalStatusId, actual.MarritalStatusId); Assert.Equal(client.MarriageDate, actual.MarriageDate); } }
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 DeleteContact() { var options = TestHelper.GetDbContext("DeleteContact"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); //Given var contactTypeId1 = Guid.NewGuid(); var contactTypeId2 = Guid.NewGuid(); var contact1 = new ContactEntity { Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "A Contact 1", ContactTypeId = contactTypeId1 }; var contact2 = new ContactEntity { Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "B Contact 2", ContactTypeId = contactTypeId1 }; using (var context = new DataContext(options)) { context.Contact.Add(contact2); context.Contact.Add(contact1); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ContactService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.DeleteContact(scope, contact1.Id); //Then Assert.True(result.Success); var actual = await context.Contact.FindAsync(contact1.Id); Assert.Null(actual); //Scope check scope = TestHelper.GetScopeOptions(user2); result = await service.DeleteContact(scope, contact1.Id); //Then Assert.False(result.Success); } }
public async Task InsertCommissionSplitRule() { var options = TestHelper.GetDbContext("InsertCommissionSplitRule"); var user1 = TestHelper.InsertUserDetailed(options); var user2 = TestHelper.InsertUserDetailed(options); using (var context = new DataContext(options)) { var csr1 = new CommissionSplitRule { UserId = user1.User.Id, Name = "Com Split Rule 1", IsDefault = true, Split = new List <CommissionSplit>() { new CommissionSplit() { UserId = user1.User.Id, Percentage = 100 } } }; var auditService = new AuditServiceMock(); var service = new CommissionSplitService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.InsertCommissionSplitRule(scope, csr1); //Then Assert.True(result.Success); var actual = await context.CommissionSplitRule.FindAsync(((CommissionSplitRule)result.Tag).Id); Assert.Equal(csr1.Id, actual.Id); Assert.Equal(csr1.Name, actual.Name); Assert.Equal(csr1.UserId, actual.UserId); Assert.Equal(csr1.IsDefault, actual.IsDefault); Assert.Equal(csr1.Split, actual.Split); //Out of scope scope = TestHelper.GetScopeOptions(user2, Scope.User); result = await service.InsertCommissionSplitRule(scope, csr1); Assert.False(result.Success); Assert.Equal("'User' does not exist.", result.ValidationFailures.First().ErrorMessage); } }
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); } }
public async Task GetContactWithValue() { var options = TestHelper.GetDbContext("GetContactWithValue"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); //Given var contactTypeId1 = Guid.NewGuid(); var contact1 = new ContactEntity { Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "*****@*****.**", ContactTypeId = contactTypeId1 }; var contact2 = new ContactEntity { Id = Guid.NewGuid(), ClientId = client1.Client.Id, Value = "*****@*****.**", ContactTypeId = contactTypeId1 }; using (var context = new DataContext(options)) { context.Contact.Add(contact1); context.Contact.Add(contact2); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ContactService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var actual = await service.GetContact(scope, client1.Client.Id, contact1.Value); //Then Assert.Equal(contact1.Id, actual.Id); Assert.Equal(contact1.ClientId, actual.ClientId); Assert.Equal(contact1.Value, actual.Value); Assert.Equal(contact1.ContactTypeId, actual.ContactTypeId); //Scope check scope = TestHelper.GetScopeOptions(user2); actual = await service.GetContact(scope, contact1.Id); //Then Assert.Null(actual); } }
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 GetClients_OrganisationLevel() { var options = TestHelper.GetDbContext("GetClients_OrganisationLevel"); var orgId1 = Guid.NewGuid(); var orgId2 = Guid.NewGuid(); //Given var client1 = new ClientEntity { Id = Guid.NewGuid(), OrganisationId = orgId1 }; var client2 = new ClientEntity { Id = Guid.NewGuid(), OrganisationId = orgId1 }; var client3 = new ClientEntity { Id = Guid.NewGuid(), OrganisationId = orgId2 }; using (var context = new DataContext(options)) { context.Client.Add(client1); context.Client.Add(client2); context.Client.Add(client3); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(orgId1); var queryOptions = new ClientQueryOptions(scope, "", "", 0, 0); var clients = await service.GetClients(queryOptions); //Then Assert.Equal(2, clients.TotalItems); Assert.Equal(2, clients.Items.Count()); var actual = clients.Items.First(); Assert.Equal(client1.Id, actual.Id); actual = clients.Items.Last(); Assert.Equal(client2.Id, actual.Id); } }
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 MergeClients_ScopeCheck() { var options = TestHelper.GetDbContext("MergeClients_ScopeCheck"); //Given var user = TestHelper.InsertUserDetailed(options); var clientSource1 = TestHelper.InsertClient(options, user.Organisation, "8210035032082"); var clientSource2 = TestHelper.InsertClient(options, user.Organisation); var user2 = TestHelper.InsertUserDetailed(options); var target = new ClientEdit { ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, IdNumber = "8210035032082" }; using (var context = new DataContext(options)) { context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); var merge = new MergeClients() { TargetClient = target, SourceClientIds = new List <Guid>() { clientSource1.Client.Id, clientSource2.Client.Id } }; //When var scope = TestHelper.GetScopeOptions(user2.Organisation.Id); var result = await service.MergeClients(scope, merge); //Then Assert.False(result.Success); Assert.Equal("SourceClientIds", result.ValidationFailures[0].PropertyName); Assert.Equal("Invalid Source Client Ids", result.ValidationFailures[0].ErrorMessage); } }
public async Task GetClients_Filter() { var options = TestHelper.GetDbContext("GetClients_Filter"); //Given var orgId1 = Guid.NewGuid(); var client1 = new ClientEntity { Id = Guid.NewGuid(), LastName = "van Niekerk", OrganisationId = orgId1 }; var client2 = new ClientEntity { Id = Guid.NewGuid(), LastName = "Jones", OrganisationId = orgId1 }; using (var context = new DataContext(options)) { context.Client.Add(client1); context.Client.Add(client2); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(orgId1); var queryOptions = new ClientQueryOptions(scope, "", "", 0, 0, "lastName=%nie%"); var clients = await service.GetClients(queryOptions); //Then Assert.Equal(1, clients.TotalItems); Assert.Single(clients.Items); var actual = clients.Items.First(); Assert.Equal(client1.Id, actual.Id); } }
public async Task DeleteCommissions() { var options = TestHelper.GetDbContext("UpdateCommissionStatement"); var user1 = TestHelper.InsertUserDetailed(options); var statement1 = TestHelper.InsertCommissionStatement(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); var statement2 = TestHelper.InsertCommissionStatement(options, user2.Organisation); using (var context = new DataContext(options)) { var bulkActions = new Mock <IBulkActions>(MockBehavior.Strict); var actualCommissionStatementId1 = Guid.Empty; bulkActions.Setup(c => c.BatchDeleteCommissionsAsync(It.IsAny <DataContext>(), It.IsAny <Guid>())) .Callback((DataContext c, Guid g1) => actualCommissionStatementId1 = g1) .Returns(Task.CompletedTask); var actualCommissionStatementId2 = Guid.Empty; bulkActions.Setup(c => c.BatchDeleteCommissionErrorsAsync(It.IsAny <DataContext>(), It.IsAny <Guid>())) .Callback((DataContext c, Guid g1) => actualCommissionStatementId2 = g1) .Returns(Task.CompletedTask); var auditService = new AuditServiceMock(); var service = new CommissionStatementService(context, bulkActions.Object, auditService); //When var scopeOptions = TestHelper.GetScopeOptions(user1); await service.DeleteCommissions(scopeOptions, statement1.Id); //Then Assert.Equal(statement1.Id, actualCommissionStatementId1); Assert.Equal(statement1.Id, actualCommissionStatementId2); //Reset actualCommissionStatementId1 = Guid.Empty; actualCommissionStatementId2 = Guid.Empty; // //Out of scope await service.DeleteCommissions(scopeOptions, statement2.Id); Assert.Equal(Guid.Empty, actualCommissionStatementId1); Assert.Equal(Guid.Empty, actualCommissionStatementId2); } }
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 GetBranch() { var options = TestHelper.GetDbContext("GetBranch"); var user1 = TestHelper.InsertUserDetailed(options); //Given var orgId2 = Guid.NewGuid(); var branch1 = new BranchEntity { Id = Guid.NewGuid(), OrganisationId = user1.Organisation.Id, Name = "Branch 1" }; var branch2 = new BranchEntity { Id = Guid.NewGuid(), OrganisationId = orgId2, Name = "Branch 2" }; using (var context = new DataContext(options)) { context.Branch.Add(branch1); context.Branch.Add(branch2); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new BranchService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var actual = await service.GetBranch(scope, branch1.Id); //Then Assert.Equal(branch1.Id, actual.Id); Assert.Equal(branch1.OrganisationId, actual.OrganisationId); Assert.Equal(branch1.Name, actual.Name); //Scope check scope = TestHelper.GetScopeOptions(user1); actual = await service.GetBranch(scope, branch2.Id); //Then Assert.Null(actual); } }
public async Task InsertContact() { var options = TestHelper.GetDbContext("InsertContact"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); //Given var contactTypeId1 = Guid.NewGuid(); var contact = new Contact() { ClientId = client1.Client.Id, ContactTypeId = contactTypeId1, Value = "A Contact 1" }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ContactService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.InsertContact(scope, contact); //Then Assert.True(result.Success); var actual = await context.Contact.FindAsync(((Contact)result.Tag).Id); Assert.Equal(contact.ClientId, actual.ClientId); Assert.Equal(contact.ContactTypeId, actual.ContactTypeId); Assert.Equal(contact.Value, actual.Value); //Scope check scope = TestHelper.GetScopeOptions(user2); result = await service.InsertContact(scope, contact); //Then Assert.False(result.Success); } }
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 InsertCommissionStatement() { var options = TestHelper.GetDbContext("InsertCommissionStatement"); var user1 = TestHelper.InsertUserDetailed(options); //Given var cs1 = new CommissionStatementEdit { CompanyId = Guid.NewGuid(), AmountIncludingVAT = 100, VAT = 10, Date = DateTime.Now, Processed = true, Notes = "note 1" }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new CommissionStatementService(context, null, auditService); //When var scopeOptions = TestHelper.GetScopeOptions(user1); var result = await service.InsertCommissionStatement(scopeOptions, cs1); //Then Assert.True(result.Success); var actual = await context.CommissionStatement.FindAsync(((CommissionStatementEdit)result.Tag).Id); Assert.Equal(cs1.CompanyId, actual.CompanyId); Assert.Equal(cs1.Date.Value.Date, actual.Date); Assert.Equal(cs1.AmountIncludingVAT, actual.AmountIncludingVAT); Assert.Equal(cs1.VAT, actual.VAT); Assert.Equal(user1.Organisation.Id, user1.Organisation.Id); Assert.Equal(cs1.Processed, actual.Processed); Assert.Equal(cs1.Notes, actual.Notes); } }
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); } }
public async Task DeleteClient() { var options = TestHelper.GetDbContext("DeleteClient"); var user1 = TestHelper.InsertUserDetailed(options); var client1 = TestHelper.InsertClient(options, user1.Organisation); var client2 = TestHelper.InsertClient(options, user1.Organisation); var user2 = TestHelper.InsertUserDetailed(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new ClientService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.DeleteClient(scope, client1.Client.Id); //Then Assert.True(result.Success); var actual = await context.Client.FindAsync(client1.Client.Id); Assert.True(actual.IsDeleted); var client = await service.GetClient(scope, client1.Client.Id); Assert.Null(client); //Scope check scope = TestHelper.GetScopeOptions(user2); result = await service.DeleteClient(scope, client2.Client.Id); //Then Assert.False(result.Success); } }
public async Task InsertBranch() { var options = TestHelper.GetDbContext("InsertBranch"); var user1 = TestHelper.InsertUserDetailed(options); //Given var branch = new Branch() { OrganisationId = user1.Organisation.Id, Name = "Branch 1" }; using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var service = new BranchService(context, auditService); //When var scope = TestHelper.GetScopeOptions(user1); var result = await service.InsertBranch(scope, branch); //Then Assert.True(result.Success); var actual = await context.Branch.FindAsync(((Branch)result.Tag).Id); Assert.Equal(branch.OrganisationId, actual.OrganisationId); Assert.Equal(branch.Name, actual.Name); //Scope check scope = TestHelper.GetScopeOptions(user1, Scope.Branch); result = await service.InsertBranch(scope, branch); //Then Assert.False(result.Success); } }