public void ShouldReturnOkWhenSufficientStock() { var userId = "userId"; var productId = 1; var identifier = new ProductIdentifier(productId, null); var stockItem = new StockItem() { Id = productId, Stock = 1 }; var basketItem = new BasketItem() { ProductId = productId, ItemCount = 0 }; _stockRepository .GetStockItem(productId) .Returns(stockItem); _basketRepository .GetBasketItem(userId, productId) .Returns(basketItem); _command .CanAddItemToBasketCheck(userId, identifier) .ShouldBe(BasketOperationStatus.Ok); }
public void ShouldAddItemToBasketAndReturnBasket() { var userId = "userId"; var productId = 1; var identifier = new ProductIdentifier(productId, null); var stockItem = new StockItem() { Id = productId }; var basket = new List <BasketItem>(); _stockRepository .GetStockItem(productId) .Returns(stockItem); _basketRepository .GetBasket(userId) .Returns(basket); _command .AddItemToBasket(userId, identifier) .ShouldBe(basket); _basketRepository .Received() .AddItemToUserBasket(userId, productId); }
public virtual bool HasAccess(long storeId, string productIdentifier) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IPublishedContent content = UmbracoHelper.TypedContent(productIdentifierObj.NodeId); return(storeId == GetStoreId(content) && library.HasAccess(content.Id, content.Path)); }
public BasketOperationStatus CanRemoveItemFromBasketCheck( string userId, ProductIdentifier identifier) { if (!identifier.Valid) { return(BasketOperationStatus.InvalidIdentifier); } var stockItem = _stockRepository.GetStockItem(identifier); if (stockItem == null) { return(BasketOperationStatus.ProductNotFound); } var basketItem = _basketRepository.GetBasketItem(userId, stockItem.Id); if (basketItem.ItemCount == 0) { return(BasketOperationStatus.NotInBasket); } return(BasketOperationStatus.Ok); }
public void ShouldReturnNotInBasketWhenNotEnoughStock() { var userId = "userId"; var productId = 1; var identifier = new ProductIdentifier(productId, null); var stockItem = new StockItem() { Id = productId, Stock = 0 }; var basketItem = new BasketItem() { ProductId = productId, ItemCount = 0 }; _stockRepository .GetStockItem(productId) .Returns(stockItem); _basketRepository .GetBasketItem(userId, productId) .Returns(basketItem); _command .CanRemoveItemFromBasketCheck(userId, identifier) .ShouldBe(BasketOperationStatus.NotInBasket); }
public void ThenProductPepperIsAddedWithAnQuantityOf(string product, int count) { var orderLineCreatedEvent = ThenGetEvent <OrderLineCreated>(); orderLineCreatedEvent.ShouldNotBeNull(); orderLineCreatedEvent.ProductIdentifier.ShouldBe(ProductIdentifier.Parse(product)); orderLineCreatedEvent.Quantity.ShouldBe(count); }
public void ShouldThrowInvalidIdentifierExceptionIfTheIdentifierSuppliedIsInvalid() { var userId = "userId"; var identifier = new ProductIdentifier(null, null); Should.Throw <ApplicationException>(() => _command .AddItemToBasket(userId, identifier)); }
public override Core.OrderManagement.Orders.Events.OrderLineCreated ConvertToIntern(OrderLineCreated e) { return(new Core.OrderManagement.Orders.Events.OrderLineCreated( OrderIdentifier.Parse(e.OrderIdentifier), OrderLineIdentifier.Parse(e.OrderLineIdentifier), ProductIdentifier.Parse(e.ProductIdentifier), ProductName.Create(e.ProductName), e.Quantity)); }
public void GivenOrderHasAnItemProductWithQuantity(string product, int quantity) { AddEvent(new OrderLineCreated( _orderIdentifier, OrderLineIdentifier.Create(1), ProductIdentifier.Parse(product), ProductName.Create("Test"), quantity)); }
public virtual long?GetVatGroupId(string productIdentifier) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IPublishedContent content = UmbracoHelper.TypedContent(productIdentifierObj.NodeId); long storeId = GetStoreId(content); VariantPublishedContent variant = VariantService.GetVariant(storeId, content, productIdentifierObj.VariantId); return(GetVatGroupId(content, variant)); }
public void ShouldReturnInvalidIdentifierIfTheIdentifierSuppliedIsInvalid() { var userId = "userId"; var identifier = new ProductIdentifier(null, null); _command .CanAddItemToBasketCheck(userId, identifier) .ShouldBe(BasketOperationStatus.InvalidIdentifier); }
public virtual OriginalUnitPriceCollection GetOriginalUnitPrices(string productIdentifier) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IPublishedContent content = UmbracoHelper.TypedContent(productIdentifierObj.NodeId); long storeId = GetStoreId(content); VariantPublishedContent variant = VariantService.GetVariant(storeId, content, productIdentifierObj.VariantId); return(GetOriginalUnitPrices(content, variant)); }
/// <summary> /// Returns the value of a property on the product. Will traverse the content tree recursively to find the value. Will also use the master relation property of the product to search master products. NOTE: If you have a IPublishedContent model use that instead of the string productIdentifier, which is slightly slower. /// </summary> /// <param name="storeId">Id of the store.</param> /// <param name="productIdentifier">A unique identifier of the product. E.g. the node id from Umbraco.</param> /// <param name="propertyAlias">Alias of the property to find.</param> /// <param name="func">A function to filter the result.</param> /// <returns>The text value of the property.</returns> public static T GetPropertyValue <T>(long storeId, string productIdentifier, string propertyAlias, Func <IPublishedContent, bool> func = null) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current); IPublishedContent content = umbracoHelper.TypedContent(productIdentifierObj.NodeId); VariantPublishedContent variant = PublishedContentVariantService.Instance.GetVariant(storeId, content, productIdentifierObj.VariantId); return(DependencyContainer.Instance.Resolve <IPublishedContentProductInformationExtractor>().GetPropertyValue <T>(content, propertyAlias, variant, func)); }
public static Product Create( IAggregateContext context, ProductName productName) { return(Product.CreateWithEvent <Product, ProductCreated>( context, new ProductCreated( ProductIdentifier.New(), productName))); }
public void ShouldThrowProductNotFoundExceptionIfProductNotFound() { var userId = "userId"; var productId = 1; var identifier = new ProductIdentifier(productId, null); _stockRepository .GetStockItem(productId) .Returns((StockItem)null); Should.Throw <ApplicationException>(() => _command .AddItemToBasket(userId, identifier)); }
public OrderLineCreated( OrderIdentifier orderIdentifier, OrderLineIdentifier orderLineIdentifier, ProductIdentifier productIdentifier, ProductName productName, int quantity) { OrderIdentifier = orderIdentifier; OrderLineIdentifier = orderLineIdentifier; ProductIdentifier = productIdentifier; ProductName = productName; Quantity = quantity; }
public void ShouldReturnProductNotFoundWhenNoProductReturned() { var userId = "userId"; var productId = 1; var identifier = new ProductIdentifier(productId, null); _stockRepository .GetStockItem(productId) .Returns((StockItem)null); _command .CanRemoveItemFromBasketCheck(userId, identifier) .ShouldBe(BasketOperationStatus.ProductNotFound); }
public void PostStock(string productIdentifier, Stock stock) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IContent content = ApplicationContext.Current.Services.ContentService.GetById(productIdentifierObj.NodeId); IProductInformationExtractor <IContent, VariantPublishedContent> productInformationExtractor = ContentProductInformationExtractor.Instance; IVariantService <IContent, VariantPublishedContent> contentVariantService = ContentVariantService.Instance; long storeId = productInformationExtractor.GetStoreId(content); VariantPublishedContent variant = contentVariantService.GetVariant(storeId, content, productIdentifierObj.VariantId); stock.Sku = !string.IsNullOrEmpty(stock.Sku) ? stock.Sku : productInformationExtractor.GetSku(content, variant); ProductService.Instance.SetStock(storeId, stock.Sku, !string.IsNullOrEmpty(stock.Value) ? stock.Value.ParseToDecimal() : null); }
public HttpResponseMessage Get(string pageId, long vatGroupId) { ProductIdentifier productIdentifierObj = new ProductIdentifier(pageId); IContent content = ApplicationContext.Current.Services.ContentService.GetById(productIdentifierObj.NodeId); IProductInformationExtractor <IContent, VariantPublishedContent> productInformationExtractor = ContentProductInformationExtractor.Instance; long storeId = productInformationExtractor.GetStoreId(content); HttpResponseMessage response = new HttpResponseMessage { Content = new StringContent(VatGroupService.Instance.Get(storeId, vatGroupId).ToJson()) }; response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(response); }
public static IEnumerable <OrderLine> OrderLinesThatMatchProductOrProductCategory(IProductService productService, int nodeId, IEnumerable <OrderLine> orderLines) { List <OrderLine> tempOrderLines = new List <OrderLine>(); string nodeIdStr = nodeId.ToString(CultureInfo.InvariantCulture); UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current); foreach (OrderLine orderLine in orderLines) { if (productService.GetSku(nodeIdStr) == orderLine.Sku) { tempOrderLines.Add(orderLine); continue; } ProductIdentifier productIdentifierObj = new ProductIdentifier(orderLine.ProductIdentifier); IPublishedContent productContent = umbracoHelper.TypedContent(productIdentifierObj.NodeId); if (productContent != null) { //Check the path - it could be a "product category" that was selected if (productContent.Path.Split(new[] { ',' }, StringSplitOptions.None).Contains(nodeIdStr)) { tempOrderLines.Add(orderLine); continue; } //Test if the master relation could be a "product category" that was selected string masterRelationNodeId = productContent.GetPropertyValue <string>(Constants.ProductPropertyAliases.MasterRelationPropertyAlias); if (string.IsNullOrEmpty(masterRelationNodeId)) { continue; } IPublishedContent masterRelationNode = umbracoHelper.TypedContent(masterRelationNodeId); if (masterRelationNode.Path.Split(new[] { ',' }, StringSplitOptions.None).Contains(nodeIdStr)) { tempOrderLines.Add(orderLine); } } } return(tempOrderLines); }
public void Then_each_product_should_receive_a_unique_id() { //Arrange List <ProductViewModel> productViewModels = new List <ProductViewModel>() { new ProductViewModel() { Name = "ProductA", Description = "Great product" } , new ProductViewModel() { Name = "ProductB", Description = "Bad product" } , new ProductViewModel() { Name = "ProductC", Description = "Cheap product" } , new ProductViewModel() { Name = "ProductD", Description = "Expensive product" } }; int productId = 1; var prod_iden = new ProductIdentifier() { RawValue = productId }; var mockProductRepository = new Mock <IProductRepository>(); Mock <IProductIdBuilder> mockIdBuilder = new Mock <IProductIdBuilder>(); mockIdBuilder.Setup(i => i.BuildProductIdentifier()) .Returns(prod_iden) .Callback(() => prod_iden.RawValue = productId++); ProductService productService = new ProductService(mockProductRepository.Object, mockIdBuilder.Object); //Act productService.CreateMany(productViewModels); //Assert mockProductRepository.Verify(p => p.Save(It.IsAny <Product>()), Times.AtLeastOnce()); }
public OrderLine CreateOrderLine(ProductIdentifier productIdentifier, int quantity) { if (Lines.Any(ol => ol.ProductIdentifier == productIdentifier)) { throw new InvalidOperationException($"An orderline with product {productIdentifier} already exists"); } var orderLineIdentifier = OrderLineIdentifier.NextIdentifier(Lines.LastIdentifier); ApplyChange( new OrderLineCreated( OrderIdentifier, orderLineIdentifier, productIdentifier, ProductName.Create("Unknown"), quantity)); return(Lines.Get(orderLineIdentifier)); }
public Stock GetStock(string productIdentifier) { Stock stock = new Stock(); ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IContent content = ApplicationContext.Current.Services.ContentService.GetById(productIdentifierObj.NodeId); IProductInformationExtractor <IContent, VariantPublishedContent> productInformationExtractor = ContentProductInformationExtractor.Instance; IVariantService <IContent, VariantPublishedContent> contentVariantService = ContentVariantService.Instance; long storeId = productInformationExtractor.GetStoreId(content); VariantPublishedContent variant = contentVariantService.GetVariant(storeId, content, productIdentifierObj.VariantId); stock.Sku = productInformationExtractor.GetSku(content, variant); decimal?stockValue = ProductService.Instance.GetStock(storeId, stock.Sku); stock.Value = stockValue != null?stockValue.Value.ToString("0.####") : ""; return(stock); }
public List <BasketItem> AddItemToBasket( string userId, ProductIdentifier identifier) { if (!identifier.Valid) { throw new ApplicationException("Invalid product identifier"); } var stockItem = _stockRepository.GetStockItem(identifier); if (stockItem == null) { throw new ApplicationException("Product Not Found: " + identifier); } _basketRepository.AddItemToUserBasket(userId, stockItem.Id); return(_basketRepository.GetBasket(userId)); }
public virtual ProductSnapshot GetSnapshot(string productIdentifier) { ProductIdentifier productIdentifierObj = new ProductIdentifier(productIdentifier); IPublishedContent content = UmbracoHelper.TypedContent(productIdentifierObj.NodeId); long storeId = GetStoreId(content); VariantPublishedContent variant = VariantService.GetVariant(storeId, content, productIdentifierObj.VariantId); ProductSnapshot snapshot = new ProductSnapshot(storeId, productIdentifier) { Sku = GetSku(content, variant), Name = GetName(content, variant), VatGroupId = GetVatGroupId(content, variant), LanguageId = GetLanguageId(content), OriginalUnitPrices = GetOriginalUnitPrices(content, variant), Properties = GetProperties(content, variant) }; return(snapshot); }
public IActionResult AddToBasket( [FromRoute] string userId, [FromQuery] int?productId = null, [FromQuery] string productName = null) { var identifier = new ProductIdentifier(productId, productName); var actionStatus = _addCommand .CanAddItemToBasketCheck(userId, identifier); var response = GetFailureResponseForCheck(actionStatus); if (response != null) { return(response); } var basket = _addCommand.AddItemToBasket(userId, identifier); return(Json(basket)); }
public BasketOperationStatus CanAddItemToBasketCheck( string userId, ProductIdentifier identifier) { if (!identifier.Valid) { return(BasketOperationStatus.InvalidIdentifier); } var stockItem = _stockRepository.GetStockItem(identifier); if (stockItem == null) { return(BasketOperationStatus.ProductNotFound); } var basketItem = _basketRepository.GetBasketItem(userId, stockItem.Id); return(stockItem.HasSufficientStockFor(basketItem.ItemCount + 1) ? BasketOperationStatus.Ok : BasketOperationStatus.InsufficientStock); }
public override Core.OrderManagement.Products.Events.ProductCreated ConvertToIntern(ProductCreated e) { return(new Core.OrderManagement.Products.Events.ProductCreated( ProductIdentifier.Parse(e.ProductIdentifier), ProductName.Create(e.ProductName))); }
public PricedProduct(ProductIdentifier identifier, decimal initialPrice) { Identifier = identifier; InitialPrice = DiscountedPrice = initialPrice; }
public Product(string name, ProductIdentifier identifier, decimal price) { Name = name; Identifier = identifier; Price = price; }