public static PreComputedNearestPostcodesDto CompressNearestPostcodeDtos(string postcode, IEnumerable <NearestPostcodeDto> nearestPostcodeDtos) { PreComputedNearestPostcodesDto preComputedNearestPostcodeses = new PreComputedNearestPostcodesDto(); preComputedNearestPostcodeses.Postcode = postcode; byte[] nearestPostcodesBytes = Utf8Json.JsonSerializer.Serialize(nearestPostcodeDtos); preComputedNearestPostcodeses.CompressedNearestPostcodes = CompressionUtils.Zip(nearestPostcodesBytes); return(preComputedNearestPostcodeses); }
public void SetUp() { _repository = new Mock <IRepository>(); _repository.SetupAllProperties(); _nearestPostcodeDtos = new List <NearestPostcodeDto>() { new NearestPostcodeDto() { Postcode = "NG1 AA", DistanceInMetres = 2 }, new NearestPostcodeDto() { Postcode = "NG1 AB", DistanceInMetres = 3 }, new NearestPostcodeDto() { Postcode = "NG1 AC", DistanceInMetres = 1 }, new NearestPostcodeDto() { Postcode = "NG1 AD", DistanceInMetres = 4 }, new NearestPostcodeDto() { Postcode = "NG1 AE", DistanceInMetres = 16095 }, }; _repository.Setup(x => x.GetNearestPostcodesAsync(It.Is <string>(y => y == _postcode), It.IsAny <double>())).ReturnsAsync(_nearestPostcodeDtos); PreComputedNearestPostcodesDto preComputedNearestPostcodes = NearestPostcodeCompressor.CompressNearestPostcodeDtos(_postcode, _nearestPostcodeDtos); _repository.Setup(x => x.GetPreComputedNearestPostcodes(It.Is <string>(y => y == _postcode))).ReturnsAsync(preComputedNearestPostcodes); _applicationConfigSettings = new ApplicationConfig() { DefaultMaxNumberOfNearbyPostcodes = 0, DefaultNearestPostcodeRadiusInMetres = 0 }; _applicationConfig = new Mock <IOptionsSnapshot <ApplicationConfig> >(); _applicationConfig.SetupGet(x => x.Value).Returns(_applicationConfigSettings); }
public async Task SavePreComputedNearestPostcodes(PreComputedNearestPostcodesDto preComputedNearestPostcodesDto) { using (SqlConnection connection = new SqlConnection(_connectionStrings.Value.AddressService)) { if (connection.DataSource.Contains("database.windows.net")) { connection.AccessToken = new AzureServiceTokenProvider().GetAccessTokenAsync("https://database.windows.net/").Result; } await connection.ExecuteAsync("[Address].[SavePreComputedNearestPostcodes]", commandType : CommandType.StoredProcedure, param : new { Postcode = preComputedNearestPostcodesDto.Postcode, CompressedNearestPostcodes = preComputedNearestPostcodesDto.CompressedNearestPostcodes }, commandTimeout : 15); } }
public async Task <PreComputedNearestPostcodesDto> GetPreComputedNearestPostcodes(string postcode) { using (SqlConnection connection = new SqlConnection(_connectionStrings.Value.AddressService)) { if (connection.DataSource.Contains("database.windows.net")) { connection.AccessToken = new AzureServiceTokenProvider().GetAccessTokenAsync("https://database.windows.net/").Result; } PreComputedNearestPostcodesDto result = await connection.QuerySingleOrDefaultAsync <PreComputedNearestPostcodesDto>("[Address].[GetPreComputedNearestPostcodes]", commandType : CommandType.StoredProcedure, param : new { Postcode = postcode }, commandTimeout : 15); return(result); } }
public static IReadOnlyList <NearestPostcodeDto> DecompressPreComputedPostcodes(PreComputedNearestPostcodesDto preComputedNearestPostcodesDto) { byte[] decompressedPreComputedNearbyPostcodesBytes = CompressionUtils.UnzipToBytes(preComputedNearestPostcodesDto.CompressedNearestPostcodes); List <NearestPostcodeDto> nearbyPostcodeDtos = Utf8Json.JsonSerializer.Deserialize <List <NearestPostcodeDto> >(decompressedPreComputedNearbyPostcodesBytes); return(nearbyPostcodeDtos); }