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(); }
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(); }