示例#1
0
        public void GivenFirstPageWithHalfPageExpected_WhenGetNextPageIndexCalled_ThenNextPageIndexIsTheSame()
        {
            var firstPageIndex = 1;
            var newPageIndex   = PageAdjuster.GetNextPageIndex(new PageInfo(firstPageIndex, DefaultPageSize), 125);

            newPageIndex.Should().Be(firstPageIndex);
        }
示例#2
0
        public void GivenPageWithHalfPageExpected_WhenGetNextPageIndexCalled_ThenNextPageIndexIsRecalculatedCorrectly()
        {
            var currentPageIndex = 5;
            var newPageIndex     = PageAdjuster.GetNextPageIndex(new PageInfo(currentPageIndex, DefaultPageSize), 125);

            newPageIndex.Should().Be(currentPageIndex * 2 - 1);
        }
示例#3
0
        public void GivenPageWithDefaultSize_WhenGetHalfPageCalled_ThenHalfPageSizeIsReturned()
        {
            var currentPageSize = DefaultPageSize;
            var newPageSize     = PageAdjuster.GetHalfPageSize(currentPageSize);

            newPageSize.Should().Be(DefaultPageSize / 2);
        }
示例#4
0
        public void GivenPageWithMinPage_WhenGetHalfPageCalled_ThenSamePageSizeIsReturned()
        {
            var currentPageSize = 1;
            var newPageSize     = PageAdjuster.GetHalfPageSize(currentPageSize);

            newPageSize.Should().Be(currentPageSize);
        }
        public void GivenPageWithIndexHigherThanFirst_WhenGetNextPageIndexWithDecreasedPageSizeTwiceIsCalled_ThenNextPageIndexIsRecalculatedCorrectly()
        {
            var currentPageIndex = 5;
            var newPageIndex     = PageAdjuster.GetNextPageIndex(new PageInfo(currentPageIndex, DefaultPageSize), 125);

            newPageIndex.Should().Be(currentPageIndex * 2 - 1);
        }
        public void GivenPageWithFirstIndex_WhenGetNextPageIndexWithDecreasedPageSizeTwiceIsCalled_ThenNextPageIndexIsTheSame()
        {
            var firstPageIndex = 1;
            var newPageIndex   = PageAdjuster.GetNextPageIndex(new PageInfo(firstPageIndex, DefaultPageSize), 125);

            newPageIndex.Should().Be(firstPageIndex);
        }
        public void GivenPageWithDecreasedTwiceDefaultPageSize_WhenGetNextPageIndexWithDecreasedPageSizeTwiceIsCalled_ThenNextPageIndexIsCalculatedCorrectly()
        {
            var currentPageIndex = 5;
            var currentPageSize  = DefaultPageSize / 2;
            var halfPageSize     = currentPageSize / 2;
            var newPageIndex     = PageAdjuster.GetNextPageIndex(new PageInfo(currentPageIndex, currentPageSize), halfPageSize);

            newPageIndex.Should().Be(currentPageIndex * 2 - 1);
        }
示例#8
0
        public void GivenResponseWithIOExceptionAndMinPageSize_WhenTryAdjustPageInfoCalled_ThenTheSamePageIsReturned()
        {
            var currentPageInfo    = new PageInfo(5, 62);
            var responseException  = new Exception(string.Empty, new IOException("Unable to read data"));
            var isResponseTooLarge = PageAdjuster.TryAdjustPageIfResponseTooLarge(currentPageInfo, MinPageSize, responseException, out PageInfo newPageInfo);

            isResponseTooLarge.Should().Be(false);
            newPageInfo.Size.Should().Be(currentPageInfo.Size);
            newPageInfo.Index.Should().Be(currentPageInfo.Index);
        }
