private static void ValidateSpec(ISpecification <Forecast> spec) { if (spec is null) { throw new ArgumentNullException(ErrorMessages.ArgumentNullMessage(nameof(spec))); } }
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); } }
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); } }
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()); }