Exemple #1
0
        public async Task Run_UpdateIsGiftBoxToFalse_ShouldReturnCartLineWithIsGiftBoxEqualFalse()
        {
            var inputCart  = new Cart();
            var cartLineId = Guid.NewGuid().ToString();
            var cartLine   = new CartLineComponent()
            {
                Id       = cartLineId,
                ItemId   = TestSellableItemId,
                Quantity = 1
            };

            cartLine.SetComponent(new CartLineGiftBoxComponent()
            {
                IsGiftBox = true
            });
            inputCart.Lines.Add(cartLine);
            var cartLineGiftBoxArgument = new CartLineGiftBoxArgument(inputCart, cartLineId, false);

            var outputCart = await _pipelineBlock.Run(cartLineGiftBoxArgument, _pipelineContextFake);

            var cartLineGiftBoxComponent = outputCart.Lines
                                           .SingleOrDefault(l => l.Id == cartLineId)
                                           .GetComponent <CartLineGiftBoxComponent>();

            Assert.False(cartLineGiftBoxComponent.IsGiftBox);
        }
Exemple #2
0
        public async Task Run_UpdateIsGiftBoxToTrueForValidItem_ShouldReturnCartLineWithIsGiftBoxEqualTrue()
        {
            var inputCart  = new Cart();
            var cartLineId = Guid.NewGuid().ToString();
            var cartLine   = new CartLineComponent()
            {
                Id       = cartLineId,
                ItemId   = TestSellableItemId,
                Quantity = 1
            };

            cartLine.SetComponent(new CartLineGiftBoxComponent()
            {
                IsGiftBox = false
            });
            inputCart.Lines.Add(cartLine);
            var cartLineGiftBoxArgument      = new CartLineGiftBoxArgument(inputCart, cartLineId, true);
            var sellableItemValidForGiftWrap = new SellableItem();

            sellableItemValidForGiftWrap.AddComponent(null, new SellableItemGiftBoxComponent()
            {
                AllowGiftBox = true
            });
            _getSellableItemPipelineMock
            .Setup(p => p.Run(It.IsAny <ProductArgument>(), It.IsAny <CommercePipelineExecutionContext>()))
            .Returns(Task.FromResult(sellableItemValidForGiftWrap));

            var outputCart = await _pipelineBlock.Run(cartLineGiftBoxArgument, _pipelineContextFake);

            var cartLineGiftBoxComponent = outputCart.Lines
                                           .SingleOrDefault(l => l.Id == cartLineId)
                                           .GetComponent <CartLineGiftBoxComponent>();

            Assert.True(cartLineGiftBoxComponent.IsGiftBox);
        }
Exemple #3
0
        /// <summary>
        /// Process UpdateCartLineGiftBoxCommand commerce command.
        /// </summary>
        /// <param name="commerceContext">Commerce context.</param>
        /// <param name="cartId">Cart Id.</param>
        /// <param name="cartLineId">Cart line Id.</param>
        /// <param name="isGiftBox">Cart line gift box boolean attribute.</param>
        /// <returns></returns>
        public async Task <Cart> Process(CommerceContext commerceContext, string cartId, string cartLineId, bool isGiftBox)
        {
            try
            {
                Cart cartResult = null;

                using (CommandActivity.Start(commerceContext, this))
                {
                    // find Cart entity
                    var findCartArgument = new FindEntityArgument(typeof(Cart), cartId, false);
                    var pipelineContext  = new CommercePipelineExecutionContextOptions(commerceContext);
                    cartResult = await _findEntityPipeline.Run(findCartArgument, pipelineContext) as Cart;

                    var validationErrorCode = commerceContext.GetPolicy <KnownResultCodes>().ValidationError;

                    if (cartResult == null)
                    {
                        await pipelineContext.CommerceContext.AddMessage(validationErrorCode,
                                                                         "EntityNotFound",
                                                                         new object[] { cartId },
                                                                         $"Cart {cartId} was not found.");
                    }
                    else if (!cartResult.Lines.Any(l => l.Id == cartLineId))
                    {
                        await pipelineContext.CommerceContext.AddMessage(validationErrorCode,
                                                                         "CartLineNotFound",
                                                                         new object[] { cartLineId },
                                                                         $"Cart line {cartLineId} was not found.");
                    }
                    else
                    {
                        var arg = new CartLineGiftBoxArgument(cartResult, cartLineId, isGiftBox);
                        cartResult = await _updateCartLineGiftBoxPipeline.Run(arg, pipelineContext);
                    }

                    return(cartResult);
                }
            }
            catch (Exception ex)
            {
                return(await Task.FromException <Cart>(ex));
            }
        }