public void GetReturnsNullWhenApiReponseIsNull() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 12345; forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(null); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNull(response); }
public void GetReturnsEmptyObjectWhenApiResponseIsEmptyJson() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 12345; ForecastResponse apiresponse = new ForecastResponse("{\"cod\":\"0\"}"); forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(apiresponse); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNotNull(response); Assert.AreEqual(response, apiresponse); }
public void GetCapturesAllForecastsWhenApiResponseContainsMultipleForecasts() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 2643743; ForecastResponse apiresponse = new ForecastResponse(GetJson()); forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(apiresponse); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNotNull(response); Assert.AreEqual(response, apiresponse); Assert.AreEqual(7, response.Forecasts.Count); }
public void GetWeatherDescriptionWhenApiResponseContainsDescription() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 2643743; ForecastResponse apiresponse = new ForecastResponse(GetJson()); forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(apiresponse); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNotNull(response); Assert.AreEqual(response, apiresponse); Assert.AreEqual("Rain", response.Forecasts[0].WeatherList[0].Summary); Assert.AreEqual("light rain", response.Forecasts[0].WeatherList[0].Description); Assert.AreEqual("10d", response.Forecasts[0].WeatherList[0].Icon); }
public void GetReturnsCityObjectWhenApiResponseContainsCityJson() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 2643743; ForecastResponse apiresponse = new ForecastResponse(GetJson()); forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(apiresponse); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNotNull(response); Assert.AreEqual(response, apiresponse); Assert.AreEqual(2643743, response.City.Id); Assert.AreEqual("London", response.City.Name); Assert.AreEqual("GB", response.City.CountryCode); Assert.AreEqual(51.5085, response.City.Latitude); Assert.AreEqual(-0.1258, response.City.Longitude); }
public void GetTempratureForTheDayWhenApiResponseContainsDailyTempratureForecast() { IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>(); int cityId = 2643743; ForecastResponse apiresponse = new ForecastResponse(GetJson()); forecastProxy.Expect(x => x.GetForecastByCityId(cityId)).Return(apiresponse); WeatherController controller = new WeatherController(forecastProxy); var response = controller.Get(cityId); Assert.IsNotNull(response); Assert.AreEqual(response, apiresponse); Assert.AreEqual(17.6, response.Forecasts[0].Temperature.Day); Assert.AreEqual(17.6, response.Forecasts[0].Temperature.Evening); Assert.AreEqual(17.6, response.Forecasts[0].Temperature.Max); Assert.AreEqual(17.6, response.Forecasts[0].Temperature.Max); Assert.AreEqual(14.16, response.Forecasts[0].Temperature.Night); Assert.AreEqual(17.6, response.Forecasts[0].Temperature.Morning); }