Пример #1
0
        public async Task <ActionResult> SyncWeather()
        {
            var service = new WeatherDataService();
            var url     = ConfigurationManager.AppSettings["api:url"];
            var apiKey  = ConfigurationManager.AppSettings["api:key"];
            var model   = new WeatherSyncModel();

            try
            {
                var result = await service.ImportWeatherData(url, apiKey);

                if (result)
                {
                    model.Success = true;
                    model.Message = "Sync done";
                }
                else
                {
                    model.Success = false;
                    model.Message = "API returned false";
                }
            }
            catch (Exception ex)
            {
                model.Success = false;
                model.Message = ex.Message;
            }

            return(View(model));
        }
        public async void ImportWeatherDataForOneCityTest()
        {
            const int cityId  = 18;
            var       service = new WeatherDataService();
            var       result  = await service.ImportWeatherData(Url, ApiKey, cityId);

            Assert.IsTrue(result);
        }