public async Task GetWeatherForecastDataByCity_TwoDaysForecast_ShouldReturnExpectedValues( string cityName, int expectedItems, double expectedTemperatureDay1, double expectedHumidityDay1, double expectedWindSpeedDay1, double expectedTemperatureDay2, double expectedHumidityDay2, double expectedWindSpeedDay2) { //arrange var loggerMock = new Mock <ILogger <WeatherForecastDataProvider> >(); var getIWeatherForecastDataProviderClientMock = new Mock <IWeatherForecastDataProviderClient>(); getIWeatherForecastDataProviderClientMock.Setup(w => w.GetRawWeatherForecastDataByCity(cityName)) .ReturnsAsync(GetTwoDaysWeatherForecastResponse()); var sut = new WeatherForecastDataProvider(loggerMock.Object, getIWeatherForecastDataProviderClientMock.Object); //act var result = await sut.GetWeatherForecastDataByCity(cityName); //assert result.Should().NotBeNull(); result.Should().HaveCount(expectedItems); var weatherForecastResultDay1 = result.First(); weatherForecastResultDay1.Temperature.Should().Be(expectedTemperatureDay1); weatherForecastResultDay1.Humidity.Should().Be(expectedHumidityDay1); weatherForecastResultDay1.WindSpeed.Should().Be(expectedWindSpeedDay1); var weatherForecastResultDay2 = result.Last(); weatherForecastResultDay2.Temperature.Should().Be(expectedTemperatureDay2); weatherForecastResultDay2.Humidity.Should().Be(expectedHumidityDay2); weatherForecastResultDay2.WindSpeed.Should().Be(expectedWindSpeedDay2); }
public void TestGetWoeIdByLocationName() { var url = "https://www.metaweather.com/api"; var svc = new WeatherForecastDataProvider(new RestApiService(), url); var result = svc.GetWoeIdByLocationName("Belfast").GetAwaiter().GetResult(); Assert.NotNull(result); Assert.Equal(result, 44544); }
public void TestGetForecastByWoeId() { //Arrange var testWoeId = 44544; var nDays = 3; //Act var url = "https://www.metaweather.com/api"; var svc = new WeatherForecastDataProvider(new RestApiService(), url); var result = svc.GetForecastByWoeId(testWoeId, nDays).GetAwaiter().GetResult().ToList().Take(nDays).ToList(); //Assert Assert.NotNull(result); Assert.Equal(nDays, result.Count); }
public async Task GetWeatherForecastDataByCity_EmptyForecast_ShouldReturnExpectedValues(string cityName) { //arrange var loggerMock = new Mock <ILogger <WeatherForecastDataProvider> >(); var getIWeatherForecastDataProviderClientMock = new Mock <IWeatherForecastDataProviderClient>(); getIWeatherForecastDataProviderClientMock.Setup(w => w.GetRawWeatherForecastDataByCity(cityName)) .ReturnsAsync(new WeatherForecastResponse()); var sut = new WeatherForecastDataProvider(loggerMock.Object, getIWeatherForecastDataProviderClientMock.Object); //act var result = await sut.GetWeatherForecastDataByCity(cityName); //assert result.Should().NotBeNull(); result.Should().BeEmpty(); }