Esempio n. 1
0
        public void GetWeatherItems_GivenBelfastAsLocation()
        {
            string             location = "belfast";
            MetaWeatherService service  = new MetaWeatherService();

            var weatherItems = service.GetWeatherItems(location);

            Assert.AreEqual(6, weatherItems.Count());
        }
Esempio n. 2
0
        public void GetMetaWeatherItems_GivenBelfastAsWhereOnEarthId()
        {
            long belfastWoeId          = 44544;
            MetaWeatherService service = new MetaWeatherService();

            var weatherItems = service.GetMetaWeatherItem(belfastWoeId);

            Assert.AreEqual(44544, weatherItems.WhereOnEarthId);
        }
Esempio n. 3
0
        public void GetWhereOnEarthId_GivenBelfastAsLocation()
        {
            string             location = "belfast";
            MetaWeatherService service  = new MetaWeatherService();

            var woeId = service.GetWhereOnEarthId(location);

            Assert.AreEqual(44544, woeId);
        }
Esempio n. 4
0
        public async void GetLocations_One(string city, int expectedResult)
        {
            // 1. Arrange
            MetaWeatherService metaService = new MetaWeatherService();

            // 2. Act
            var result = await metaService.GetLocations(city);

            // 3. Assert
            Assert.Equal(expectedResult, result[0].Woeid);
        }
Esempio n. 5
0
        public async void GetWeather_ZeroOrMines(int woeid, int expectedResult)
        {
            // 1. Arrange
            MetaWeatherService metaService = new MetaWeatherService();

            // 2. Act
            var result = await metaService.GetWeather(woeid);

            // 3. Assert
            Assert.Equal(expectedResult, result.Count);
        }
        private WeatherForecastViewModel GetWeatherData(string location)
        {
            IWeatherService service = new MetaWeatherService();

            var weatherItems = service.GetWeatherItems(location);
            var top5Items    = weatherItems.Count() > 4 ? weatherItems.Take(5) : weatherItems;

            WeatherForecastViewModel model = new WeatherForecastViewModel
            {
                WeatherItems = top5Items,
                Location     = location
            };

            return(model);
        }
        public async Task <List <ConsolidatedWeather> > GetWeather(int woeid)
        {
            List <ConsolidatedWeather> weatherForecasts = new List <ConsolidatedWeather>();
            MetaWeatherService         metaService      = new MetaWeatherService();

            try
            {
                weatherForecasts = await metaService.GetWeather(woeid);
            }
            catch (Exception exp)
            {
                _logger.LogError(exp.Message);
            };

            return(weatherForecasts);
        }
        public async Task <List <Location> > GetLocations(string city)
        {
            List <Location>    locations   = new List <Location>();
            MetaWeatherService metaService = new MetaWeatherService();

            try
            {
                locations = await metaService.GetLocations(city);
            }
            catch (Exception exp)
            {
                _logger.LogError(exp.Message);
            };

            return(locations);
        }
        public MetaWeatherServiceTest()
        {
            var clientFactory = new Mock <IHttpClientFactory>();

            clientFactory.Setup(x => x.CreateClient("MetaWeatherApiUrl"))
            .Returns(new HttpClient
            {
                BaseAddress = new Uri("http://localhost:7070")
            });

            service = new MetaWeatherService(clientFactory.Object);

            if (server == null)
            {
                server = FluentMockServer.Start("http://localhost:7070");
            }
        }
Esempio n. 10
0
        public MetaWeatherServiceTests()
        {
            var restClient = new RestClient("https://www.metaweather.com/api/");

            _weatherService = new MetaWeatherService(restClient);
        }