Exemplo n.º 1
0
        public async Task WHEN_param_ok_SHOULD_invoke_LineItemService_GetInvalidLineItems()
        {
            //Arrange
            var p = new RemoveInvalidLineItemsParam
            {
                CartName          = GetRandom.String(7),
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                CustomerId        = GetRandom.Guid(),
                Scope             = GetRandom.String(7),
                ExecuteWorkflow   = GetRandom.Boolean(),
                WorkflowToExecute = GetRandom.String(7),
                BaseUrl           = GetRandom.WwwUrl()
            };

            MockLineItemService(GetRandom.Boolean());

            Container.GetMock <ICartRepository>().Setup(repository => repository.RemoveLineItemsAsync(It.IsAny <RemoveLineItemsParam>())).ReturnsAsync(new ProcessedCart()).Verifiable();

            var sut = Container.CreateInstance <CartService>();

            //Act
            await sut.RemoveInvalidLineItemsAsync(p);

            //Assert
            Container.Verify <ILineItemService>(m => m.GetInvalidLineItems(It.IsNotNull <ProcessedCart>()));
        }
Exemplo n.º 2
0
        public virtual async Task <CartViewModel> RemoveInvalidLineItemsAsync(RemoveInvalidLineItemsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }

            var cart = await CartRepository.GetCartAsync(new GetCartParam
            {
                CartName          = param.CartName,
                CultureInfo       = param.CultureInfo,
                CustomerId        = param.CustomerId,
                ExecuteWorkflow   = param.ExecuteWorkflow,
                Scope             = param.Scope,
                WorkflowToExecute = param.WorkflowToExecute
            }).ConfigureAwait(false);

            var invalidLineItems = LineItemService.GetInvalidLineItems(cart);

            if (invalidLineItems.Any())
            {
                var p = new RemoveLineItemsParam
                {
                    CartName    = param.CartName,
                    CultureInfo = param.CultureInfo,
                    CustomerId  = param.CustomerId,
                    Scope       = param.Scope,
                    LineItems   = invalidLineItems.Select(li => new RemoveLineItemsParam.LineItemDescriptor
                    {
                        Id        = li.Id,
                        ProductId = li.ProductId,
                        VariantId = li.VariantId
                    }).ToList()
                };

                cart = await CartRepository.RemoveLineItemsAsync(p).ConfigureAwait(false);
            }

            var vmParam = new CreateCartViewModelParam
            {
                Cart        = cart,
                CultureInfo = param.CultureInfo,
                BaseUrl     = param.BaseUrl
            };

            var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false);

            return(viewModel);
        }
Exemplo n.º 3
0
        public virtual async Task <IHttpActionResult> CleanCartAsync()
        {
            var param = new RemoveInvalidLineItemsParam
            {
                CartName    = CartConfiguration.ShoppingCartName,
                CultureInfo = ComposerContext.CultureInfo,
                CustomerId  = ComposerContext.CustomerId,
                Scope       = ComposerContext.Scope,
                BaseUrl     = RequestUtils.GetBaseUrl(Request).ToString()
            };

            var cartViewModel = await CartService.RemoveInvalidLineItemsAsync(param);

            return(Ok(cartViewModel));
        }
Exemplo n.º 4
0
        public virtual async Task <CartViewModel> RemoveInvalidLineItemsAsync(RemoveInvalidLineItemsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var cart = await ProcessInvalidLineItemsRemovalAsync(param).ConfigureAwait(false);

            var vmParam = new CreateCartViewModelParam
            {
                Cart        = cart,
                CultureInfo = param.CultureInfo,
                BaseUrl     = param.BaseUrl
            };

            var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false);

            return(viewModel);
        }
Exemplo n.º 5
0
        public virtual async Task <ProcessedCart> ProcessInvalidLineItemsRemovalAsync(RemoveInvalidLineItemsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            var cart = await CartRepository.GetCartAsync(new GetCartParam
            {
                CartName          = param.CartName,
                CartType          = param.CartType,
                CultureInfo       = param.CultureInfo,
                CustomerId        = param.CustomerId,
                ExecuteWorkflow   = param.ExecuteWorkflow,
                Scope             = param.Scope,
                WorkflowToExecute = param.WorkflowToExecute
            }).ConfigureAwait(false);

            var invalidLineItems = LineItemService.GetInvalidLineItems(cart);

            if (invalidLineItems.Any())
            {
                var p = new RemoveLineItemsParam
                {
                    CartName    = param.CartName,
                    CartType    = param.CartType,
                    CultureInfo = param.CultureInfo,
                    CustomerId  = param.CustomerId,
                    Scope       = param.Scope,
                    LineItems   = invalidLineItems.Select(li => new RemoveLineItemsParam.LineItemDescriptor
                    {
                        Id        = li.Id,
                        ProductId = li.ProductId,
                        VariantId = li.VariantId
                    }).ToList()
                };

                cart = await CartRepository.RemoveLineItemsAsync(p).ConfigureAwait(false);
            }

            return(cart);
        }