public async Task ConsoleOutputTest() { var weather = new Weather(null, null, null, null, null, null, null); var mock = new Mock <IHttpClient>(); ConsoleOutput.OutputWeather(weather); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getOpenWeatherMockData()); var parserOpenWeather = new ParserOpenWeather(mock.Object); var parserTomorrowIo = new ParserTomorrowIo(mock.Object); weather = await parserOpenWeather.GetWeatherInfoAsync(); try { ConsoleOutput.OutputWeather(weather); ConsoleOutput.OutputExitMessage(); ConsoleOutput.OutputExitMessage(); ConsoleOutput.OutputSiteName(parserOpenWeather); ConsoleOutput.OutputSiteName(parserTomorrowIo); } catch { Assert.Fail(); } Assert.Pass(); }
public async Task TomorrowIoPrecipitation() { var mock = new Mock <IHttpClient>(); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getTomorrowIoRainData()); var parserTomorrowIo = new ParserTomorrowIo(mock.Object); var weather = await parserTomorrowIo.GetWeatherInfoAsync(); Assert.IsNotNull(weather); Assert.AreEqual((int)weather.CelsiusTemperature, 9); Assert.AreEqual((int)weather.FahrenheitTemperature, 41); Assert.AreEqual(weather.Precipitation, "Rain"); Assert.AreEqual(weather.Humidity, 55); Assert.AreEqual(weather.CloudCover, "98"); Assert.AreEqual((int)weather.WindSpeed, 5); Assert.AreEqual(weather.WindDirection, "NE"); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getTomorrowIoSnowData()); weather = await parserTomorrowIo.GetWeatherInfoAsync(); Assert.AreEqual(weather.Precipitation, "Snow"); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getTomorrowIoNoData()); weather = await parserTomorrowIo.GetWeatherInfoAsync(); Assert.AreEqual(weather.Precipitation, "Undefined"); Assert.Pass(); }
private async void LoadWeather() { MyHttpClient client = new MyHttpClient(); IParser parserTomorrowIo = new ParserTomorrowIo(client); IParser parserOpenWeather = new ParserOpenWeather(client); _weatherTomorrowIo = await GetWeather(parserTomorrowIo); _weatherOpenWeather = await GetWeather(parserOpenWeather); try { _weatherTomorrowIo = await GetWeather(parserTomorrowIo); } catch { _weatherTomorrowIo = null; } try { _weatherOpenWeather = await GetWeather(parserOpenWeather); } catch { _weatherOpenWeather = null; } UpdatePanelData(rightPanel, _weatherTomorrowIo); UpdatePanelData(leftPanel, _weatherOpenWeather); }
private async void LoadWeather() { MyHttpClient client = new MyHttpClient(); IParser parserTomorrowIo = new ParserTomorrowIo(client); IParser parserOpenWeather = new ParserOpenWeather(client); Weather.Weather weatherTomorrowIo; Weather.Weather weatherOpenWeather; try { weatherTomorrowIo = await GetWeather(parserTomorrowIo); } catch { weatherTomorrowIo = null; } try { weatherOpenWeather = await GetWeather(parserOpenWeather); } catch { weatherOpenWeather = null; } UpdateGrid(tomorrowIoGrid, weatherTomorrowIo); UpdateGrid(openWeatherGrid, weatherOpenWeather); }
public void NameTest() { var openWeather = new ParserOpenWeather(new MyHttpClient()); var tomorrowIo = new ParserTomorrowIo(new MyHttpClient()); Assert.AreEqual(tomorrowIo.Name, "TomorrowIo"); Assert.AreEqual(openWeather.Name, "OpenWeather"); }
public async Task TomorrowIoTest() { var mock = new Mock <IHttpClient>(); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getTomorrowIoData()); var parserTomorrowIo = new ParserTomorrowIo(mock.Object); var weather = await parserTomorrowIo.GetWeatherInfoAsync(); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getFailedMockDataTomorrowIo()); try { weather = await parserTomorrowIo.GetWeatherInfoAsync(); } catch { Assert.Pass(); } Assert.Fail(); }