Пример #1
0
        public void Add_City_Param_When_Non_Empty()
        {
            // Arrange
            _openWeatherMapClientParam.AddFilterByCityParams(_fakeCity, _fakeCountry, _fakeUnit);
            var expectedResult = $"q={_fakeCity},{_fakeCountry}&units={_fakeUnit}";

            //Act
            var actualResult = _openWeatherMapClientParam.ToQueryString();

            //Assert
            Assert.AreEqual(expectedResult, actualResult);
        }
Пример #2
0
        private async Task <T> GetApiResponse <T>(OpenWeatherMapClientParam parameter, string path) where T : class
        {
            var queryParams = parameter.ToQueryString();

            var uriBuilder = new UriBuilder(_config.ApiBaseUrl)
            {
                Path = path, Query = queryParams
            };

            using var httpResponse = await _client.GetAsync(uriBuilder.ToString(), HttpCompletionOption.ResponseHeadersRead);

            if (httpResponse.IsSuccessStatusCode)
            {
                var contentStream = await httpResponse.Content.ReadAsStreamAsync();

                return(await JsonSerializer.DeserializeAsync <T>(contentStream));
            }

            if (httpResponse.StatusCode == HttpStatusCode.Unauthorized)
            {
                throw new UnauthorizedAccessException();
            }

            return(null);
        }
Пример #3
0
        public void Add_Config_Param_Config_Non_Empty()
        {
            // Arrange
            _openWeatherMapClientParam = new OpenWeatherMapClientParam(new OpenWeatherMapConfig()
            {
                DefaultCountryCode = "DE", ApiKey = "AppId"
            });
            _openWeatherMapClientParam.AddFilterByZipParams(_fakeZip, "", _fakeUnit);
            var expectedResult = $"zip={_fakeZip},DE&units={_fakeUnit}&appid=AppId";

            // Act
            var actualResult = _openWeatherMapClientParam.ToQueryString();

            // Assert
            Assert.AreEqual(expectedResult, actualResult);
        }