示例#9
0
        public void GivenResponseWithInnerCommonException_WhenTryAdjustPageInfoCalled_ThenTheSamePageInfoIsReturned()
        {
            var currentPageInfo    = new PageInfo(5, DefaultPageSize);
            var responseException  = new Exception(string.Empty, new Exception("some unrepeatable error happened"));
            var isResponseTooLarge = PageAdjuster.TryAdjustPageIfResponseTooLarge(currentPageInfo, MinPageSize, responseException, out PageInfo newPageInfo);

            isResponseTooLarge.Should().Be(false);
            newPageInfo.Size.Should().Be(currentPageInfo.Size);
            newPageInfo.Index.Should().Be(currentPageInfo.Index);
        }
示例#10
0
        public void GivenResponseWithIOException_WhenTryAdjustPageInfoCalled_ThenAdjustedPageInfoIsReturned()
        {
            var initialPageIndex   = 5;
            var currentPageInfo    = new PageInfo(initialPageIndex, DefaultPageSize);
            var responseException  = new Exception(string.Empty, new IOException("Unable to read data"));
            var isResponseTooLarge = PageAdjuster.TryAdjustPageIfResponseTooLarge(currentPageInfo, MinPageSize, responseException, out PageInfo newPageInfo);

            isResponseTooLarge.Should().Be(true);
            newPageInfo.Size.Should().Be(DefaultPageSize / 2);
            newPageInfo.Index.Should().Be(initialPageIndex * 2 - 1);
        }
        public List <BigCommerceCategory> GetCategories()
        {
            var categories = new List <BigCommerceCategory>();
            var marker     = this.GetMarker();

            for (var i = 1; i < int.MaxValue; i++)
            {
                var endpoint             = "";    //mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)));
                var categoriesWithinPage = ActionPolicy.Handle <Exception>().Retry(ActionPolicies.RetryCount, (ex, retryAttempt) =>
                {
                    if (PageAdjuster.TryAdjustPageIfResponseTooLarge(new PageInfo(i, this.RequestMaxLimit), this.RequestMinLimit, ex, out var newPageInfo))
                    {
                        i = newPageInfo.Index;
                        this.RequestMaxLimit = newPageInfo.Size;
                    }

                    ActionPolicies.LogRetryAndWait(ex, marker, endpoint, retryAttempt);
                }).Get(() => {
                    return(this._webRequestServices.GetResponseByRelativeUrl <BigCommerceCategoryInfoData>(BigCommerceCommand.GetCategoriesV3, endpoint, marker));
                });

                this.CreateApiDelay(categoriesWithinPage.Limits).Wait();                 //API requirement

                if (categoriesWithinPage.Response == null)
                {
                    break;
                }

                foreach (var category in categoriesWithinPage.Response.Data)
                {
                    var CatURL = category.Category_URL;

                    categories.Add(new BigCommerceCategory
                    {
                        Id           = category.Id,
                        Category_URL = new BigCommerceCategoryURL()
                        {
                            Url = CatURL.Url
                        },
                        Category_Name = category.Name,
                        IsVisible     = category.IsVisible
                    });
                }

                if (categoriesWithinPage.Response.Data.Length < RequestMaxLimit)
                {
                    break;
                }
            }


            return(categories);
        }
        public List <BigCommerceProduct> GetProducts(bool includeExtendedInfo)
        {
            var mainEndpoint = "?include=variants,images";
            var products     = new List <BigCommerceProduct>();
            var marker       = this.GetMarker();

            for (var i = 1; i < int.MaxValue; i++)
            {
                var endpoint           = mainEndpoint.ConcatParams(ParamsBuilder.CreateGetNextPageParams(new BigCommerceCommandConfig(i, RequestMaxLimit)));
                var productsWithinPage = ActionPolicy.Handle <Exception>().Retry(ActionPolicies.RetryCount, (ex, retryAttempt) =>
                {
                    if (PageAdjuster.TryAdjustPageIfResponseTooLarge(new PageInfo(i, this.RequestMaxLimit), this.RequestMinLimit, ex, out var newPageInfo))
                    {
                        i = newPageInfo.Index;
                        this.RequestMaxLimit = newPageInfo.Size;
                    }

                    ActionPolicies.LogRetryAndWait(ex, marker, endpoint, retryAttempt);
                }).Get(() => {
                    return(this._webRequestServices.GetResponseByRelativeUrl <BigCommerceProductInfoData>(BigCommerceCommand.GetProductsV3, endpoint, marker));
                });

                this.CreateApiDelay(productsWithinPage.Limits).Wait();                 //API requirement

                if (productsWithinPage.Response == null)
                {
                    break;
                }

                foreach (var product in productsWithinPage.Response.Data)
                {
                    var productImageThumbnail = product.Images.FirstOrDefault(img => img.IsThumbnail);

                    var additional_images = product.Images;

                    var custom_url = product.Product_URL;

                    products.Add(new BigCommerceProduct
                    {
                        Id = product.Id,
                        InventoryTracking = this.ToCompatibleWithV2InventoryTrackingEnum(product.InventoryTracking),
                        Upc               = product.Upc,
                        Sku               = product.Sku,
                        Name              = product.Name,
                        Description       = product.Description,
                        Price             = product.Price,
                        IsProductVisible  = product.IsVisible,
                        Condition         = product.Condition,
                        Availability      = product.Availability,
                        ProductType       = product.Type,
                        SalePrice         = product.SalePrice,
                        RetailPrice       = product.RetailPrice,
                        CostPrice         = product.CostPrice,
                        Weight            = product.Weight,
                        BrandId           = product.BrandId,
                        Quantity          = product.Quantity,
                        Product_URL       = custom_url.ProductURL,
                        Categories        = product.Categories,
                        ThumbnailImageURL = new BigCommerceProductPrimaryImages()
                        {
                            StandardUrl = productImageThumbnail != null ? productImageThumbnail.UrlStandard : string.Empty
                        },
                        ProductOptions = product.Variants.Select(x => new BigCommerceProductOption
                        {
                            Id        = x.Id,
                            ProductId = x.ProductId,
                            Sku       = x.Sku,
                            Quantity  = x.Quantity,
                            Upc       = x.Upc,
                            Price     = x.Price,
                            CostPrice = x.CostPrice,
                            Weight    = x.Weight,
                            ImageFile = x.ImageUrl
                        }).ToList(),
                        Main_Images = product.Images.Select(y => new BigCommerceImage
                        {
                            UrlStandard = y.UrlStandard,
                            IsThumbnail = y.IsThumbnail
                        }).ToList()
                    });
                }

                if (productsWithinPage.Response.Data.Count < RequestMaxLimit)
                {
                    break;
                }
            }

            if (includeExtendedInfo)
            {
                base.FillWeightUnit(products, marker);
                base.FillBrands(products, marker);
            }

            return(products);
        }
示例#13
0
        public void GivenResponseWithWebException_WhenIsResponseTooLargeCalled_ThenPositiveResultExpected()
        {
            bool isResponseTooLarge = PageAdjuster.IsResponseTooLargeToRead(new Exception(string.Empty, new WebException(string.Empty, WebExceptionStatus.ConnectionClosed)));

            isResponseTooLarge.Should().Be(true);
        }
示例#14
0
        public void GivenResponseWithIOException_WhenIsResponseTooLargeCalled_ThenPositiveResultExpected()
        {
            bool isResponseTooLarge = PageAdjuster.IsResponseTooLargeToRead(new Exception(string.Empty, new IOException()));

            isResponseTooLarge.Should().Be(true);
        }
示例#15
0
        public void GivenResponseWithCommonException_WhenIsResponseTooLargeCalled_ThenNegativeResultExpected()
        {
            bool isResponseTooLarge = PageAdjuster.IsResponseTooLargeToRead(new Exception(null, new Exception()));

            isResponseTooLarge.Should().Be(false);
        }