/// <summary> /// Checks if the product is existing in the current store and if the passed quantity is present. /// Returns ProductInjuryResult.NotFound in case the product does not exists /// Returns ProductInjuryResult.QuantityNotAvailable in case the passed quantity is greater than the stock /// </summary> /// <param name="productId">The product identifier.</param> /// <param name="quantity">The quantity of the product.</param> /// <returns>ProductInjuryResult.</returns> public ProductInjuryResult CheckProduct(int productId, int quantity) { var availableProducts = _productContext.GetProducts(); var product = availableProducts.FirstOrDefault(p => p.Id == productId); if (product == null) { return(ProductInjuryResult.NotFound); } else if (product.StockQuantity < quantity) { return(ProductInjuryResult.QuantityNotAvailable); } return(ProductInjuryResult.Ok); }
private bool CanCheckout(List <Product> shoppingBasket) { foreach (var cartProduct in shoppingBasket) { var realProduct = _productContext.GetProducts().FirstOrDefault(x => x.Identifier == cartProduct.Identifier); if (realProduct == null) { return(false); } if (realProduct.Stock < cartProduct.Stock) { return(false); } } return(true); }
public void GetProducts_CanReturn_AnyProductsFromDataSource() { //Arrange _mockConfig.Setup(x => x.GetDataSourcePath()).Returns(It.IsAny <string>()); var expectedProducts = Builder <Product> .CreateListOfSize(10).Build(); _mockDataSource.Setup(x => x.LoadProducts(It.IsAny <string>())).Returns(expectedProducts); //Act var products = _productContext.GetProducts(); //Assert _mockConfig.Verify(x => x.GetDataSourcePath(), Times.Once); _mockDataSource.Verify(x => x.LoadProducts(It.IsAny <string>()), Times.Once); products.ShouldAllBeEquivalentTo(expectedProducts); }
public List <ProductDto> GetProducts(int companyID) { return(context.GetProducts(companyID)); }
public List <Product> GetProducts() { List <Product> productList = _productContext.GetProducts(); return(productList); }
// GET api/products public IEnumerable<Product> Get() { return _productContext.GetProducts(); }