Example #1
0
        public void CurrentTempAsync__CallsOpenWithGet()
        {
            var handlerMock = SetupBackend(x => x.Method == HttpMethod.Get);

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            Func <Task> act = async() => await weather.CurrentTempAsync(new Coord(0d, 0d));

            act.Should().NotThrow();
        }
Example #2
0
        public void CurrentTempAsync__CallsOpenWeather()
        {
            var handlerMock = SetupBackend(x => x.RequestUri.AbsoluteUri.StartsWith("http://api.openweathermap.org/data/2.5/weather"));

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            Func <Task> act = async() => await weather.CurrentTempAsync(new Coord(0d, 0d));

            act.Should().NotThrow();
        }
Example #3
0
        public void CurrentTempAsync__ThrowsExceptionWhenApiFails()
        {
            var handlerMock = SetupBackend(response: FailedResponse);

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            Func <Task> act = async() => await weather.CurrentTempAsync(new Coord(0d, 0d));

            act.Should().Throw <ApiException>().WithMessage($"*{failedMessage}");
        }
Example #4
0
        public async Task CurrentTempAsync__ReturnsTheTempature()
        {
            var handlerMock = SetupBackend();

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            var actual = await weather.CurrentTempAsync(new Coord(0d, 0d));

            actual.Should().BeApproximately(temp, 2d);
        }
Example #5
0
        public void CurrentTempAsync__AddsTheLocation()
        {
            var coord       = new Coord(41.65d, -93.71d);
            var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"lat={coord.Lat}") && x.RequestUri.Query.Contains($"lon={coord.Lng}"));

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            Func <Task> act = async() => await weather.CurrentTempAsync(coord);

            act.Should().NotThrow();
        }
Example #6
0
        public void CurrentTempAsync__AddsTheApiKey()
        {
            var apiKey      = "Foobar";
            var handlerMock = SetupBackend(x => x.RequestUri.Query.Contains($"APPID={apiKey}"));

            var client  = new HttpClient(handlerMock.Object);
            var weather = new OpenWeather(client, apiKey);

            Func <Task> act = async() => await weather.CurrentTempAsync(new Coord(0d, 0d));

            act.Should().NotThrow();
        }