예제 #1
0
        private async Task <WeatherModel> LoadWeather()
        {
            string       url      = GetURL();
            WeatherModel response = new WeatherModel();

            try
            {
                response = await APIProcessor <WeatherModel> .APICall(GetURL());
            }
            catch (Exception e)
            {
                response = await APIProcessor <WeatherModel> .APICall(GetDefaultURL());

                MessageBox.Show("Error while loading weather data. Server response: " + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(response);
        }
예제 #2
0
        public async Task APIProcessor_Scenario_APICall_ReturnsWeatherModel()
        {
            //Arrange
            APIHelper.InitializeClient();

            //Act
            string       url          = "https://samples.openweathermap.org/data/2.5/weather?id=2172797&appid=b6907d289e10d714a6e88b30761fae22";
            WeatherModel actualResult = await APIProcessor <WeatherModel> .APICall(url);

            HttpResponseMessage response = await APIHelper.APIClient.GetAsync(url);

            WeatherModel expectedResult = await response.Content.ReadAsAsync <WeatherModel>();

            Task.WaitAll();

            //Assert
            Assert.IsTrue(actualResult == expectedResult);
        }