示例#1
0
        public async Task UpdateCartDiscountChangeTarget()
        {
            var newCartDiscountTarget = new LineItemsCartDiscountTarget()
            {
                Predicate = " 1 <> 1"
            };

            await WithUpdateableCartDiscount(client, async cartDiscount =>
            {
                var updateActions      = new List <UpdateAction <CartDiscount> >();
                var changeTargetAction = new ChangeTargetUpdateAction
                {
                    Target = newCartDiscountTarget
                };
                updateActions.Add(changeTargetAction);

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

                var newTarget = updatedCartDiscount.Target as LineItemsCartDiscountTarget;

                Assert.NotNull(newTarget);
                Assert.Equal(newCartDiscountTarget.Predicate, newTarget.Predicate);
                return(updatedCartDiscount);
            });
        }
示例#2
0
        public void UpdateCartDiscountByIdChangeTarget()
        {
            IClient      commerceToolsClient = this.cartDiscountFixture.GetService <IClient>();
            CartDiscount cartDiscount        = this.cartDiscountFixture.CreateCartDiscount();

            //creating new cart discount value
            var newCartDiscountTarget = new LineItemsCartDiscountTarget()
            {
                Predicate = " 1 <> 1"
            };

            List <UpdateAction <CartDiscount> > updateActions            = new List <UpdateAction <CartDiscount> >();
            ChangeTargetUpdateAction            changeTargetUpdateAction = new ChangeTargetUpdateAction()
            {
                Target = newCartDiscountTarget
            };

            updateActions.Add(changeTargetUpdateAction);

            CartDiscount retrievedCartDiscount = commerceToolsClient
                                                 .ExecuteAsync(new UpdateByIdCommand <CartDiscount>(new Guid(cartDiscount.Id),
                                                                                                    cartDiscount.Version, updateActions))
                                                 .Result;

            var cartDiscountTarget = (LineItemsCartDiscountTarget)cartDiscount.Target;

            this.cartDiscountFixture.CartDiscountsToDelete.Add(retrievedCartDiscount);

            Assert.NotEqual(cartDiscount.Version, retrievedCartDiscount.Version);
            Assert.NotEqual(cartDiscountTarget.Predicate, newCartDiscountTarget.Predicate);
        }