public async void CheckConcurrentModificationException()
        {
            await WithUpdateableCategory(client, async category =>
            {
                var key    = TestingUtility.RandomString();
                var action = new SetKeyUpdateAction {
                    Key = key
                };

                var updatedCategory = await client
                                      .ExecuteAsync(category.UpdateById(actions => actions.AddUpdate(action)));

                Assert.Equal(key, updatedCategory.Key);

                // updatedCategory now has a new version
                // then if we try to update the original category it will throw ConCurrentModification Exception

                var exception = await Assert.ThrowsAsync <ConcurrentModificationException>(() =>
                                                                                           client.ExecuteAsync(
                                                                                               category.UpdateById(actions => actions.AddUpdate(action))));

                Assert.NotNull(exception);
                Assert.Single(exception.ErrorResponse.Errors);
                Assert.IsType <ConcurrentModificationError>(exception.ErrorResponse.Errors[0]);
                Assert.Equal(exception.GetCurrentVersion(), updatedCategory.Version);
                return(updatedCategory);
            });
        }
示例#2
0
        public async Task UpdateCustomerGroupByIdSetKey()
        {
            await WithUpdateableCustomerGroup(client, async customerGroup =>
            {
                var key    = TestingUtility.RandomString();
                var action = new SetKeyUpdateAction {
                    Key = key
                };

                var updatedCustomerGroup = await client
                                           .ExecuteAsync(customerGroup.UpdateByKey(actions => actions.AddUpdate(action)));

                Assert.Equal(key, updatedCustomerGroup.Key);
                return(updatedCustomerGroup);
            });
        }
示例#3
0
        public async Task UpdateProductDiscountSetKey()
        {
            await WithUpdateableProductDiscount(client, async productDiscount =>
            {
                var key    = TestingUtility.RandomString();
                var action = new SetKeyUpdateAction {
                    Key = key
                };

                var updatedProductDiscount = await client
                                             .ExecuteAsync(productDiscount.UpdateById(actions => actions.AddUpdate(action)));

                Assert.Equal(key, updatedProductDiscount.Key);
                return(updatedProductDiscount);
            });
        }
示例#4
0
        /// <summary>
        /// Update Category set random Key and return updated instance
        /// </summary>
        /// <param name="category"></param>
        /// <returns>Updated Category with newer version and updated random Key</returns>
        public Category UpdateCategorySetRandomKey(Category category)
        {
            IClient commerceToolsClient = this.GetService <IClient>();

            List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >();
            SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction()
            {
                Key = this.RandomString(10)
            };

            updateActions.Add(setKeyAction);
            Category updatedCategory = commerceToolsClient
                                       .ExecuteAsync(new UpdateByIdCommand <Category>(new Guid(category.Id), category.Version, updateActions))
                                       .Result;

            return(updatedCategory);
        }
示例#5
0
        public async Task UpdateExtensionSetKey()
        {
            var newKey = $"UpdateExtensionSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableExtension(client, async extension =>
            {
                var updateActions = new List <UpdateAction <Extension> >();
                var setKeyAction  = new SetKeyUpdateAction {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedExtension = await client
                                       .ExecuteAsync(new UpdateByIdCommand <Extension>(extension, updateActions));

                Assert.Equal(newKey, updatedExtension.Key);
                return(updatedExtension);
            });
        }
        public async Task UpdateProductTypeSetKey()
        {
            var newKey = $"UpdateProductTypeSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableProductType(client, async productType =>
            {
                var updateActions = new List <UpdateAction <ProductType> >();
                var setKeyAction  = new SetKeyUpdateAction {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedProductType = await client
                                         .ExecuteAsync(new UpdateByIdCommand <ProductType>(productType, updateActions));

                Assert.Equal(newKey, updatedProductType.Key);
                return(updatedProductType);
            });
        }
