Exemplo n.º 1
0
        public void FindMostExpensiveProductsShouldReturnNullIfCollectionIsEmpty()
        {
            var newProducts = new ProductStock();

            var result = newProducts.FindMostExpensiveProduct();

            Assert.AreEqual(result, null);
        }
Exemplo n.º 2
0
        public void ProductStock_FindMostExpensiveProductReturnsCorrectValue()
        {
            var stock = new ProductStock();

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

            var result = stock.FindMostExpensiveProduct();

            Assert.AreEqual(result.CompareTo(new Product("HDD", 20.7m, 3)), 0);
        }
Exemplo n.º 3
0
        public void FindMostExpensiveProducts_ReturnsProductsWithHighestPrice()
        {
            var price = 1.2m;

            for (int i = 0; i < 3; i++)
            {
                var product = new Product($"{i}", price * (i + 1), 1);
                productStock.Add(product);
            }
            for (int i = 3; i > 0; i--)
            {
                var product = new Product($"{i}m", price * (i + 7), i);
                productStock.Add(product);
            }

            var mostExpensive = productStock.FindMostExpensiveProduct();
            var expected      = new Product("3m", 10 * price, 3);

            Assert.AreEqual(expected.Price, mostExpensive.Price);
            Assert.AreEqual(expected.Label, mostExpensive.Label);
            Assert.AreEqual(expected.Quantity, mostExpensive.Quantity);
        }
Exemplo n.º 4
0
        public void ProductStock_FindMostExpensiveProductThrowsExceptionWhenThereAreNoProducts()
        {
            var stock = new ProductStock();

            Assert.Throws <InvalidOperationException>(() => stock.FindMostExpensiveProduct());
        }
Exemplo n.º 5
0
 public void FindMostExpensiveProduct_WhenCollectionIsEmptySHouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(() => productStock.FindMostExpensiveProduct());
 }