示例#1
0
        public async Task QueryAsyncTest()
        {
            var weatherService = new WeatherStackService();
            var response       = await weatherService.QueryCurrentAsync("New York");

            Assert.Greater(response.current.pressure, 0);
        }
示例#2
0
 /// <summary>
 /// Creates an instance of the <see cref="MainViewModel"/>
 /// </summary>
 public MainViewModel(IViewFacade viewFacade, WeatherStackService weatherService,
                      Func <WeatherQueryResponse, WeatherViewModel> weatherViewModelFactory,
                      Func <string, ErrorViewModel> errorViewModelFactory)
 {
     ViewFacade                   = viewFacade;
     this.WeatherService          = weatherService;
     this.WeatherViewModelFactory = weatherViewModelFactory;
     ErrorViewModelFactory        = errorViewModelFactory;
 }
示例#3
0
        public void GivenMockResponse_WeatherMap_TransformResponse_ShouldReturnValidData()
        {
            using (StreamReader r = new StreamReader("weatherMapResponse.json"))
            {
                string mockResponse = r.ReadToEnd();


                var optionMock        = new Mock <IOptions <WeatherStackConfig> >();
                var weatherMapService = new WeatherStackService(optionMock.Object);
                var(weatherOutput, error) = weatherMapService.TransformResponse(mockResponse);

                Assert.Empty(error);
                Assert.Equal(15, weatherOutput.temperature_degrees);
                Assert.Equal(35, weatherOutput.wind_speed);
            }
        }
示例#4
0
        public async Task GivenAllBadWeatherSources_Handle_ShouldGetFromMemoryCache()
        {
            GetCurrentWeatherQuery query = new GetCurrentWeatherQuery("AU", "Melbourne");

            IOptions <OpenWeatherMapConfig> config = Options.Create(new OpenWeatherMapConfig
            {
                BaseURL       = "WillFailURL",
                Units         = UnitsEnum.Metric,
                PriorityOrder = 1
            });
            OpenWeatherMapService openWeatherMapService = new OpenWeatherMapService(config);

            IOptions <WeatherStackConfig> weatherStackConfig = Options.Create(new WeatherStackConfig
            {
                BaseURL       = "WillFailURL",
                Units         = UnitsEnum.Metric,
                PriorityOrder = 2
            });
            var weatherStackService = new WeatherStackService(weatherStackConfig);

            List <IWeatherService> weatherServices = new List <IWeatherService>
            {
                weatherStackService, openWeatherMapService
            };

            var memoryCache = new Mock <IMemoryCacheService>();

            memoryCache.Setup(m => m.GetValueFromCache <WeatherOutputModel>(It.IsAny <string>())).Returns(new WeatherOutputModel(5, 23));

            GetCurrentWeatherQueryHandler queryHandler = new GetCurrentWeatherQueryHandler(weatherServices, memoryCache.Object);

            var(weatherOutput, error) = await queryHandler.Handle(query, CancellationToken.None);

            //assert
            Assert.Empty(error);
            Assert.Equal(5, weatherOutput.wind_speed);
            Assert.Equal(23, weatherOutput.temperature_degrees);
        }