public async Task CallSetLocationOnceWithOneQueryLocationOnGetForecast()
        {
            var    location    = "Karlsruhe,de";
            string urlLocation = string.Empty;
            var    urlBuilder  = CreateFluentUrlProvider();
            var    mockQuery   = CreateQuery(location);
            var    client      = CreateClient();

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);
            await serviceUnderTest.GetForecasts(mockQuery.Object);

            urlBuilder.Verify(builder => builder.SetLocation(It.IsAny <string>()), Times.Once);
        }
        public async Task CallClientWithUrlFromUrlBuilderWhenQueriedWithOneQueryLocation()
        {
            var Location   = "Karlsruhe,de";
            var urlBuilder = CreateFluentUrlProvider("http://api.openweathermap.org/data/2.5/forecast");
            var client     = CreateClient();
            var mockQuery  = CreateQuery(Location);

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            await serviceUnderTest.GetForecasts(mockQuery.Object);

            client.Verify(cli => cli.GetForecastAsync(It.IsAny <string>()), Times.Once);
        }
        public async Task BuildUrlFromEveryLocationInQueryOnGetForecast()
        {
            string firstLocation  = "Karlsruhe,de";
            string secondLocation = "Stuttgart,de";
            var    urlBuilder     = CreateFluentUrlProvider();
            var    client         = CreateClient();

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);
            await serviceUnderTest.GetForecasts(CreateQuery(new List <string>()
            {
                firstLocation, secondLocation
            }).Object);

            urlBuilder.Verify(builder => builder.SetLocation(It.IsAny <string>()), Times.Exactly(2));
        }
        public async Task CallClientWithEachUrlFromurlBuilderForEachQueryLocation()
        {
            string firstLocation  = "Karlsruhe,de";
            string secondLocation = "Stuttgart,de";
            var    urlBuilder     = CreateFluentUrlProviderWithReturnUrl();
            var    client         = CreateClient();
            var    mockQuery      = CreateQuery(new List <string>()
            {
                firstLocation, secondLocation
            });

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            await serviceUnderTest.GetForecasts(mockQuery.Object);

            client.Verify(cli => cli.GetForecastAsync(It.IsAny <string>()), Times.Exactly(2));
        }
        public async Task ReturnEmptyIEnumerableWhenNoMatchFound()
        {
            string location   = "Karlsruhe,de";
            var    urlBuilder = CreateFluentUrlProviderWithReturnUrl();
            var    client     = CreateClient(new List <Helper.Maybe <ForecastResponse> >()
            {
                new Helper.Maybe <ForecastResponse>(ForecastResponse.FromJson(TestData.ForecastResponseKarlsruhe))
            });
            var mockQuery = CreateQuery(location);

            mockQuery.Setup(query => query.IsSatisfiedBy(It.IsAny <Forecast>()))
            .Returns((Forecast forecast) => false);

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            var result = await serviceUnderTest.GetForecasts(mockQuery.Object);

            Assert.False(result.Any());
        }
        public async Task ReturnsIEnumerableForGetForecast()
        {
            string location   = "Karlsruhe,de";
            var    urlBuilder = CreateFluentUrlProviderWithReturnUrl();
            var    client     = CreateClient(new List <Helper.Maybe <ForecastResponse> >()
            {
                new Helper.Maybe <ForecastResponse>(ForecastResponse.FromJson(TestData.ForecastResponseKarlsruhe))
            });
            var mockQuery = CreateQuery(location);

            mockQuery.Setup(query => query.IsSatisfiedBy(It.IsAny <Forecast>()))
            .Returns((Forecast forecast) => forecast.MeasureTime.Equals(new DateTimeOffset(2019, 7, 30, 21, 0, 0, new TimeSpan())));

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            var result = await serviceUnderTest.GetForecasts(mockQuery.Object);

            Assert.IsAssignableFrom <IEnumerable <ForecastResult> >(result);
        }
        public async Task OneQueryWithOneLocationAndTwoHitsReturnsOneForecastResultWithTwoElements()
        {
            string location   = "Karlsruhe,de";
            var    urlBuilder = CreateFluentUrlProviderWithReturnUrl();
            var    client     = CreateClient(new List <Helper.Maybe <ForecastResponse> >()
            {
                new Helper.Maybe <ForecastResponse>(ForecastResponse.FromJson(TestData.ForecastResponseKarlsruhe))
            });
            var mockQuery = CreateQuery(location);

            mockQuery.Setup(query => query.IsSatisfiedBy(It.IsAny <Forecast>()))
            .Returns((Forecast forecast) =>
            {
                return(forecast.MeasureTime.Equals(new DateTime(2019, 7, 30, 21, 0, 0)) ||
                       forecast.MeasureTime.Equals(new DateTime(2019, 7, 31, 9, 0, 0)));
            });

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            var result = await serviceUnderTest.GetForecasts(mockQuery.Object);

            Assert.True(result.First().ForecastData.Count == 2);
        }
        public async Task ReturnTwoForecastResultsWhenGivenTwoLocationsInQuery()
        {
            string firstLocation  = "Karlsruhe,de";
            string secondLocation = "Stuttgart,de";
            var    urlBuilder     = CreateFluentUrlProviderWithReturnUrl();
            var    client         = CreateClient(new List <Helper.Maybe <ForecastResponse> >()
            {
                new Helper.Maybe <ForecastResponse>(ForecastResponse.FromJson(TestData.ForecastResponseKarlsruhe)),
                new Helper.Maybe <ForecastResponse>(ForecastResponse.FromJson(TestData.ForecastResponseStuttgart))
            });
            var mockQuery = CreateQuery(new List <string>()
            {
                firstLocation, secondLocation
            });

            mockQuery.Setup(query => query.IsSatisfiedBy(It.IsAny <Forecast>()))
            .Returns((Forecast forecast) => forecast.MeasureTime.Equals(new DateTime(2019, 7, 30, 21, 0, 0)));

            var serviceUnderTest = new OpenWeatherService(client.Object, urlBuilder.Object);

            var result = await serviceUnderTest.GetForecasts(mockQuery.Object);

            Assert.True(result.Count() == 2);
        }