public async Task UsingTheSimpleFlagOnlyReturnsBasicAddressInformation() { var addressKey = _faker.Random.String2(14); var addressDetails = new NationalAddress { UPRN = _faker.Random.Int(), Line1 = _faker.Address.StreetName(), Line2 = _faker.Address.StreetAddress(), Line3 = _faker.Address.County(), Line4 = _faker.Address.Country(), Town = _faker.Address.City(), Postcode = "E41JJ", AddressStatus = "Historical" }; TestEfDataHelper.InsertAddress(DatabaseContext, addressKey, addressDetails); AddSomeRandomAddressToTheDatabase(); var queryString = $"UPRN={addressDetails.UPRN}&AddressStatus=Historical&Format=Simple"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var data = await response.Content.ReadAsStringAsync().ConfigureAwait(true); data.Should().BeEquivalentTo( "{\"data\":" + "{\"address\":[" + $"{{\"line1\":\"{addressDetails.Line1}\",\"line2\":\"{addressDetails.Line2}\"," + $"\"line3\":\"{addressDetails.Line3}\",\"line4\":\"{addressDetails.Line4}\"," + $"\"town\":\"{addressDetails.Town}\",\"postcode\":\"{addressDetails.Postcode}\"," + $"\"UPRN\":{addressDetails.UPRN}}}" + "],\"page_count\":1,\"total_count\":1},\"statusCode\":200}"); }
public async Task SettingAddressScopeToNationalWillReturnAllAddresses() { var addressKey = _faker.Random.String2(14); var dbOptions = new NationalAddress { UPRN = _faker.Random.Int(), Gazetteer = "National" }; var record = await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, addressKey, dbOptions) .ConfigureAwait(true); await AddSomeRandomAddressToTheDatabase(count : 3).ConfigureAwait(true); await AddSomeRandomAddressToTheDatabase(count : 3, gazetteer : "National").ConfigureAwait(true); var queryString = $"uprn={dbOptions.UPRN}&address_status={record.AddressStatus}&format=Detailed&address_scope=national"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(1); returnedAddress.Data.Addresses.First().AddressKey.Should().Be(addressKey); }
private static QueryableAddress MapAddressToQueryableAddress(NationalAddress address) { return(new QueryableAddress { Gazetteer = address.Gazetteer, Line1 = address.Line1, Line2 = address.Line2, Line3 = address.Line3, Line4 = address.Line4, Postcode = address.Postcode, Street = address.Street, Town = address.Town, AddressKey = address.AddressKey, AddressStatus = address.AddressStatus, BuildingNumber = address.BuildingNumber, PropertyShell = address.PropertyShell, PropertyChangeDate = address.PropertyChangeDate, PropertyStartDate = address.PropertyStartDate, UsageCode = address.UsageCode, UsagePrimary = address.UsagePrimary, AddressChangeDate = address.AddressChangeDate, OutOfBoroughAddress = address.NeverExport, UPRN = address.UPRN, USRN = address.USRN, ParentUPRN = address.ParentUPRN }); }
public async Task CanQueryTheAddressText(string query) { var addressKey = _faker.Random.String2(14); var addressLines = new[] { "Flat C", "290 Green Street", "Hackney", "London" }; var queryParameters = new NationalAddress { Line1 = addressLines.ElementAt(0), Line2 = addressLines.ElementAt(1), Line3 = addressLines.ElementAt(2), Line4 = addressLines.ElementAt(3), Gazetteer = "hackney" }; await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, addressKey, queryParameters) .ConfigureAwait(true); await AddSomeRandomAddressToTheDatabase().ConfigureAwait(true); var queryString = $"query={query}&format=detailed"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(1); returnedAddress.Data.Addresses.First().AddressKey.Should().Be(addressKey); }
public async Task IncludeOrExlcudePropertyShellsInARequest(string primaryUsage, bool includePropertyShell, int expectedCount) { const string postCode = "AB11 1AB"; var blockAddressKey = _faker.Random.String2(14); var blockOfFlats = new NationalAddress { UPRN = _faker.Random.Int(1, 287987129), UsagePrimary = primaryUsage, Postcode = postCode }; await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, blockAddressKey, blockOfFlats) .ConfigureAwait(true); var flatAddressKey = _faker.Random.String2(14); var flat = new NationalAddress { ParentUPRN = blockOfFlats.UPRN, Postcode = postCode }; var flatRecord = await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, flatAddressKey, flat) .ConfigureAwait(true); await AddSomeRandomAddressToTheDatabase().ConfigureAwait(true); var propertyShellQuery = includePropertyShell ? "&include_property_shells=true" : ""; var queryString = $"postcode={postCode}&Format=Detailed{propertyShellQuery}&address_scope=national"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject() .ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(expectedCount); var returnedUprns = returnedAddress.Data.Addresses .Select(x => x.UPRN).ToList(); if (expectedCount >= 2) { returnedUprns.Should().Contain(blockOfFlats.UPRN); returnedUprns.Should().Contain(flatRecord.UPRN); } else if (expectedCount == 1) { if (includePropertyShell) { returnedUprns.Should().Contain(blockOfFlats.UPRN); } else { returnedUprns.Should().Contain(flatRecord.UPRN); } } }
public static async Task <NationalAddress> InsertAddressInDbAndEs(AddressesContext context, ElasticClient elasticClient, string key = null, NationalAddress request = null) { var address = InsertAddressInDb(context, key, request); var queryableAddress = MapAddressToQueryableAddress(address); await InsertAddressInEs(elasticClient, address.AddressKey, queryableAddress).ConfigureAwait(true); return(address); }
public static Address ToDomain(this NationalAddress addressEntity) { return(new Address { AddressKey = addressEntity.AddressKey, USRN = addressEntity.USRN, ParentUPRN = addressEntity.ParentUPRN, AddressStatus = addressEntity.AddressStatus, UnitName = addressEntity.UnitName, UnitNumber = addressEntity.UnitNumber?.ToString(), BuildingName = addressEntity.BuildingName, BuildingNumber = addressEntity.BuildingNumber, Street = addressEntity.Street, Locality = addressEntity.Locality, Gazetteer = addressEntity.Gazetteer, CommercialOccupier = addressEntity.Organisation, Ward = addressEntity.Ward, UsageDescription = addressEntity.UsageDescription, UsagePrimary = addressEntity.UsagePrimary, UsageCode = addressEntity.UsageCode, PlanningUseClass = addressEntity.PlanningUseClass, PropertyShell = addressEntity.PropertyShell, HackneyGazetteerOutOfBoroughAddress = addressEntity.NeverExport, Easting = addressEntity.Easting, Northing = addressEntity.Northing, Longitude = addressEntity.Longitude, Latitude = addressEntity.Latitude, AddressStartDate = addressEntity.AddressStartDate, AddressEndDate = addressEntity.AddressEndDate, AddressChangeDate = addressEntity.AddressChangeDate, PropertyStartDate = addressEntity.PropertyStartDate, PropertyEndDate = addressEntity.PropertyEndDate, PropertyChangeDate = addressEntity.PropertyChangeDate, Line1 = addressEntity.Line1, Line2 = addressEntity.Line2, Line3 = addressEntity.Line3, Line4 = addressEntity.Line4, Town = addressEntity.Town, UPRN = addressEntity.UPRN, Postcode = addressEntity.Postcode, }); }
public async Task SearchAddressReturnsAddressesInHackneyBoroughForAGivenCrossReference() { var uprnOne = _faker.Random.Int(); var uprnTwo = _faker.Random.Int(); var crossReferenceOne = new CrossReference { Code = "000ABC", Value = "100000" }; var crossReferenceTwo = new CrossReference { Code = "123XYZ", Value = "100000" }; var hackneyBoroughOne = new NationalAddress { UPRN = uprnOne, Gazetteer = "Hackney", NeverExport = false }; var hackneyBoroughTwo = new NationalAddress { UPRN = uprnTwo, Gazetteer = "Hackney", NeverExport = false }; var record = await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, request : hackneyBoroughOne).ConfigureAwait(true); TestDataHelper.InsertCrossReference(DatabaseContext, uprnOne, crossReferenceOne); await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, request : hackneyBoroughTwo).ConfigureAwait(true); TestDataHelper.InsertCrossReference(DatabaseContext, uprnTwo, crossReferenceTwo); await AddSomeRandomAddressToTheDatabase().ConfigureAwait(true); var queryString = $"cross_ref_code={crossReferenceOne.Code}&cross_ref_value={crossReferenceOne.Value}&format=Detailed"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(1); returnedAddress.Data.Addresses.First().AddressKey.Should().Be(record.AddressKey); }
public async Task CanSearchAddressesByUprn() { var addressKey = _faker.Random.String2(14); var queryParameters = new NationalAddress { UPRN = _faker.Random.Int(), }; var record = TestEfDataHelper.InsertAddress(DatabaseContext, addressKey, queryParameters); AddSomeRandomAddressToTheDatabase(); var queryString = $"UPRN={queryParameters.UPRN}&AddressStatus={record.AddressStatus}&Format=Detailed"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(1); returnedAddress.Data.Addresses.First().AddressKey.Should().Be(addressKey); }
public async Task CanSearchAddressesByUsrn() { var addressKey = _faker.Random.String2(14); var queryParameters = new NationalAddress { USRN = _faker.Random.Int(), AddressStatus = "Historical" }; await TestDataHelper.InsertAddressInDbAndEs(DatabaseContext, ElasticsearchClient, addressKey, queryParameters) .ConfigureAwait(true); await AddSomeRandomAddressToTheDatabase().ConfigureAwait(true); var queryString = $"USRN={queryParameters.USRN}&address_status=Historical&Format=Detailed&address_scope=national"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); var returnedAddress = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); returnedAddress.Data.Addresses.Count.Should().Be(1); returnedAddress.Data.Addresses.First().AddressKey.Should().Be(addressKey); }
public async Task <IActionResult> OnPost(Employee_UV_Dto employee, IList <PhysicalID_UV_Dto> physicalIDs, IList <BasicSalaryRDTO> basicSalaries, IList <AllowanceRDTO> allowances, IList <BanksRDTO> banks, Contact primaryContact, NationalAddress nationalAddress, IList <Contact> secondaryContacts, IList <Qualification> qualifications, IList <Dependant> dependants, IList <PhysicalId <int> > dependantsIds, IList <WorkShiftRDto> workShifts) { try { for (int i = 0; i < physicalIDs.Count; i++) { //physicalIDs[i].SetId(GuidGenerator.Create()); physicalIDs[i].IDTypeId = physicalIDs[i].IDType.Id; physicalIDs[i].IDType = null; physicalIDs[i].IssuedFromId = physicalIDs[i].IssuedFrom.Id; physicalIDs[i].IssuedFrom = null; } var empIds = new List <PhysicalID_UV_Dto>(); empIds.AddRange(physicalIDs); //employee.PhysicalIDs = empIds; employee.WorkShiftId = workShifts.Last().WorkShiftId; //Employee_UV_Dto employeeObj = JsonSerializer.Deserialize<Employee_UV_Dto>(employee); FinancialDetails financialDetails = new FinancialDetails(basicSalaries, allowances, banks); ContactInformation contactInformation = new ContactInformation(primaryContact, nationalAddress, secondaryContacts); QualificationDetail qualificationDetail = new QualificationDetail(qualifications); DependantsDetail dependantsDetail = new DependantsDetail(dependants, dependantsIds); WorkShiftDetail workShiftDetail = new WorkShiftDetail(workShifts); employee.ExtraProperties.Add("financialDetails", financialDetails); employee.ExtraProperties.Add("contactInformation", contactInformation); employee.ExtraProperties.Add("qualificationDetail", qualificationDetail); employee.ExtraProperties.Add("dependantsDetail", dependantsDetail); employee.ExtraProperties.Add("workShiftDetail", workShiftDetail); //Employee_Dto empAdded = await employeeAppService.CreateEmployee(employee); } catch (Exception ex) { } return(Page()); }
public static NationalAddress InsertAddress(AddressesContext context, string key = null, NationalAddress request = null) { var fixture = new Fixture(); var randomAddressRecord = fixture.Build <NationalAddress>() .With(a => a.AddressStatus, request?.AddressStatus ?? "Approved Preferred") .Create(); if (key != null) { randomAddressRecord.AddressKey = key; } if (request?.Postcode != null) { randomAddressRecord.Postcode = ReplaceEmptyStringWithNull(request.Postcode); randomAddressRecord.PostcodeNoSpace = request.Postcode?.Replace(" ", ""); } if (request?.BuildingNumber != null) { randomAddressRecord.BuildingNumber = request.BuildingNumber; } if (request?.Street != null) { randomAddressRecord.Street = request.Street; } if (request?.UPRN != null) { randomAddressRecord.UPRN = request.UPRN; } if (request?.USRN != null) { randomAddressRecord.USRN = request.USRN; } if (request?.UsagePrimary != null) { randomAddressRecord.UsagePrimary = request.UsagePrimary; } if (request?.UsageCode != null) { randomAddressRecord.UsageCode = request.UsageCode; } if (request?.Gazetteer != null) { randomAddressRecord.Gazetteer = request.Gazetteer; } if (request?.NeverExport != null) { randomAddressRecord.NeverExport = request.NeverExport; } if (request?.Town != null) { randomAddressRecord.Town = request.Town; } if (request?.Street != null) { randomAddressRecord.Street = request.Street; } if (request?.PaonStartNumber != null) { randomAddressRecord.PaonStartNumber = request.PaonStartNumber; } if (request?.BuildingNumber != null) { randomAddressRecord.BuildingNumber = ReplaceEmptyStringWithNull(request.BuildingNumber); } if (request?.UnitNumber != null) { randomAddressRecord.UnitNumber = request.UnitNumber; } if (request?.UnitName != null) { randomAddressRecord.UnitName = ReplaceEmptyStringWithNull(request.UnitName); } if (request?.Line1 != null) { randomAddressRecord.Line1 = request.Line1; } if (request?.Line2 != null) { randomAddressRecord.Line2 = request.Line2; } if (request?.Line3 != null) { randomAddressRecord.Line3 = request.Line3; } if (request?.Line4 != null) { randomAddressRecord.Line4 = request.Line4; } context.NationalAddresses.Add(randomAddressRecord); context.SaveChanges(); return(randomAddressRecord); }
public static NationalAddress InsertAddressInDb(AddressesContext context, string key = null, NationalAddress request = null) { var randomAddressRecord = CreateConfigurableAddressRecord(key, request); context.NationalAddresses.Add(randomAddressRecord); context.SaveChanges(); return(randomAddressRecord); }
private static NationalAddress CreateConfigurableAddressRecord(string key, NationalAddress request) { var fixture = new Fixture(); var randomAddressRecord = fixture.Build <NationalAddress>() .With(a => a.AddressStatus, request?.AddressStatus ?? "Approved") .Create(); if (key != null) { randomAddressRecord.AddressKey = key; } if (request?.Postcode != null) { randomAddressRecord.Postcode = ReplaceEmptyStringWithNull(request.Postcode); randomAddressRecord.PostcodeNoSpace = request.Postcode?.Replace(" ", ""); } if (request?.BuildingNumber != null) { randomAddressRecord.BuildingNumber = request.BuildingNumber; } if (request?.Street != null) { randomAddressRecord.Street = request.Street; } if (request?.UPRN != null && request.UPRN != 0) { randomAddressRecord.UPRN = request.UPRN; } if (request?.USRN != null && request.USRN != 0) { randomAddressRecord.USRN = request.USRN; } if (request?.UsagePrimary != null) { randomAddressRecord.UsagePrimary = request.UsagePrimary; } if (request?.UsageCode != null) { randomAddressRecord.UsageCode = request.UsageCode; } if (request?.Gazetteer != null) { randomAddressRecord.Gazetteer = request.Gazetteer; } if (request?.NeverExport != null) { randomAddressRecord.NeverExport = request.NeverExport; } if (request?.Town != null) { randomAddressRecord.Town = request.Town; } if (request?.Street != null) { randomAddressRecord.Street = request.Street; } if (request?.PaonStartNumber != null) { randomAddressRecord.PaonStartNumber = request.PaonStartNumber; } if (request?.PropertyChangeDate != null) { randomAddressRecord.PropertyChangeDate = request.PropertyChangeDate; } if (request?.PropertyChangeDate == 0) { randomAddressRecord.PropertyChangeDate = null; } if (request?.BuildingNumber != null) { randomAddressRecord.BuildingNumber = ReplaceEmptyStringWithNull(request.BuildingNumber); } if (request?.UnitNumber != null) { randomAddressRecord.UnitNumber = request.UnitNumber; } if (request?.UnitName != null) { randomAddressRecord.UnitName = ReplaceEmptyStringWithNull(request.UnitName); } if (request?.Line1 != null) { randomAddressRecord.Line1 = request.Line1; } if (request?.Line2 != null) { randomAddressRecord.Line2 = request.Line2; } if (request?.Line3 != null) { randomAddressRecord.Line3 = request.Line3; } if (request?.Line4 != null) { randomAddressRecord.Line4 = request.Line4; } randomAddressRecord.ParentUPRN = (request?.ParentUPRN).GetValueOrDefault() == 0 ? null : request.ParentUPRN; randomAddressRecord.PropertyShell = request?.PropertyShell ?? false; return(randomAddressRecord); }