Пример #1
0
        public async Task <PaginationResults> GetServices(string apiBaseUrl, string id, WebServiceReader webServiceReader, APIValidatorSettings settings = null)
        {
            settings = settings ?? new APIValidatorSettings();

            var paginationResults = new PaginationResults();

            async Task <bool> processor(dynamic serviceList, int totalPages, int hash)
            {
                if (serviceList == null)
                {
                    return(true);
                }

                paginationResults.MissingPaginationMetaData = GetMissingPaginationMetadata(serviceList);
                paginationResults.Hashes.Add(hash);

                try
                {
                    paginationResults.TotalPages = Convert.ToInt32(serviceList.totalPages);
                }
                catch
                {
                    paginationResults.HasInvalidTotalPages = true;
                }

                if (HasProperty(serviceList, "content"))
                {
                    if (settings.RandomServiceOnly)
                    {
                        await ValidateRandomService(apiBaseUrl, paginationResults, serviceList, webServiceReader);
                    }
                    else
                    {
                        List <dynamic> services = new List <dynamic>();
                        foreach (dynamic s in serviceList.content)
                        {
                            services.Add(s);
                        }

                        Parallel.ForEach(services, (s) =>
                        {
                            ValidateService(apiBaseUrl, paginationResults, s, webServiceReader).GetAwaiter().GetResult();
                        });
                    }
                }

                return(true);
            }

            int?maximumPages = null;

            if (settings != null && settings.SamplePages)
            {
                maximumPages = SampleSize;
            }

            await PaginateServices(apiBaseUrl, id, processor, webServiceReader, totalPagesOverride : settings.FirstPageOnly? 1 : maximumPages);

            return(paginationResults);
        }
Пример #2
0
        private static async Task ValidateService(string apiBaseUrl, PaginationResults paginationResults, dynamic service, WebServiceReader webServiceReader)
        {
            dynamic obj = service;

            try
            {
                WebServiceResponse result = await webServiceReader.ConvertToDynamic(apiBaseUrl + "/services/" + service.id);

                if (result != null)
                {
                    obj = result.Data;
                    paginationResults.HasAllowOrigin = result.HasAllowOrigin;
                }

                if (obj == null)
                {
                    obj = service;
                    paginationResults.MissingDetailIDs.Add(Convert.ToString(service.id));
                }
            }
            catch
            {
                try
                {
                    paginationResults.MissingDetailIDs.Add(Convert.ToString(service.id));
                }
                catch
                {
                    //bad data don't stop the test for this
                }
            }

            paginationResults.Items.Add(obj);
        }
Пример #3
0
        private static async Task <string> ValidateRandomService(string apiBaseUrl, PaginationResults paginationResults, dynamic serviceList, WebServiceReader webServiceReader)
        {
            var service = GetRandomService(serviceList);

            if (service == null)
            {
                return(null); // maybe a message is required
            }
            await ValidateService(apiBaseUrl, paginationResults, service, webServiceReader);

            return(Convert.ToString(service.id ?? null));
        }