示例#7
0
        public async Task UpdateTaxCategorySetKey()
        {
            var newKey = $"UpdateTaxCategorySetKey-{TestingUtility.RandomString()}";

            await WithUpdateableTaxCategory(client, async taxCategory =>
            {
                var updateActions = new List <UpdateAction <TaxCategory> >();
                var setKeyAction  = new SetKeyUpdateAction {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedTaxCategory = await client
                                         .ExecuteAsync(new UpdateByIdCommand <TaxCategory>(taxCategory, updateActions));

                Assert.Equal(newKey, updatedTaxCategory.Key);
                return(updatedTaxCategory);
            });
        }
        public void UpdateCustomerGroupByIdSetKey()
        {
            IClient       commerceToolsClient = this.customerGroupFixture.GetService <IClient>();
            CustomerGroup customerGroup       = this.customerGroupFixture.CreateCustomerGroup();
            string        key = TestingUtility.RandomString(10);
            List <UpdateAction <CustomerGroup> > updateActions = new List <UpdateAction <CustomerGroup> >();
            SetKeyUpdateAction setKeyUpdateAction = new SetKeyUpdateAction()
            {
                Key = key
            };

            updateActions.Add(setKeyUpdateAction);
            CustomerGroup retrievedCustomerGroup = commerceToolsClient
                                                   .ExecuteAsync(new UpdateByIdCommand <CustomerGroup>(new Guid(customerGroup.Id), customerGroup.Version,
                                                                                                       updateActions)).Result;

            this.customerGroupFixture.CustomerGroupsToDelete.Add(retrievedCustomerGroup);
            Assert.Equal(key, retrievedCustomerGroup.Key);
        }
        public async Task UpdateZoneSetKey()
        {
            var newKey = $"UpdateZoneSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableZone(client, async zone =>
            {
                var updateActions = new List <UpdateAction <Zone> >();
                var setKeyAction  = new SetKeyUpdateAction()
                {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedZone = await client
                                  .ExecuteAsync(new UpdateByIdCommand <Zone>(zone, updateActions));

                Assert.Equal(newKey, updatedZone.Key);
                return(updatedZone);
            });
        }
示例#10
0
        public void UpdateCategoryByIdSetKey()
        {
            IClient  commerceToolsClient = this.categoryFixture.GetService <IClient>();
            Category category            = this.categoryFixture.CreateCategory();
            string   newKey = this.categoryFixture.RandomString(10);
            List <UpdateAction <Category> > updateActions = new List <UpdateAction <Category> >();
            SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction()
            {
                Key = newKey
            };

            updateActions.Add(setKeyAction);
            Category retrievedCategory = commerceToolsClient.ExecuteAsync(new UpdateByIdCommand <Category>(new Guid(category.Id), category.Version, updateActions)).Result;

            // The retrieved category has to be deleted and not the created category.
            // The retrieved category will have version 2 and the created category will have version 1.
            // Only the latest version can be deleted.
            this.categoryFixture.CategoriesToDelete.Add(retrievedCategory);
            Assert.Equal(newKey, retrievedCategory.Key);
        }
        public async Task UpdateShippingMethodSetKey()
        {
            var newKey = $"UpdateShippingMethodSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableShippingMethod(client, async shippingMethod =>
            {
                var updateActions = new List <UpdateAction <ShippingMethod> >();
                var action        = new SetKeyUpdateAction()
                {
                    Key = newKey
                };
                updateActions.Add(action);

                var updatedShippingMethod = await client
                                            .ExecuteAsync(new UpdateByIdCommand <ShippingMethod>(shippingMethod, updateActions));

                Assert.Equal(newKey, updatedShippingMethod.Key);
                return(updatedShippingMethod);
            });
        }
        public async Task UpdateShoppingListChangeKey()
        {
            var newKey = $"UpdateShoppingListSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableShoppingList(client, async shoppingList =>
            {
                var updateActions = new List <UpdateAction <ShoppingList> >();
                var action        = new SetKeyUpdateAction
                {
                    Key = newKey
                };
                updateActions.Add(action);

                var updatedShoppingList = await client
                                          .ExecuteAsync(new UpdateByIdCommand <ShoppingList>(shoppingList, updateActions));

                Assert.Equal(newKey, updatedShoppingList.Key);
                return(updatedShoppingList);
            });
        }
