public async Task OpenWeatherMapSuccess() { var mock = new Mock <IHttpClient>(); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getOpenWeatherMockData()); var parserOpenWeather = new ParserOpenWeather(mock.Object); var weather = await parserOpenWeather.GetWeatherInfoAsync(); Assert.IsNotNull(weather); Assert.AreEqual((int)weather.CelsiusTemperature, 283); Assert.AreEqual((int)weather.FahrenheitTemperature, 315); Assert.AreEqual(weather.Precipitation, "Clear"); Assert.AreEqual(weather.Humidity, 47); Assert.AreEqual(weather.CloudCover, "0"); Assert.AreEqual(weather.WindSpeed, 6); Assert.AreEqual(weather.WindDirection, "NE"); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getOpenWeatherMockSEData()); weather = await parserOpenWeather.GetWeatherInfoAsync(); Assert.AreEqual(weather.WindDirection, "SE"); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getOpenWeatherMockSWData()); weather = await parserOpenWeather.GetWeatherInfoAsync(); Assert.AreEqual(weather.WindDirection, "SW"); mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getOpenWeatherMockNWData()); weather = await parserOpenWeather.GetWeatherInfoAsync(); Assert.AreEqual(weather.WindDirection, "NW"); Assert.Pass(); }
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(); }
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 OpenWeatherMapFail() { var mock = new Mock <IHttpClient>(); try { mock.Setup(x => x.GetData(It.IsAny <string>())).Returns(getFailedMockData()); var parserOpenWeather = new ParserOpenWeather(mock.Object); var weather = await parserOpenWeather.GetWeatherInfoAsync(); } catch { Assert.Pass(); } Assert.Fail(); }