Ejemplo n.º 1
0
        public async Task MapToCollectionOfCarsIds_CorrectJsonStringObject_ReturnsNotEmptyCollectionOfObjects()
        {
            // Arrange
            using (var streamReader = new StreamReader($"{_testFilesFolderPath}autoSearchTestFile.json"))
            {
                string jsonString = await streamReader.ReadToEndAsync();

                // Act
                IEnumerable <int> carsIds = _carMapper.MapToCollectionOfCarsIds(jsonString);

                // Assert
                Assert.NotEmpty(carsIds);
            }
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <int> > GetCarsIds(IDictionary <string, string> carsParameters)
        {
            carsParameters.Add("api_key", _configuration["AutoRiaApi:ApiKey"]);
            var uriBuilder = new UriBuilder(_configuration["AutoRiaApi:Scheme"], _configuration["AutoRiaApi:Host"]);

            uriBuilder.Path = _configuration["AutoRiaApi:AutoSearchPath"];
            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 <int> carsIds = _carMapper.MapToCollectionOfCarsIds(stringResponse);

            return(carsIds);
        }