public void GetForecastThrowsExceptionWhenCityIdIsInvalid() { IConfiguration configuration = MockRepository.GenerateMock <IConfiguration>(); configuration.Expect(x => x.OpenWeatherApiKey).Return(_openWeatherApiKey); configuration.Expect(x => x.OpenWeatherApiForecastUrl).Return(_forecastApiUrl); IForecastProxy forecastProxy = new ForecastProxy(configuration); Assert.That(() => forecastProxy.GetForecastByCityId(999999999999999999), Throws.Exception.TypeOf <InvalidUrlOrCityIdException>() .With.Message.Contains("The API url or the city id passed may be invalid")); }
public void GetForecastThrowsExceptionWhenCityIdIsNegative() { IConfiguration configuration = MockRepository.GenerateMock <IConfiguration>(); configuration.Expect(x => x.OpenWeatherApiKey).Return(_openWeatherApiKey); configuration.Expect(x => x.OpenWeatherApiForecastUrl).Return(_forecastApiUrl); IForecastProxy forecastProxy = new ForecastProxy(configuration); Assert.That(() => forecastProxy.GetForecastByCityId(-1), Throws.Exception.TypeOf <InvalidCityException>() .With.Message.Contains("Ensure that a valid city Id is passed")); }
public void GetForecastForLondon() { IConfiguration configuration = MockRepository.GenerateMock <IConfiguration>(); configuration.Expect(x => x.OpenWeatherApiKey).Return(_openWeatherApiKey); configuration.Expect(x => x.OpenWeatherApiForecastUrl).Return(_forecastApiUrl); IForecastProxy forecastProxy = new ForecastProxy(configuration); var response = forecastProxy.GetForecastByCityId(2643743); Assert.IsNotNull(response.Forecasts, "response.Forecasts != null"); Assert.IsTrue(response.Forecasts.Count > 0, "response.Forecasts.Count greater than 0"); Assert.IsNotNull(response.Forecasts[0].Clouds); Assert.IsNotNull(response.Forecasts[0].WeatherList); Assert.IsNotNull(response.Forecasts[0].Wind); Assert.IsNotNull(response.Forecasts[0].DateInUnixFormat); Assert.IsNotNull(response.Forecasts[0].Temperature); Assert.Greater(response.Forecasts[1].DateInLocalFormat, DateTime.Now); }