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 void CanSearchOnlyLocalHackneyAddressesCaseInsensitively(string gazetteerDatabaseValue) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Gazetteer = gazetteerDatabaseValue } ); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Gazetteer = "National" } ); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Local, }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void WillFilterByOutOfBoroughAddresses(bool outOfBoroughAddressFlag) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { NeverExport = outOfBoroughAddressFlag } ); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { NeverExport = !outOfBoroughAddressFlag } ); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, HackneyGazetteerOutOfBoroughAddress = outOfBoroughAddressFlag, }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void WillSearchForAddressesWithStatus(string savedStatus, string statusSearchTerm) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { AddressStatus = savedStatus } ); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { AddressStatus = savedStatus == "Provisional" ? "Alternative" : "Provisional" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, AddressStatus = statusSearchTerm }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void WillThirdlyOrderByStreet() { var addressOne = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town b" }); var addressTwo = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town a", Postcode = "", Street = "B Street" }); var addressThree = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town a", Postcode = "", Street = "A Street" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(3); addresses.ElementAt(0).Should().BeEquivalentTo(addressThree.ToDomain()); addresses.ElementAt(1).Should().BeEquivalentTo(addressTwo.ToDomain()); addresses.ElementAt(2).Should().BeEquivalentTo(addressOne.ToDomain()); }
public void ItWillGetASimpleAddressFromTheDatabase() { var addressKey = _faker.Random.String2(14); var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, addressKey); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Simple, Gazetteer = GlobalConstants.Gazetteer.Both }; var(addresses, _) = _classUnderTest.SearchAddresses(request); var expectedAddress = new Address { Line1 = savedAddress.Line1, Line2 = savedAddress.Line2, Line3 = savedAddress.Line3, Line4 = savedAddress.Line4, Town = savedAddress.Town, UPRN = savedAddress.UPRN, Postcode = savedAddress.Postcode }; addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(expectedAddress); }
public void WillSearchForAnAddressesUsageCodeFromAList(string savedUsage, string usageSearchTerm) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { UsageCode = savedUsage } ); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { UsageCode = "B7" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, UsageCode = usageSearchTerm }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
private List <NationalAddress> AddOrderedRecordsToDatabase(int count) { var towns = GenerateRandomOrderedListOfWordsOfMaxLength(count, 100); var postcodes = GenerateRandomOrderedListOfWordsOfMaxLength(count, 8); var streets = GenerateRandomOrderedListOfWordsOfMaxLength(count, 100); var buildingNumbers = GenerateRandomOrderedListOfWordsOfMaxLength(count, 17); var unitNumbers = GenerateRandomOrderedListOfWordsOfMaxLength(count, 17); var unitNames = GenerateRandomOrderedListOfWordsOfMaxLength(count, 90); var records = new List <NationalAddress>(); for (var i = 0; i < count; i++) { records.Add(TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = towns.ElementAt(i), Postcode = postcodes.ElementAt(i), Street = streets.ElementAt(i), BuildingNumber = buildingNumbers.ElementAt(i), UnitNumber = Convert.ToInt16($"{i}{_faker.Random.Int(10, 99)}"), UnitName = unitNames.ElementAt(i), PaonStartNumber = Convert.ToInt16($"{i}{_faker.Random.Int(10, 99)}") })); } return(records); }
public async Task GetAddressReturnsADetailedAddressRecordInTheResponse() { var addressId = _faker.Random.String2(14); var addressRecord = _fixture.Build <NationalAddress>() .With(add => add.AddressKey, addressId) .Create(); TestEfDataHelper.InsertAddress(DatabaseContext, addressId, addressRecord); var url = new Uri($"api/v1/addresses/{addressId}", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var apiResponse = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); var returnedRecord = apiResponse.Data.Addresses.FirstOrDefault(); returnedRecord.AddressKey.Should().Be(addressId); returnedRecord.USRN.Should().Be(addressRecord.USRN); returnedRecord.UPRN.Should().Be(addressRecord.UPRN); returnedRecord.Line1.Should().BeEquivalentTo(addressRecord.Line1); returnedRecord.Line2.Should().BeEquivalentTo(addressRecord.Line2); returnedRecord.Line3.Should().BeEquivalentTo(addressRecord.Line3); returnedRecord.Line4.Should().BeEquivalentTo(addressRecord.Line4); returnedRecord.Town.Should().BeEquivalentTo(addressRecord.Town); returnedRecord.Postcode.Should().BeEquivalentTo(addressRecord.Postcode); }
public void WillSearchPostcodeForAMatch(string savedPostcode, string postcodeSearch) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Postcode = savedPostcode } ); var randomPostcode = $"NW{_faker.Random.Int(1, 9)} {_faker.Random.Int(1, 9)}TY"; TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Postcode = randomPostcode }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, Postcode = postcodeSearch }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void ItWillReturnADetailedRecordForASingleAddressRetrievedUsingTheAddressKey() { var addressKey = _faker.Random.String2(14); var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, addressKey); var retrievedRecord = _classUnderTest.GetSingleAddress(addressKey); retrievedRecord.Should().NotBeNull(); retrievedRecord.Should().BeEquivalentTo(savedAddress.ToDomain()); }
public async Task Get404WhenUPRNIsNotProvided() { var uprn = _faker.Random.Int(); TestEfDataHelper.InsertCrossReference(DatabaseContext, uprn); var url = new Uri($"api/v1/properties/crossreferences", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(404); }
public async Task SearchAddressReturns200() { var addressKey = "eytshdnshsuahs"; TestEfDataHelper.InsertAddress(DatabaseContext, addressKey); var queryString = "PostCode=E8"; var response = await CallEndpointWithQueryParameters(queryString).ConfigureAwait(true); response.StatusCode.Should().Be(200); }
private void AddSomeRandomAddressToTheDatabase(int?count = null, string gazetteer = "Local") { var number = count ?? _faker.Random.Int(2, 7); for (var i = 0; i < number; i++) { var addressKey = _faker.Random.String2(14); var randomAddress = _fixture.Build <NationalAddress>() .With(a => a.Gazetteer, gazetteer).Create(); TestEfDataHelper.InsertAddress(DatabaseContext, addressKey, randomAddress); } }
public async Task GetAddressReturns200WithValidAddressIdParameter() { var addressId = _faker.Random.String2(14); TestEfDataHelper.InsertAddress(DatabaseContext, addressId); var url = new Uri($"api/v1/addresses/{addressId}", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); }
public void ItWillReturnAListOfCrossReferencesUsingAUprn() { var uprn = _faker.Random.Long(); var savedCrossRef = TestEfDataHelper.InsertCrossReference(DatabaseContext, uprn); var response = _classUnderTest.GetAddressCrossReference(uprn); response.Should().NotBeNull(); response.First().UPRN.Should().Be(uprn); response.First().Should().BeEquivalentTo(savedCrossRef.ToDomain()); }
public async Task GetAddressReturns400IfAddressIdParameterIsEmpty() { var addressId = _faker.Random.String2(14); TestEfDataHelper.InsertAddress(DatabaseContext, addressId); const string emptyId = ""; var url = new Uri($"api/v1/addresses/{emptyId}", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(400); response.ReasonPhrase.Should().Be("Bad Request"); }
public async Task GetAddressReturns500WhenAddressIdParameterIsNot14Characters() { var addressId = _faker.Random.String2(14); TestEfDataHelper.InsertAddress(DatabaseContext, addressId); var incorrectLength = addressId.Substring(0, 10); var url = new Uri($"api/v1/addresses/{incorrectLength}", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(500); response.ReasonPhrase.Should().Be("Internal Server Error"); }
public async Task GetCrossReferenceAddressReturns200() { var uprn = _faker.Random.Int(); TestEfDataHelper.InsertCrossReference(DatabaseContext, uprn); var url = new Uri($"api/v1/properties/{uprn}/crossreferences", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var convertedResponse = await ConvertToCrossReferenceResponseObject(response).ConfigureAwait(true); convertedResponse.StatusCode.Should().Be(200); }
public void WillInTheSeventhCaseOrderByPresenceAndOrderOfUnitName() { var addressOne = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town a", Postcode = "", Street = "B Street", PaonStartNumber = 1, BuildingNumber = "78", UnitNumber = 43, UnitName = "J name" }); var addressTwo = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town a", Postcode = "", Street = "B Street", PaonStartNumber = 1, BuildingNumber = "78", UnitNumber = 43, UnitName = "A name" }); var addressThree = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Town = "town a", Postcode = "", Street = "B Street", PaonStartNumber = 1, BuildingNumber = "78", UnitNumber = 43, UnitName = "" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(3); addresses.ElementAt(0).Should().BeEquivalentTo(addressTwo.ToDomain()); addresses.ElementAt(1).Should().BeEquivalentTo(addressOne.ToDomain()); addresses.ElementAt(2).Should().BeEquivalentTo(addressThree.ToDomain()); }
public async Task GetAddressReturnsNoAddressesIfAddressIdParameterDoesNotMatchARecordInTheDatabase() { var addressId = _faker.Random.String2(14); TestEfDataHelper.InsertAddress(DatabaseContext, addressId); var differentId = _faker.Random.String2(14); var url = new Uri($"api/v1/addresses/{differentId}", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); response.StatusCode.Should().Be(200); var convertedResponse = await response.ConvertToSearchAddressResponseObject().ConfigureAwait(true); convertedResponse.Data.Addresses.Should().BeNull(); }
public void ItWillGetADetailedAddressFromTheDatabase() { var addressKey = _faker.Random.String2(14); var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, addressKey); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().AddressKey.Should().Be(addressKey); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void WillOnlyGetPostcodesWhichMatchAtTheStart(string savedPostcode, string postcodeSearch) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Postcode = savedPostcode } ); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, Postcode = postcodeSearch }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(0); }
public void IfNoAddressStatusSearchGivenDefaultsToApprovedPreferred() { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { AddressStatus = "Historical" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public async Task SearchAddressReturnsAnAddressWithMatchingPostcode() { var addressKey = _faker.Random.String2(14); var postcode = "E4 2JH"; var record = TestEfDataHelper.InsertAddress(DatabaseContext, addressKey, new NationalAddress { Postcode = postcode }); AddSomeRandomAddressToTheDatabase(); var queryString = $"PostCode={postcode}&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 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 void WillSearchStreetForAMatch(string savedStreet, string streetSearch) { var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { Street = savedStreet } ); TestEfDataHelper.InsertAddress(DatabaseContext); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, Street = streetSearch }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public async Task GetDetailedCrossReferenceAddressRecord() { var uprn = _faker.Random.Int(); var record = _fixture.Build <CrossReference>() .With(add => add.UPRN, uprn) .Create(); TestEfDataHelper.InsertCrossReference(DatabaseContext, uprn, record); var url = new Uri($"api/v1/properties/{uprn}/crossreferences", UriKind.Relative); var response = await Client.GetAsync(url).ConfigureAwait(true); var apiResponse = await ConvertToCrossReferenceResponseObject(response).ConfigureAwait(true); var recordReturned = apiResponse.Data.AddressCrossReferences.FirstOrDefault(); recordReturned.UPRN.Should().Be(uprn); recordReturned.Name.Should().Be(record.Name); recordReturned.Value.Should().Be(record.Value); recordReturned.Code.Should().Be(record.Code); recordReturned.CrossRefKey.Should().Be(record.CrossRefKey); recordReturned.EndDate.Value.Date.Should().Be(record.EndDate.Value.Date); }
public void WillSearchUsrnsForAMatch() { var uprn = _faker.Random.Number(10000000, 99999999); var savedAddress = TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { USRN = uprn } ); TestEfDataHelper.InsertAddress(DatabaseContext); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, Usrn = uprn }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(1); addresses.First().Should().BeEquivalentTo(savedAddress.ToDomain()); }
public void WontFilterByParentShellWhenSearchingByPrimaryUsage() { TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { UsagePrimary = "Parent Shell" } ); TestEfDataHelper.InsertAddress(DatabaseContext, request: new NationalAddress { UsagePrimary = "Commercial" }); var request = new SearchParameters { Page = 1, PageSize = 50, Format = GlobalConstants.Format.Detailed, Gazetteer = GlobalConstants.Gazetteer.Both, UsagePrimary = "Parent Shell" }; var(addresses, _) = _classUnderTest.SearchAddresses(request); addresses.Count.Should().Be(2); }