protected NewCartItem BuildNewCartItem(string productId, int quantity, decimal productPrice) { var catalogProductId = _fixture.Create <string>(); var catalogProduct = new CatalogProduct { Id = catalogProductId }; var cartProduct = new CartProduct(catalogProduct); cartProduct.ApplyPrices(new List <Price>() { new Price { ProductId = catalogProductId, PricelistId = _fixture.Create <string>(), List = _fixture.Create <decimal>(), MinQuantity = _fixture.Create <int>(), } }, GetCurrency()); var newCartItem = new NewCartItem(productId, quantity) { Price = productPrice, CartProduct = cartProduct }; return(newCartItem); }
public async Task <IEnumerable <CartProduct> > GetCartProductsByIdsAsync(CartAggregate cartAggr, string[] ids) { if (cartAggr == null) { throw new ArgumentNullException(nameof(cartAggr)); } if (ids == null) { throw new ArgumentNullException(nameof(ids)); } var result = new List <CartProduct>(); var products = await _productService.GetByIdsAsync(ids, (ItemResponseGroup.ItemAssets | ItemResponseGroup.ItemInfo | ItemResponseGroup.Outlines | ItemResponseGroup.Seo).ToString()); if (!products.IsNullOrEmpty()) { var loadInventoriesTask = _inventorySearchService.SearchInventoriesAsync(new InventorySearchCriteria { ProductIds = ids, //Do not use int.MaxValue use only 10 items per requested product //TODO: Replace to pagination load Take = Math.Min(ids.Length * 10, 500) }); var pricesEvalContext = _mapper.Map <PriceEvaluationContext>(cartAggr); pricesEvalContext.ProductIds = ids; var evalPricesTask = _pricingService.EvaluateProductPricesAsync(pricesEvalContext); await Task.WhenAll(loadInventoriesTask, evalPricesTask); foreach (var product in products) { var cartProduct = new CartProduct(product); //Apply inventories cartProduct.ApplyInventories(loadInventoriesTask.Result.Results, cartAggr.Store); //Apply prices cartProduct.ApplyPrices(evalPricesTask.Result, cartAggr.Currency); result.Add(cartProduct); } } return(result); }
public XPurchaseMoqHelper() { _fixture.Register <PaymentMethod>(() => new StubPaymentMethod(_fixture.Create <string>())); _fixture.Register(() => _fixture .Build <ShoppingCart>() .With(x => x.Currency, CURRENCY_CODE) .With(x => x.LanguageCode, CULTURE_NAME) .With(x => x.Name, CART_NAME) .Without(x => x.Items) .Create()); _fixture.Register(() => { var catalogProduct = _fixture.Create <CatalogProduct>(); catalogProduct.TrackInventory = true; var cartProduct = new CartProduct(catalogProduct); cartProduct.ApplyPrices(new List <Price>() { new Price { ProductId = catalogProduct.Id, PricelistId = _fixture.Create <string>(), List = ItemCost, MinQuantity = 1, } }, GetCurrency()); var store = GetStore(); cartProduct.ApplyInventories(new List <InventoryInfo>() { new InventoryInfo { ProductId = catalogProduct.Id, FulfillmentCenterId = store.MainFulfillmentCenterId, InStockQuantity = InStockQuantity, ReservedQuantity = 0, } }, store); return(cartProduct); }); _fixture.Register(() => new CatalogProduct { Id = _fixture.Create <string>(), IsActive = true, IsBuyable = true, }); _fixture.Register(() => _fixture.Build <LineItem>() .Without(x => x.DynamicProperties) .With(x => x.IsReadOnly, false) .With(x => x.Quantity, InStockQuantity) .With(x => x.SalePrice, ItemCost) .With(x => x.ListPrice, ItemCost) .Create()); _fixture.Register <Price>(() => null); _cartProductServiceMock = new Mock <ICartProductService>(); _currencyServiceMock = new Mock <ICurrencyService>(); _currencyServiceMock .Setup(x => x.GetAllCurrenciesAsync()) .ReturnsAsync(_fixture.CreateMany <Currency>(1).ToList()); _marketingPromoEvaluatorMock = new Mock <IMarketingPromoEvaluator>(); _marketingPromoEvaluatorMock .Setup(x => x.EvaluatePromotionAsync(It.IsAny <IEvaluationContext>())) .ReturnsAsync(new StubPromotionResult()); _paymentMethodsSearchServiceMock = new Mock <IPaymentMethodsSearchService>(); _shippingMethodsSearchServiceMock = new Mock <IShippingMethodsSearchService>(); _shoppingCartTotalsCalculatorMock = new Mock <IShoppingCartTotalsCalculator>(); _storeServiceMock = new Mock <IStoreService>(); _storeServiceMock .Setup(x => x.GetByIdAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(_fixture.Create <Store>()); _taxProviderSearchServiceMock = new Mock <ITaxProviderSearchService>(); _mapperMock = new Mock <IMapper>(); }