Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
0
        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 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}");
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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());
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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 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);
        }
Ejemplo n.º 11
0
        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 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 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");
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 19
0
        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());
        }
Ejemplo n.º 20
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());
        }
Ejemplo n.º 21
0
        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 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);
        }
Ejemplo n.º 24
0
        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());
        }
Ejemplo n.º 25
0
        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);
        }
Ejemplo n.º 26
0
        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());
        }