public async Task UpdateShoppingListAddLineItem()
        {
            await WithProduct(client, async product =>
            {
                await WithUpdateableShoppingList(client, async shoppingList =>
                {
                    var variantId     = product.MasterData.Staged.MasterVariant.Id;
                    var quantity      = 2;
                    var updateActions = new List <UpdateAction <ShoppingList> >();
                    var action        = new AddLineItemUpdateAction
                    {
                        ProductId = product.Id,
                        VariantId = variantId,
                        Quantity  = quantity
                    };
                    updateActions.Add(action);

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

                    Assert.Single(updatedShoppingList.LineItems);
                    var addedLineItem = updatedShoppingList.LineItems[0];
                    Assert.Equal(product.Id, addedLineItem.ProductId);
                    Assert.Equal(variantId, addedLineItem.VariantId);
                    Assert.Equal(quantity, addedLineItem.Quantity);
                    return(updatedShoppingList);
                });
            });
        }
Ejemplo n.º 2
0
        public async void ApplyOrderEditAddLineItem()
        {
            string addedItemSku      = "";
            var    addedItemQuantity = 5;

            await WithUpdateableSimpleOrder(client, async order =>
            {
                Assert.Single(order.LineItems);
                var taxCategoryRef = await GetProductTaxCategory(client, order.LineItems[0].ProductId);

                await WithProduct(client,
                                  draft =>
                {
                    var productDraft         = DefaultProductDraft(draft);
                    productDraft.TaxCategory = taxCategoryRef;
                    return(productDraft);
                },
                                  async product =>
                {
                    Assert.NotNull(product);
                    addedItemSku = product.MasterData.Staged.MasterVariant.Sku;
                    //create orderEdit with stagedAction AddLineItemStagedAction
                    await WithUpdateableOrderEdit(client, draft =>
                    {
                        var orderEditDraft = DefaultOrderEditDraft(draft, order);
                        //Add a new lineItem
                        var action = new AddLineItemUpdateAction
                        {
                            Sku      = addedItemSku,
                            Quantity = addedItemQuantity
                        };
                        orderEditDraft.StagedActions.Add(action);
                        return(orderEditDraft);
                    },
                                                  async orderEdit =>
                    {
                        var retrievedOrderEdit = await client
                                                 .ExecuteAsync(
                            orderEdit.ToIdResourceIdentifier().GetById().Expand(oe => oe.Resource));

                        Assert.NotNull(retrievedOrderEdit);
                        Assert.NotNull(retrievedOrderEdit.Resource.Obj);

                        //Apply OrderEdit
                        var applyOrderEditCommand = new ApplyOrderEditCommand(retrievedOrderEdit,
                                                                              retrievedOrderEdit.Resource.Obj.Version);

                        var appliedOrderEdit = await client.ExecuteAsync(applyOrderEditCommand);

                        Assert.NotNull(appliedOrderEdit.Result);
                        Assert.IsType <OrderEditApplied>(appliedOrderEdit.Result);
                        return(appliedOrderEdit);
                    });
                });
                //then retrieved updated order
                var updatedOrder = await client
                                   .ExecuteAsync(order.ToIdResourceIdentifier().GetById());

                //assert that order now with 2 lineItems
                Assert.Equal(2, updatedOrder.LineItems.Count);
                Assert.Contains(updatedOrder.LineItems,
                                item => item.Variant.Sku == addedItemSku &&
                                item.Quantity == addedItemQuantity);
                return(updatedOrder);
            });
        }