示例#13
0
        public async Task UpdateReviewSetKey()
        {
            var newKey = $"UpdateReviewSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableReview(client, async review =>
            {
                var updateActions = new List <UpdateAction <Review> >();
                SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction()
                {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedReview = await client
                                    .ExecuteAsync(new UpdateByIdCommand <Review>(review, updateActions));

                Assert.Equal(newKey, updatedReview.Key);
                return(updatedReview);
            });
        }
示例#14
0
        public async Task UpdateCartDiscountSetKey()
        {
            var newKey = $"UpdateCartDiscountSetKey-{TestingUtility.RandomString()}";

            await WithUpdateableCartDiscount(client, async cartDiscount =>
            {
                var updateActions = new List <UpdateAction <CartDiscount> >();
                var setKeyAction  = new SetKeyUpdateAction()
                {
                    Key = newKey
                };
                updateActions.Add(setKeyAction);

                var updatedCartDiscount = await client
                                          .ExecuteAsync(new UpdateByIdCommand <CartDiscount>(cartDiscount, updateActions));

                Assert.NotEqual(cartDiscount.Version, updatedCartDiscount.Version);
                Assert.Equal(newKey, updatedCartDiscount.Key);
                return(updatedCartDiscount);
            });
        }
        public void UpdatePaymentByIdSetKey()
        {
            IClient commerceToolsClient = this.paymentsFixture.GetService <IClient>();
            Payment payment             = this.paymentsFixture.CreatePayment();
            string  newKey = TestingUtility.RandomString(10);

            var updateActions = new List <UpdateAction <Payment> >();
            SetKeyUpdateAction setKeyAction = new SetKeyUpdateAction()
            {
                Key = newKey
            };

            updateActions.Add(setKeyAction);

            Payment retrievedPayment = commerceToolsClient
                                       .ExecuteAsync(new UpdateByIdCommand <Payment>(payment.Id, payment.Version, updateActions))
                                       .Result;

            this.paymentsFixture.PaymentsToDelete.Add(retrievedPayment);
            Assert.Equal(newKey, retrievedPayment.Key);
        }
示例#16
0
        public void UpdateProductByIdSetKey()
        {
            IClient commerceToolsClient = this.productFixture.GetService <IClient>();
            Product product             = this.productFixture.CreateProduct();
            string  newKey = this.productFixture.RandomString(10);
            List <UpdateAction <Product> > updateActions = new List <UpdateAction <Product> >();
            SetKeyUpdateAction             setKeyAction  = new SetKeyUpdateAction()
            {
                Key = newKey
            };

            updateActions.Add(setKeyAction);
            Product retrievedProduct = commerceToolsClient
                                       .ExecuteAsync(new UpdateByIdCommand <Product>(new Guid(product.Id), product.Version, updateActions))
                                       .Result;

            // The retrieved product has to be deleted and not the created product.
            // The retrieved product will have version 2 and the created product will have version 1.
            // Only the latest version can be deleted.
            this.productFixture.ProductsToDelete.Add(retrievedProduct);
            Assert.Equal(newKey, retrievedProduct.Key);
        }
示例#17
0
        public async Task UpdateCategoryByIdSetKeyAndExpandParent()
        {
            await WithCategory(client, async parentCategory =>
            {
                await WithUpdateableCategory(client,
                                             categoryDraft => DefaultCategoryDraftWithParent(categoryDraft, parentCategory)
                                             , async category =>
                {
                    var key    = TestingUtility.RandomString();
                    var action = new SetKeyUpdateAction {
                        Key = key
                    };

                    var updatedCategory = await client
                                          .ExecuteAsync(category.UpdateById(actions => actions.AddUpdate(action))
                                                        .Expand(c => c.Parent));

                    Assert.Equal(key, updatedCategory.Key);
                    Assert.NotNull(updatedCategory.Parent.Obj);
                    return(updatedCategory);
                });
            });
        }