public async Task <IActionResult> getFiveDayWeatherByCityID(int id = 5395754) { WeatherWrapper weatherWrapper = null; using (var httpClient = new HttpClient()) { try{ string url = "https://api.openweathermap.org/data/2.5/forecast?id=" + id + "&APPID=" + API_KEY; var response = await httpClient.GetAsync(new Uri(url)).ConfigureAwait(false); response.EnsureSuccessStatusCode(); var stringResult = await response.Content.ReadAsStringAsync(); var rawData = JsonConvert.DeserializeObject <WeatherWrapper>(stringResult); weatherWrapper = new WeatherWrapper { city = rawData.city, list = rawData.list.Where(element => (rawData.list.IndexOf(element) % 8 == 0)? true : false). Select(element => { element.weather[0].icon = "http://openweathermap.org/img/w/" + element.weather[0].icon + ".png"; return(element); }).ToList(), }; return(Ok(weatherWrapper)); } catch (HttpRequestException httpRequestException) { return(BadRequest($"Error getting data: {httpRequestException.Message}")); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { wardrobe = e?.Parameter as Wardrobe; // Populate available type list var types = wardrobe.Garments.Select(g => g.Type.ToString()) .Distinct() .Select(t => new TypeWrapper { TypeName = t, TypeSelectCommand = new TypeSelectCommand(this), TypeUnselectCommand = new TypeUnselectCommand(this) }); UnselectedList.ItemsSource = types; // Populate weather info, if available DataContext = new WeatherWrapper(); // Populate weather advice var advices = WeatherUtil.GenerateAdvice() .Select(a => new CodeToLocalizedWeatherAdviceConverter().Convert(a)) .ToList(); WeatherAdvice.ItemsSource = advices.Select(a => (WeatherAdviceWrapper)a); }
public void CheckForecastioIsActive() { var factory = new Mock <IFactory>(); var forecastio = new Mock <IWeather>(); factory.Setup(m => m.GetInstances()).Returns(new List <IWeather>() { new Forecastio() }); var wrapper = new WeatherWrapper(factory.Object); var forecast = wrapper.ForecastLookup(); Assert.AreEqual(forecast[0].Provider, "Forecast.io"); }