示例#1
0
 private static void ValidateSpec(ISpecification <Forecast> spec)
 {
     if (spec is null)
     {
         throw new ArgumentNullException(ErrorMessages.ArgumentNullMessage(nameof(spec)));
     }
 }
示例#2
0
        private static void ValidateLocation(string location)
        {
            if (location is null)
            {
                throw new ArgumentNullException(ErrorMessages.ArgumentNullMessage(nameof(location)));
            }

            if (string.IsNullOrEmpty(location))
            {
                throw new ArgumentException(ErrorMessages.LocationMustNotBeEmptyError);
            }
        }
示例#3
0
        private void ValidateEnumerableInput <T>(IEnumerable <T> enumerable, Action <T> validateElementAction)
        {
            if (enumerable is null)
            {
                throw new ArgumentNullException(ErrorMessages.ArgumentNullMessage(nameof(enumerable)));
            }

            if (!enumerable.Any())
            {
                throw new ArgumentException(ErrorMessages.QueryMustContainAtLeastOneElementError);
            }

            foreach (var item in enumerable)
            {
                validateElementAction(item);
            }
        }
示例#4
0
        public async Task <IEnumerable <IForecastResult> > GetForecasts(IQuery <string, Forecast> currentQuery)
        {
            if (currentQuery == null)
            {
                throw new ArgumentNullException(ErrorMessages.ArgumentNullMessage(nameof(currentQuery)));
            }

            var tasksToExecute = currentQuery.Queries.Select(queryLocation => UrlProvider.SetLocation(queryLocation).GetUriAsString())
                                 .Select(urlToCall => Client.GetForecastAsync(urlToCall));

            var results = await Task.WhenAll(tasksToExecute).ConfigureAwait(false);

            return(results.Where(response => response.Any())
                   .Select(response => response.Single())
                   .Select(response =>
            {
                var tempResult = new ForecastResult(response.City.DisplayName);
                var Satisfied = response.Forecasts.Where(forecast => currentQuery.IsSatisfiedBy(forecast));
                tempResult.AddRange(Satisfied);
                return tempResult;
            }).
                   Where(matchedForecast => matchedForecast.ForecastData.Any()) // Filter out, if no match was found
                   .ToList());
        }