コード例 #1
0
        public async Task GetPostcodesFromDb_ResultsAreOrdered_LimitedByDefaultRadius()
        {
            _repository.Setup(x => x.GetPreComputedNearestPostcodes(It.IsAny <string>())).ReturnsAsync(default(PreComputedNearestPostcodesDto));

            _applicationConfigSettings = new ApplicationConfig()
            {
                DefaultMaxNumberOfNearbyPostcodes    = 0,
                DefaultNearestPostcodeRadiusInMetres = 3
            };
            _applicationConfig.SetupGet(x => x.Value).Returns(_applicationConfigSettings);

            NearestPostcodeGetter nearestPostcodeGetter = new NearestPostcodeGetter(_repository.Object, _applicationConfig.Object);

            IReadOnlyList <NearestPostcodeDto> result = await nearestPostcodeGetter.GetNearestPostcodesAsync(_postcode, null, 5);


            List <NearestPostcodeDto> expectedResult = _nearestPostcodeDtos.Where(x => x.DistanceInMetres <= 3).OrderBy(x => x.DistanceInMetres).Take(5).ToList();


            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].Postcode, result[i].Postcode);
                Assert.AreEqual(expectedResult[i].DistanceInMetres, result[i].DistanceInMetres);
            }
        }
コード例 #2
0
        public async Task GetPostcodesFromDb_GetPostcodesWithinARadiusOf16094Metres()
        {
            _repository.Setup(x => x.GetPreComputedNearestPostcodes(It.IsAny <string>())).ReturnsAsync(default(PreComputedNearestPostcodesDto));

            NearestPostcodeGetter nearestPostcodeGetter = new NearestPostcodeGetter(_repository.Object, _applicationConfig.Object);

            IReadOnlyList <NearestPostcodeDto> result = await nearestPostcodeGetter.GetNearestPostcodesAsync(_postcode, 1, 1);

            _repository.Verify(x => x.GetNearestPostcodesAsync(It.Is <string>(y => y == _postcode), It.Is <double>(y => y == 16094)));
        }
コード例 #3
0
        public async Task GetPostcodesFromCache_CantGetResutsWithARadiusGreaterThan16094Metres()
        {
            NearestPostcodeGetter nearestPostcodeGetter = new NearestPostcodeGetter(_repository.Object, _applicationConfig.Object);

            IReadOnlyList <NearestPostcodeDto> result = await nearestPostcodeGetter.GetNearestPostcodesAsync(_postcode, 99999, 5);

            _repository.Verify(x => x.GetNearestPostcodesAsync(It.IsAny <string>(), It.IsAny <double>()), Times.Never);

            List <NearestPostcodeDto> expectedResult = _nearestPostcodeDtos.Where(x => x.DistanceInMetres <= 16094).OrderBy(x => x.DistanceInMetres).Take(5).ToList();

            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].Postcode, result[i].Postcode);
                Assert.AreEqual(expectedResult[i].DistanceInMetres, result[i].DistanceInMetres);
            }
        }
コード例 #4
0
        public async Task GetPostcodesFromCache_ResultsAreOrdered_LimitedByMaxNumberOfResults()
        {
            NearestPostcodeGetter nearestPostcodeGetter = new NearestPostcodeGetter(_repository.Object, _applicationConfig.Object);

            IReadOnlyList <NearestPostcodeDto> result = await nearestPostcodeGetter.GetNearestPostcodesAsync(_postcode, 5, 3);

            _repository.Verify(x => x.GetNearestPostcodesAsync(It.IsAny <string>(), It.IsAny <double>()), Times.Never);

            List <NearestPostcodeDto> expectedResult = _nearestPostcodeDtos.Where(x => x.DistanceInMetres <= 5).OrderBy(x => x.DistanceInMetres).Take(3).ToList();


            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].Postcode, result[i].Postcode);
                Assert.AreEqual(expectedResult[i].DistanceInMetres, result[i].DistanceInMetres);
            }
        }
コード例 #5
0
        public async Task GetPostcodesFromDb_ResultsAreOrdered_LimitedByMaxNumberOfResults()
        {
            _repository.Setup(x => x.GetPreComputedNearestPostcodes(It.IsAny <string>())).ReturnsAsync(default(PreComputedNearestPostcodesDto));

            NearestPostcodeGetter nearestPostcodeGetter = new NearestPostcodeGetter(_repository.Object, _applicationConfig.Object);

            IReadOnlyList <NearestPostcodeDto> result = await nearestPostcodeGetter.GetNearestPostcodesAsync(_postcode, 5, 3);


            List <NearestPostcodeDto> expectedResult = _nearestPostcodeDtos.Where(x => x.DistanceInMetres <= 5).OrderBy(x => x.DistanceInMetres).Take(3).ToList();

            _repository.Verify(x => x.SavePreComputedNearestPostcodes(It.IsAny <PreComputedNearestPostcodesDto>()));

            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].Postcode, result[i].Postcode);
                Assert.AreEqual(expectedResult[i].DistanceInMetres, result[i].DistanceInMetres);
            }
        }