Пример #1
0
        public void ConstructClassUnderTest()
        {
            IForecastProxy forecastProxy = MockRepository.GenerateMock <IForecastProxy>();

            WeatherController controller = new WeatherController(forecastProxy);

            Assert.IsNotNull(controller);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 public WeatherController(IForecastProxy forecastProxy)
 {
     _forecastProxy = forecastProxy;
 }