Пример #1
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            CollectService.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);
            CustomCollectionService.SetExecutionPolicy(policy);

            // Create a custom collection to use with these tests.
            var collection = await CustomCollectionService.CreateAsync(new CustomCollection()
            {
                Title     = "Things",
                Published = false,
                BodyHtml  = "<h1>Hello from ShopifySharp</h1>",
                Image     = new CustomCollectionImage()
                {
                    Attachment = "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
                }
            });

            CollectionId = collection.Id.Value;

            // Create a collection to use with get, list, count, etc. tests.
            await Create();
        }
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);
            VariantService.SetExecutionPolicy(policy);

            // Create a product to use with these tests.
            var product = await CreateProductAndVariantAsync();

            ProductId = product.Id.Value;

            // Get the product's variant and use its inventory item id for tests
            var variant = product.Variants.First();

            VariantId       = variant.Id.Value;
            InventoryItemId = variant.InventoryItemId.Value;

            // Set an SKU and inventory management policy on the variant. This is required for fulfillment.
            variant.SKU = "TestSKU";
            variant.InventoryManagement = "Shopify";
            // InventoryQuantity must be null as it is read-only
            variant.InventoryQuantity = null;

            await VariantService.UpdateAsync(VariantId, variant);
        }
Пример #3
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            CustomCollectionService.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);

            // Create a custom collection to use with these tests.
            var collection = await CustomCollectionService.CreateAsync(new CustomCollection()
            {
                Title     = "Things",
                Published = false,
                BodyHtml  = "<h1>Hello from ShopifySharp</h1>",
                Image     = new CustomCollectionImage()
                {
                    Src = "http://placehold.it/250x250"
                }
            });

            CollectionId = collection.Id.Value;

            // Create a collection to use with get, list, count, etc. tests.
            await Create();
        }
Пример #4
0
        public Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy(false);

            Service.SetExecutionPolicy(policy);
            OrderService.SetExecutionPolicy(policy);

            return(Task.CompletedTask);
        }
Пример #5
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            DiscountCodeService.SetExecutionPolicy(policy);
            PriceRuleService.SetExecutionPolicy(policy);

            // Create one for count, list, get, etc. orders.
            await Create(Code);
        }
Пример #6
0
        public async Task ForegroundRequestsMustRunBeforeBackgroundRequests()
        {
            var context = RequestContext.Background;
            var policy  = new LeakyBucketExecutionPolicy(getRequestContext: () => context);
            var filter  = new Filters.OrderListFilter
            {
                Status = "any",
                Limit  = 1,
                Fields = "id"
            };

            DateTime?backgroundCompletedAt = null;
            DateTime?foregroundCompletedAt = null;

            async Task ListInBackground()
            {
                var tasks = Enumerable.Range(0, 50)
                            .Select(_ => Fixture.OrderService.ListAsync(filter));

                await Task.WhenAll(tasks);

                backgroundCompletedAt = DateTime.UtcNow;
            };

            async Task ListInForeground()
            {
                var tasks = Enumerable.Range(0, 10)
                            .Select(_ => Fixture.OrderService.ListAsync(filter));

                await Task.WhenAll(tasks);

                foregroundCompletedAt = DateTime.UtcNow;
            }

            Fixture.OrderService.SetExecutionPolicy(policy);

            // Kick off background requests, which will trigger a throttle
            var bgTask = ListInBackground();

            // Change the context
            context = RequestContext.Foreground;

            // Now list in foreground, which should finish before the background tasks
            var fgTask = ListInForeground();

            await Task.WhenAll(bgTask, fgTask);

            Assert.NotNull(backgroundCompletedAt);
            Assert.NotNull(foregroundCompletedAt);

            Console.WriteLine("Foreground completed at {0}", foregroundCompletedAt);
            Console.WriteLine("Background completed at {0}", backgroundCompletedAt);

            Assert.True(foregroundCompletedAt < backgroundCompletedAt);
        }
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);
            CollectService.SetExecutionPolicy(policy);

            // Create one collection for use with count, list, get, etc. tests.
            await Create();
        }
Пример #8
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            ThemeService.SetExecutionPolicy(policy);

            var themes = await ThemeService.ListAsync();

            ThemeId = themes.First().Id.Value;
        }
Пример #9
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy(false);

            Service.SetExecutionPolicy(policy);
            OrderService.SetExecutionPolicy(policy);

            // Create one collection for use with count, list, get, etc. tests.
            var order = await CreateOrder();

            await Create(order.Id.Value, currency : order.Currency);
        }
Пример #10
0
        public async Task InitializeAsync()
        {
            // Fulfillment API has a stricter rate limit when on a non-paid store.
            var policy = new LeakyBucketExecutionPolicy(false);

            Service.SetExecutionPolicy(policy);
            OrderService.SetExecutionPolicy(policy);

            // Create an order and fulfillment for count, list, get, etc. tests.
            var order = await CreateOrder();

            var fulfillment = await Create(order.Id.Value);
        }
