Example #1
0
        public async void TimeMachineExclusionWorksCorrectly()
        {
            // prepare
            var      date   = new DateTime(2021, 01, 24, 10, 00, 01, DateTimeKind.Utc);
            Forecast output = null;

            using (var stream = new BufferedStream(File.OpenRead("./Resources/DarkSky_GetWeatherByDate_SI.json"), 8192)) {
                var mockHttp = new MockHttpMessageHandler();
                mockHttp
                .When(DarkSkyService.EndPointRoot + "*")
                .Respond("application/json", stream);

                var exclusionList = new List <Exclude> {
                    Exclude.Minutely, Exclude.Hourly
                };
                IDarkSkyService client = new DarkSkyService("a_valid_key", mockHttp);
                output = await client.GetWeatherByDate(AlcatrazLatitude, AlcatrazLongitude, date, exclusionList, DSUnit.SI);

                stream.Close();
            }

            Assert.NotNull(output);
            Assert.Null(output.Hourly);
            Assert.NotNull(output.Currently);
            Assert.NotNull(output.Daily);
            Assert.NotNull(output.Daily.Data);
            output.Daily.Data.Count.ShouldBe(1);
            output.Daily.Data[0].Time.Date.ShouldBe(date.Date);
        }
Example #2
0
        public void InvalidKeyThrowsException()
        {
            // prepare
            var mockHttp = new MockHttpMessageHandler();

            mockHttp
            .When(DarkSkyService.EndPointRoot + "*")
            .Respond(HttpStatusCode.Unauthorized);
            // assert
            var client = new DarkSkyService(null, mockHttp);

            Assert.ThrowsAsync <WeatherException>(async() => await client.GetCurrentWeather(AlcatrazLatitude, AlcatrazLongitude));
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetForecast(AlcatrazLatitude, AlcatrazLongitude));
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetWeatherByDate(AlcatrazLatitude, AlcatrazLongitude, DateTime.Today.AddDays(+1)));

            client = new DarkSkyService(string.Empty, mockHttp);
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetCurrentWeather(AlcatrazLatitude, AlcatrazLongitude));
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetForecast(AlcatrazLatitude, AlcatrazLongitude));
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetWeatherByDate(AlcatrazLatitude, AlcatrazLongitude, DateTime.Today.AddDays(+1)));

            client = new DarkSkyService("fake_key", mockHttp);
            Assert.ThrowsAsync <WeatherException>(async() => await client.GetWeatherByDate(AlcatrazLatitude, AlcatrazLongitude, DateTime.Today.AddDays(+1)));
        }