public async void ReturnsNullIfApiCallFails()
        {
            var mockHandler = GetMockMessageHandler(HttpStatusCode.GatewayTimeout, null);
            var mockFactory = GetMockHttpClientFactory(mockHandler.Object);
            var mockLogger  = new Mock <ILogger <WeatherApiClient> >();
            var apiClient   = new WeatherApiClient(mockFactory.Object, mockLogger.Object);
            // Act
            var result = await apiClient.GetLocation(1234);

            // Assert
            Assert.Null(result);
        }
        public async void ReturnsARedWarningWhenWindSpeedIsOverSeventy()
        {
            string locationData = File.ReadAllText("../../../Fixtures/red-warning.json");
            var    mockHandler  = GetMockMessageHandler(HttpStatusCode.OK, new StringContent(locationData));
            var    mockFactory  = GetMockHttpClientFactory(mockHandler.Object);
            var    mockLogger   = new Mock <ILogger <WeatherApiClient> >();
            var    apiClient    = new WeatherApiClient(mockFactory.Object, mockLogger.Object);

            // Act
            var result = await apiClient.GetLocation(1234);

            // Assert
            Assert.Equal("red", result.ConsolidatedWeather[0].Warning);
        }
        public async void ReturnsSixDaysWeather()
        {
            string locationData = File.ReadAllText("../../../Fixtures/london.json");
            var    mockHandler  = GetMockMessageHandler(HttpStatusCode.OK, new StringContent(locationData));
            var    mockFactory  = GetMockHttpClientFactory(mockHandler.Object);
            var    mockLogger   = new Mock <ILogger <WeatherApiClient> >();
            var    apiClient    = new WeatherApiClient(mockFactory.Object, mockLogger.Object);

            // Act
            var result = await apiClient.GetLocation(31253);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(6, result.ConsolidatedWeather.Count);
        }
        public async void ReturnsNullIfZeroIsPassed()
        {
            var mockHandler = GetMockMessageHandler(HttpStatusCode.GatewayTimeout, null);
            var mockFactory = GetMockHttpClientFactory(mockHandler.Object);
            var mockLogger  = new Mock <ILogger <WeatherApiClient> >();
            var apiClient   = new WeatherApiClient(mockFactory.Object, mockLogger.Object);

            // Act
            var result = await apiClient.GetLocation(0);

            // Assert
            Assert.Null(result);
            var expectedUri = new Uri($"{_defaultBaseUrl}/api/location/");

            mockHandler.Protected().Verify(
                "SendAsync",
                Times.Exactly(0), // we expected a single external request
                ItExpr.Is <HttpRequestMessage>(req =>
                                               req.Method == HttpMethod.Get && // we expected a GET request
                                               req.RequestUri == expectedUri // to this uri
                                               ),
                ItExpr.IsAny <CancellationToken>()
                );
        }