コード例 #1
0
        public void GetAllProducts()
        {
            ProductCollectionMoq.GetProducts(MockProductRepository, products);
            IList <Product> foundProducts = MockProductRepository.Object.GetProducts();

            Assert.AreEqual(3, foundProducts.Count);
        }
コード例 #2
0
        public void GetProductsToRefillWhenProductsWithQuantityLessThan10ReturnsProductsList()
        {
            ProductCollectionMoq.GetProductsToRefill(MockProductRepository, products);
            IList <Product> foundProducts = MockProductRepository.Object.GetProductsToRefill();

            Assert.AreEqual(2, foundProducts.Count);
        }
コード例 #3
0
        public void RefillWhenQuantity10ReturnTrue()
        {
            ProductCollectionMoq.GetProductsToRefill(MockProductRepository, products);
            IList <Product> foundProducts = MockProductRepository.Object.GetProductsToRefill();

            Assert.AreEqual(2, foundProducts.Count);
        }
コード例 #4
0
        public void GetProductPriceByKeyWhenProductExists()
        {
            ProductCollectionMoq.GetProductPriceByKey(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            double price = MockProductRepository.Object.GetProductPriceByKey(0);

            Assert.AreEqual(10, price);
        }
コード例 #5
0
        public void RemoveProductWhenIdExists()
        {
            ProductCollectionMoq.RemoveProduct(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            MockProductRepository.Object.RemoveProduct(0);

            IList <Product> foundProducts = MockProductRepository.Object.GetProducts();

            Assert.AreEqual(2, foundProducts.Count);
        }
コード例 #6
0
        public void GetProductPriceByKeyWhenNoProduct()
        {
            products = new List <Product>();

            ProductCollectionMoq.GetProductPriceByKey(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            double price = MockProductRepository.Object.GetProductPriceByKey(0);

            Assert.AreEqual(-1, price);
        }
コード例 #7
0
        public void DecreaseProductQuantityWhenIdExists()
        {
            ProductCollectionMoq.DecreaseProductQuantity(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            MockProductRepository.Object.DecreaseProductQuantity(0);

            IList <Product> foundProducts   = MockProductRepository.Object.GetProducts();
            int             updatedQuantity = foundProducts.FirstOrDefault(product => product.ProductId == 0).Quantity;

            Assert.AreEqual(5, updatedQuantity);
        }
コード例 #8
0
        public void AddProduct()
        {
            ProductCollectionMoq.AddProduct(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            Product p = new Product {
                ProductId = 0, Name = "ProdTest1a", Quantity = 4, Price = 10
            };

            MockProductRepository.Object.AddProduct(p);
            IList <Product> foundProducts = MockProductRepository.Object.GetProducts();

            Assert.AreEqual(foundProducts.Count, products.Count);
        }
コード例 #9
0
        public void UpdateProduct()
        {
            ProductCollectionMoq.UpdateProduct(MockProductRepository, products);
            ProductCollectionMoq.GetProducts(MockProductRepository, products);

            Product p = new Product {
                ProductId = 0, Name = "ProdTest1a", Quantity = 4, Price = 10
            };

            MockProductRepository.Object.UpdateProduct(p);
            IList <Product> foundProducts = MockProductRepository.Object.GetProducts();

            string updatedName = foundProducts.FirstOrDefault(product => product.ProductId == p.ProductId).Name;

            Assert.AreEqual("ProdTest1a", updatedName);
        }
コード例 #10
0
        public void GetProductsToRefillWhenAllProductsQuantityAre10ReturnsEmptyList()
        {
            products = new List <Product>
            {
                new Product {
                    Name = "ProdTest1", Quantity = 10, Price = 10
                },
                new Product {
                    Name = "ProdTest2", Quantity = 10, Price = 10
                },
                new Product {
                    Name = "ProdTest3", Quantity = 10, Price = 10
                },
            };

            ProductCollectionMoq.GetProductsToRefill(MockProductRepository, products);
            IList <Product> foundProducts = MockProductRepository.Object.GetProductsToRefill();

            Assert.AreEqual(0, foundProducts.Count);
        }