public WeatherDataController(
     DarkSkyWeatherService darkSkyWeatherService,
     OpenWeatherService openWeatherService)
 {
     DarkSkyWeatherService = darkSkyWeatherService;
     OpenWeatherService    = openWeatherService;
 }
示例#2
0
 public UpdateWeatherForecasts(
     ILoginService loginService,
     IWeatherDataService documentStore,
     IClock clock,
     IUserSettignsDataService userSettingsDataService,
     DarkSkyWeatherService weatherService) : base(loginService)
 {
     this.documentStore           = documentStore;
     this.clock                   = clock;
     this.userSettingsDataService = userSettingsDataService;
     this.weatherService          = weatherService;
 }
        public async Task GetWeather()
        {
            String sentUrl     = null;
            String expectedUrl = string.Format
                                 (
                "{0}{1}/{2},{3}?units={4}",
                settings.Url,
                settings.Token,
                1,
                1,
                "si"
                                 );

            var        serialisedWeather = File.ReadAllText(@"../../../Resources/weather.json");
            GetWeather weather           = JsonConvert.DeserializeObject <GetWeather>(serialisedWeather);
            var        expectedFirst     = weather.Hourly.Data[2];

            _mockHttpClient.Setup(cli => cli.GetAsync(It.IsAny <string>()))
            .Callback <string>(url => sentUrl = url)
            .ReturnsAsync(new HttpResponseMessage {
                StatusCode = HttpStatusCode.OK
            });
            _mockHttpResponseMapper.Setup(mpr => mpr.ParseResponse <GetWeather>(It.IsAny <HttpResponseMessage>()))
            .ReturnsAsync(weather);

            var darkSkyWeatherService = new DarkSkyWeatherService
                                        (
                settings,
                _mockHttpClient.Object,
                _mockHttpResponseMapper.Object,
                _mockCache.Object,
                new LoggerFactory().CreateLogger <DarkSkyWeatherService>()
                                        );
            var fetchedWeather = await darkSkyWeatherService.GetWeather(1, 1);

            Assert.Equal(expectedFirst.Time, fetchedWeather.Date);
            Assert.Equal(expectedUrl, sentUrl);
        }
        public async Task <IActionResult> DarkSkyWeatherForecasts()
        {
            WeatherData weatherForecast = await DarkSkyWeatherService.GetWeatherData(1, 2);

            return(Ok(weatherForecast));
        }