Example #1
0
        public void FindAllByQuantity_ReturnsProductsOrEmptyCollection(int quantity)
        {
            var productsWithQuantity = new List <IProduct>();

            for (int i = 0; i <= 3; i++)
            {
                var product  = new Product($"{i} product", 1.1m, i + 1);
                var product2 = new Product($" product{i}", 2.2m, i + 2);
                productStock.Add(product);
                productStock.Add(product2);

                if (product.Quantity == quantity)
                {
                    productsWithQuantity.Add(product);
                }
                if (product2.Quantity == quantity)
                {
                    productsWithQuantity.Add(product2);
                }
            }

            var productsFound = productStock.FindAllByQuantity(quantity);

            CollectionAssert.AreEqual(productsFound, productsWithQuantity);
        }
Example #2
0
        public void ProductStock_FindByPriceReturnsCorrectEmptyCollection(int quantity)
        {
            var stock = new ProductStock();

            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("HDD", 12.4m, 3));
            stock.Add(new Product("RAM", 12.4m, 3));

            var result = stock.FindAllByQuantity(quantity);

            Assert.AreEqual(result.Count(), 0);
        }
Example #3
0
        public void ProductStock_FindByQuantityReturnCorrectNonEmptyCollection()
        {
            var stock = new ProductStock();

            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("SSD", 12.4m, 3));
            stock.Add(new Product("HDD", 12.4m, 3));
            stock.Add(new Product("RAM", 12.4m, 3));
            var result = stock.FindAllByQuantity(3);

            string[] names = new string[] { "HDD", "RAM" };
            int      i     = 0;

            foreach (var item in result)
            {
                Assert.AreEqual(item.CompareTo(new Product(names[i++], 12.4m, 3)), 0);
            }
        }
        public void FindAllByQuantity_ShouldReturnEmptyEnumeration()
        {
            var actual = productStock.FindAllByQuantity(2);

            Assert.IsEmpty(actual);
        }