Пример #11
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            BlogService.SetExecutionPolicy(policy);

            var blogs = await BlogService.ListAsync();

            BlogId = blogs.Items.First().Id;

            // Create at least one article for list, count, etc commands.
            await Create();
        }
Пример #12
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            CustomerService.SetExecutionPolicy(policy);

            var customers = await CustomerService.ListAsync();

            CustomerId = customers.Items.First().Id;

            // Create at least one Address for list, count, etc commands.
            //await Create();
        }
Пример #13
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy(false);

            OrderService.SetExecutionPolicy(policy);
            Service.SetExecutionPolicy(policy);

            if (!OrderId.HasValue)
            {
                return;
            }

            // Retrieve an order for count, list, get, etc. orders.
            await Retrieve(OrderId.Value);
        }
Пример #14
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy(false);

            Service.SetExecutionPolicy(policy);
            OrderService.SetExecutionPolicy(policy);

            OrderId = (await OrderService.ListAsync(new OrderListFilter()
            {
                Limit = 1
            })).Items.First().Id.Value;

            // Create a risk for count, list, get, etc. tests.
            await Create(OrderId);
        }
Пример #15
0
        public async Task Allows_Setting_Global_HttpClientFactory()
        {
            var factory = new FakeHttpClientFactory();

            ShopifyService.SetGlobalHttpClientFactory(factory);

            var shopService  = new ShopService(Utils.MyShopifyUrl, Utils.AccessToken);
            var orderService = new OrderService(Utils.MyShopifyUrl, Utils.AccessToken);
            var policy       = new LeakyBucketExecutionPolicy();
            var orderFilter  = new OrderListFilter
            {
                Limit = 1
            };

            shopService.SetExecutionPolicy(policy);
            orderService.SetExecutionPolicy(policy);

            var ex1 = await Assert.ThrowsAsync <Exception>(() => shopService.GetAsync());

            var ex2 = await Assert.ThrowsAsync <Exception>(() => orderService.ListAsync(orderFilter));

            Assert.Equal("This is an exception thrown by the FakeHttpClient", ex1.Message);
            Assert.Equal("This is an exception thrown by the FakeHttpClient", ex2.Message);

            // Removing the factory should only remove it for future instances
            ShopifyService.SetGlobalHttpClientFactory(null);

            ex1 = await Assert.ThrowsAsync <Exception>(() => shopService.GetAsync());

            ex2 = await Assert.ThrowsAsync <Exception>(() => orderService.ListAsync(orderFilter));

            Assert.Equal("This is an exception thrown by the FakeHttpClient", ex1.Message);
            Assert.Equal("This is an exception thrown by the FakeHttpClient", ex2.Message);

            // Instantiating the services again should now use the default HttpClientFactory
            shopService  = new ShopService(Utils.MyShopifyUrl, Utils.AccessToken);
            orderService = new OrderService(Utils.MyShopifyUrl, Utils.AccessToken);

            shopService.SetExecutionPolicy(policy);
            orderService.SetExecutionPolicy(policy);

            var shop = await shopService.GetAsync();

            var orders = await orderService.ListAsync(orderFilter);

            Assert.NotNull(shop);
            Assert.NotNull(orders);
        }
Пример #16
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);

            // Get a product to use as the parent for all images.
            ProductId = (await ProductService.ListAsync(new ProductListFilter()
            {
                Limit = 1
            })).Items.First().Id.Value;

            // Create one for count, list, get, etc. orders.
            await Create();
        }
Пример #17
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            VariantService.SetExecutionPolicy(policy);

            // Get a product id to use with these tests.
            ProductId = (await new ProductService(Utils.MyShopifyUrl, Utils.AccessToken).ListAsync(new ProductListFilter()
            {
                Limit = 1
            })).Items.First().Id.Value;

            // Create one for use with count, list, get, etc. tests.
            await Create();
        }
Пример #18
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            GiftCardService.SetExecutionPolicy(policy);

            // Get a gift card id to use with these tests.
            GiftCardId = (await GiftCardService.ListAsync(new Filters.GiftCardListFilter()
            {
                Limit = 1
            })).Items.First().Id.Value;

            // Create one for use with count, list, get, etc. tests.
            await Create();
        }
Пример #19
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
            ProductService.SetExecutionPolicy(policy);

            // Get a product to add metafields to.
            var products = await ProductService.ListAsync();

            ResourceId      = products.Items.First().Id.Value;
            ChildResourceId = products.Items.First().Variants.First().Id.Value;

            // Create a metafield for use in count, list, get, etc. tests.
            await Create();
            await Create(ResourceId, ResourceType);
            await Create(ChildResourceId, ChildResourceType, ResourceId, ResourceType);
        }
Пример #20
0
        public async Task InitializeAsync()
        {
            var policy = new LeakyBucketExecutionPolicy();

            Service.SetExecutionPolicy(policy);
        }