private async Task <List <EmployerInfo> > GetEmployerInfosAsync(ProviderPermissions providerPermissions) { var employerInfos = new List <EmployerInfo>(); var permittedEmployerAccounts = providerPermissions.AccountProviderLegalEntities.GroupBy(p => p.AccountId); foreach (var permittedEmployer in permittedEmployerAccounts) { var accountId = await _employerAccountProvider.GetEmployerAccountPublicHashedIdAsync(permittedEmployer.Key); var employerInfo = new EmployerInfo() { EmployerAccountId = accountId, Name = permittedEmployer.First().AccountName, //should be same in all the items hence read from first LegalEntities = new List <LegalEntity>() }; var legalEntityViewModels = await _employerAccountProvider.GetLegalEntitiesConnectedToAccountAsync(accountId); foreach (var permittedLegalEntity in permittedEmployer) { var matchingLegalEntity = legalEntityViewModels.FirstOrDefault(e => e.AccountLegalEntityPublicHashedId == permittedLegalEntity.AccountLegalEntityPublicHashedId); if (matchingLegalEntity != null) { var legalEntity = LegalEntityMapper.MapFromAccountApiLegalEntity(matchingLegalEntity); legalEntity.AccountLegalEntityPublicHashedId = permittedLegalEntity.AccountLegalEntityPublicHashedId; employerInfo.LegalEntities.Add(legalEntity); } } employerInfos.Add(employerInfo); } return(employerInfos); }
private async Task <LegalEntity> GetAssociatedLegalEntityAsync(UpdatedPermissionsEvent message, string employerAccountId) { var legalEntities = await _employerAccountProvider.GetLegalEntitiesConnectedToAccountAsync(employerAccountId); var legalEntity = legalEntities.FirstOrDefault(le => le.AccountLegalEntityId == message.AccountLegalEntityId); return(legalEntity == null ? null : LegalEntityMapper.MapFromAccountApiLegalEntity(legalEntity)); }
public void ThenReturnsCorrectlyPolulatedLegalEntity() { // Arrange var fixture = new Fixture(); var expected = fixture .Build <LegalEntityViewModel>() .With(x => x.Address, "Cheylesmore House, 5 Quinton Rd, Coventry, CV1 2WT") .With(x => x.Agreements, new List <AgreementViewModel>()) .Create(); // Act var actual = LegalEntityMapper.MapFromAccountApiLegalEntity(expected); // Assert actual.AccountLegalEntityPublicHashedId.Should().Be(expected.AccountLegalEntityPublicHashedId); actual.Name.Should().Be(expected.Name); actual.HasLegalEntityAgreement.Should().BeFalse(); }
public void ThenSetsHasLegalEntityAgreementToTrue() { // Arrange var fixture = new Fixture(); var agreementViewModel = fixture .Build <AgreementViewModel>() .With(x => x.Status, EmployerAgreementStatus.Signed) .Create(); var expected = fixture .Build <LegalEntityViewModel>() .With(x => x.Address, "Cheylesmore House, 5 Quinton Rd, Coventry, CV1 2WT") .With(x => x.Agreements, new List <AgreementViewModel> { agreementViewModel }) .Create(); // Act var actual = LegalEntityMapper.MapFromAccountApiLegalEntity(expected); // Assert actual.HasLegalEntityAgreement.Should().BeTrue(); }