コード例 #1
0
        public void ProductStock_AddMethodThrowsExceptionWhenAddingInvalidProdduct()
        {
            var stock = new ProductStock();

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

            Assert.Throws <ArgumentNullException>(() => stock.Add(new Product(null, 12.4m, 2)));
        }
コード例 #2
0
        public void ProductStock_CountMethodReturnsCorrectNumberOfProductsInStock()
        {
            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));
            Assert.AreEqual(stock.Count, 2);
        }
コード例 #3
0
        public void ProductStock_FindMethodThrowsExceptionWhenSearchingWithInvalidIndex(int index)
        {
            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));

            Assert.Throws <IndexOutOfRangeException>(() => stock.Find(index));
        }
コード例 #4
0
        public void ProductStock_FindMethodReturnsCorrectElement(int index, string name)
        {
            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));
            Assert.AreEqual(stock.Find(index).CompareTo(new Product(name, 12.4m, 3)), 0);
        }
コード例 #5
0
        public void ProductStock_AddMethodIncreasesCountCorrectly()
        {
            var stock = new ProductStock();

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

            stock.Add(new Product("HDD", 12.4m, 2));

            Assert.AreEqual(stock.Count, 2);
        }
コード例 #6
0
        public void ProductStock_FindByLabelThrowsExceptionWhenProductCannotBeFound()
        {
            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));

            Assert.Throws <ArgumentException>(() => stock.FindByLabel("GPU"));
        }
コード例 #7
0
        public void ProductStock_FindByLabelReturnsTheCorrectProduct()
        {
            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));

            Assert.AreEqual(stock.FindByLabel("SSD").CompareTo(new Product("SSD", 12.4m, 3)), 0);
        }
コード例 #8
0
        public void ProductStock_RemoveMethodReturnsFalse()
        {
            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));

            Assert.IsFalse(stock.Remove(new Product("GPU", 12.4m, 3)));
        }
コード例 #9
0
        public void ProductStock_RandomTest()
        {
            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));

            stock.FindByLabel("SSD").Price = 100;
        }
コード例 #10
0
        public void ProductStock_IndexerThrowsExceptionWhenGettingInvalidIndex(int index)
        {
            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));
            IProduct result = null;

            Assert.Throws <IndexOutOfRangeException>(() => result = stock[index]);
        }
コード例 #11
0
        public void ProductStock_IndexerThrowsExceptionWhenSettingNullProduct(int index)
        {
            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));
            IProduct result = null;

            Assert.Throws <ArgumentNullException>(() => stock[index] = result);
        }
コード例 #12
0
        public void ProductStock_IndexerGetsTheCorrectElementFromStock(string name, int index)
        {
            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));

            IProduct result = stock[index];

            Assert.AreEqual(result.CompareTo(new Product(name, 12.4m, 3)), 0);
        }
コード例 #13
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);
        }
コード例 #14
0
        public void ProductStock_FindByPriceReturnCorrectEmptyCollection(decimal price)
        {
            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.FindAllByPrice(price);

            Assert.AreEqual(result.Count(), 0);
        }
コード例 #15
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);
        }
コード例 #16
0
        public void ProductStock_FindByPriceRangeReturnsCorrectEmptyCollection(decimal lo, decimal hi)
        {
            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.FindAllInRange(lo, hi);

            Assert.AreEqual(result.Count(), 0);
        }
コード例 #17
0
        public void ProductStock_RemoveMethodReturnsTrue()
        {
            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));

            Assert.IsTrue(stock.Remove(new Product("SSD", 12.4m, 3)));

            Assert.AreEqual(stock[0].Quantity, 0);
        }
コード例 #18
0
        public void ProductStock_ContainsMethodReturnsFalse(string name, decimal price, int quantity)
        {
            var stock = new ProductStock();

            stock.Add(new Product(name, price, quantity));
            Assert.IsFalse(stock.Contains(new Product("GPU", 12.4m, 3)));
        }
コード例 #19
0
        public void ProductStock_FindByPriceRangeReturnsCorrectNonEmptyCollection(decimal lo, decimal hi, string orderNames)
        {
            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.FindAllInRange(lo, hi);
            var names  = orderNames.Split(" ").ToArray();
            int i      = 0;

            foreach (var item in result)
            {
                Assert.AreEqual(item.CompareTo(new Product(names[i++], 12.4m, 3)), 0);
            }
        }
コード例 #20
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);
            }
        }
コード例 #21
0
        public void ProductStock_TestEnumeratorReturnsCorrectValue()
        {
            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 items = new List <IProduct>()
            {
                new Product("SSD", 12.4m, 3), new Product("CPU", 16.5m, 3), new Product("HDD", 20.7m, 3), new Product("RAM", 14.9m, 3)
            };
            int index = 0;

            Console.WriteLine();
            foreach (var item in stock)
            {
                Assert.AreEqual(item.CompareTo(items[index++]), 0);
            }
        }
コード例 #22
0
        public void Add_ShouldIncreaseCountCorrectly()
        {
            productStock.Add(product);

            var expectedCount = 1;
            var actualCount   = productStock.Count;

            Assert.AreEqual(expectedCount, actualCount);
        }
コード例 #23
0
        public void ProductStock_AddMethodThrowsExceptionWhenAddingNullProdduct()
        {
            var stock = new ProductStock();

            Assert.Throws <ArgumentNullException>(() => stock.Add(null));
        }
コード例 #24
0
        public void AddMethod_ShouldAddProductsIfLabelIsUnique(string label)
        {
            var product0 = new Product(label, 1.20m, 1);
            var product1 = new Product("other", 1.20m, 1);

            productStock.Add(product0);
            productStock.Add(product1);

            Assert.AreEqual(product0, productStock[0]);
            Assert.AreEqual(product1, productStock[1]);
            Assert.AreEqual(2, productStock.Count);
        }