コード例 #1
0
        public async Task MapToCollectionOfCarPhotoUris_CorrectJsonStringObject_ReturnsNotEmptyCollectionOfObjects()
        {
            // Arrange
            using (var streamReader = new StreamReader($"{_testFilesFolderPath}carPhotoUrisTestFile.json"))
            {
                string jsonString = await streamReader.ReadToEndAsync();

                // Act
                IEnumerable <string> carPhotoUris = _carMapper.MapToCollectionOfCarPhotoUris(jsonString);

                // Assert
                Assert.NotEmpty(carPhotoUris);
            }
        }
コード例 #2
0
        public async Task <IEnumerable <string> > GetCarPhotos(int autoId)
        {
            var carsParameters = new Dictionary <string, string>();

            carsParameters.Add("api_key", _configuration["AutoRiaApi:ApiKey"]);

            var uriBuilder = new UriBuilder(_configuration["AutoRiaApi:Scheme"], _configuration["AutoRiaApi:Host"]);

            uriBuilder.Path = $"{_configuration["AutoRiaApi:AutoPhotosPath"]}/{autoId}";
            var stringBuilder = new StringBuilder();

            uriBuilder.Query = stringBuilder.AppendJoin("&", carsParameters.Select(p => $"{p.Key}={p.Value}")).ToString();

            HttpResponseMessage response = await _httpClient.GetAsync(uriBuilder.Uri);

            response.EnsureSuccessStatusCode();
            string stringResponse = await response.Content.ReadAsStringAsync();

            IEnumerable <string> carPhotos = _carMapper.MapToCollectionOfCarPhotoUris(stringResponse);

            return(carPhotos);
        }