コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: ProductRepository.cs プロジェクト: JelleStu/OIVS
 public List <ProductDto> GetProducts(int companyID)
 {
     return(context.GetProducts(companyID));
 }
コード例 #5
0
        public List <Product> GetProducts()
        {
            List <Product> productList = _productContext.GetProducts();

            return(productList);
        }
コード例 #6
0
 // GET api/products
 public IEnumerable<Product> Get()
 {
     return _productContext.GetProducts();
 }