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));
        }
예제 #3
0
        public void ShouldMapFullFivePartAddress()
        {
            var inputAddr = "Valtech, 46 Colebrooke Row,Islington,London, N1 8AF";

            var actualAddr = LegalEntityMapper.MapFromAddressLine(inputAddr);

            actualAddr.AddressLine1.Should().Be("Valtech");
            actualAddr.AddressLine2.Should().Be("46 Colebrooke Row");
            actualAddr.AddressLine3.Should().Be("Islington");
            actualAddr.AddressLine4.Should().Be("London");
            actualAddr.Postcode.Should().Be("N1 8AF");
        }
예제 #4
0
        public void ShouldMapOnlySinglePartNonPostcodeAddress()
        {
            var inputAddr = "46 Colebrooke Row";

            var actualAddr = LegalEntityMapper.MapFromAddressLine(inputAddr);

            actualAddr.AddressLine1.Should().Be("46 Colebrooke Row");
            actualAddr.AddressLine2.Should().BeNull();
            actualAddr.AddressLine3.Should().BeNull();
            actualAddr.AddressLine4.Should().BeNull();
            actualAddr.Postcode.Should().BeNull();
        }
예제 #5
0
        public void ShouldMapOnlyPostcodeAddress()
        {
            var inputAddr = "N1 8AF";

            var actualAddr = LegalEntityMapper.MapFromAddressLine(inputAddr);

            actualAddr.AddressLine1.Should().BeNull();
            actualAddr.AddressLine2.Should().BeNull();
            actualAddr.AddressLine3.Should().BeNull();
            actualAddr.AddressLine4.Should().BeNull();
            actualAddr.Postcode.Should().Be("N1 8AF");
        }
예제 #6
0
        public void ShouldMapFullThreePartAddress()
        {
            var inputAddr = "46 Colebrooke Row,London, N1 8AF";

            var actualAddr = LegalEntityMapper.MapFromAddressLine(inputAddr);

            actualAddr.AddressLine1.Should().Be("46 Colebrooke Row");
            actualAddr.AddressLine2.Should().Be("London");
            actualAddr.AddressLine3.Should().BeNull();
            actualAddr.AddressLine4.Should().BeNull();

            actualAddr.Postcode.Should().Be("N1 8AF");
        }
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end   = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId {
                SystemName = "Test", Identifier = "A"
            };
            var contractDetails = new EnergyTrading.MDM.Contracts.Sample.LegalEntityDetails();
            var contract        = new EnergyTrading.MDM.Contracts.Sample.LegalEntity
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList {
                    id
                },
                Details       = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData {
                    StartDate = start, EndDate = end
                },
                Party = ObjectMother.Create <Party>().CreateNexusEntityId(() => ""),
            };

            // NB Don't assign validity here, want to prove SUT sets it
            var details = new LegalEntityDetails();

            var mapping = new PartyRoleMapping();

            var mappingEngine = new Mock <IMappingEngine>();

            mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.LegalEntityDetails, LegalEntityDetails>(contractDetails)).Returns(details);
            var repository = new Mock <IRepository>();

            repository.Setup(x => x.FindOne <Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create <Party>());

            var mapper = new LegalEntityMapper(repository.Object, mappingEngine.Object);

            // Act
            var candidate = mapper.Map(contract);

            // Assert
            //Assert.AreEqual(1, candidate.Details.Count, "Detail count differs");
            Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs");
            Check(range, details.Validity, "Validity differs");
        }
        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();
        }
        public void Map()
        {
            // Arrange
            var start = new DateTime(2010, 1, 1);
            var end = DateUtility.MaxDate;
            var range = new DateRange(start, end);

            var id = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" };
            var contractDetails = new EnergyTrading.MDM.Contracts.Sample.LegalEntityDetails();
            var contract = new EnergyTrading.MDM.Contracts.Sample.LegalEntity
            {
                Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id },
                Details = contractDetails,
                MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end },
                Party = ObjectMother.Create<Party>().CreateNexusEntityId(() => ""),
            };

            // NB Don't assign validity here, want to prove SUT sets it
            var details = new LegalEntityDetails();

            var mapping = new PartyRoleMapping();

            var mappingEngine = new Mock<IMappingEngine>();
            mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, PartyRoleMapping>(id)).Returns(mapping);
            mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.LegalEntityDetails, LegalEntityDetails>(contractDetails)).Returns(details);
            var repository = new Mock<IRepository>();
            repository.Setup(x => x.FindOne<Party>(int.Parse(contract.Party.Identifier.Identifier))).Returns(ObjectMother.Create<Party>());

            var mapper = new LegalEntityMapper(repository.Object, mappingEngine.Object);

            // Act
            var candidate = mapper.Map(contract);

            // Assert
            //Assert.AreEqual(1, candidate.Details.Count, "Detail count differs");
            Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs");
            Check(range, details.Validity, "Validity differs");
        }