Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public CartLineComponent Build()
        {
            var line = new CartLineComponent
            {
                Id            = lineId,
                Quantity      = quantity,
                ItemId        = itemId,
                UnitListPrice = new Money(price),
                Policies      =
                {
                    new PurchaseOptionMoneyPolicy
                    {
                        SellPrice = new Money(price)
                    }
                },
                Totals = new Totals
                {
                    GrandTotal = new Money(quantity * price)
                }
            };

            if (fullfilmentMethod != null)
            {
                line.SetComponent(new FulfillmentComponent
                {
                    FulfillmentMethod = fullfilmentMethod
                });
            }

            if (categorySitecoreId != null)
            {
                var categoryComponent = line.GetComponent <CategoryComponent>();
                categoryComponent.ParentCategoryList.Add(categorySitecoreId);
            }

            return(line);
        }
        public async Task Run_CartWithTwoGiftBoxItems_ShouldReturnCartWithNonZeroGitfBoxFee()
        {
            var expectedFeeAmount = new GiftBoxFeeAdjustmentPolicy().FeeAmount * 2;
            var inputCart         = new Cart();
            var cartLine1         = new CartLineComponent()
            {
                Id       = Guid.NewGuid().ToString(),
                ItemId   = "some-item-1",
                Quantity = 1
            };

            cartLine1.SetComponent(new CartLineGiftBoxComponent()
            {
                IsGiftBox = true
            });
            inputCart.Lines.Add(cartLine1);
            var cartLine2 = new CartLineComponent()
            {
                Id       = Guid.NewGuid().ToString(),
                ItemId   = "some-item-2",
                Quantity = 1
            };

            cartLine2.SetComponent(new CartLineGiftBoxComponent()
            {
                IsGiftBox = true
            });
            inputCart.Lines.Add(cartLine2);

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

            var giftBoxAdjustment = outputCart.Adjustments.SingleOrDefault(a => a.Name == Constants.Adjustments.GiftBox.Name);

            Assert.NotNull(giftBoxAdjustment);
            Assert.True(giftBoxAdjustment.Adjustment.Amount == expectedFeeAmount);
        }