コード例 #1
0
        public void TestProductStockStartsWithFiveOfEachItem()
        {
            ProductStock productStock = new ProductStock();

            Assert.AreEqual(5, productStock.Count(Products.Cola));
            Assert.AreEqual(5, productStock.Count(Products.Chips));
            Assert.AreEqual(5, productStock.Count(Products.Candy));
        }
コード例 #2
0
        public void TestCountCantGoBelowZero()
        {
            ProductStock productStock = new ProductStock();

            int originalCountAndMore = productStock.Count(Products.Cola) + 3;

            for (int i = 0; i < originalCountAndMore; i++)
            {
                productStock.Remove(Products.Cola);
                Assert.GreaterOrEqual(productStock.Count(Products.Cola), 0);
            }
        }
コード例 #3
0
        public void TestHandlesUnknownProductsGracefully()
        {
            MockProduct              mockProduct              = new MockProduct();
            ProductStock             productStock             = new ProductStock();
            MockProductStockObserver mockProductStockObserver = new MockProductStockObserver();

            productStock.RegisterObserver(mockProductStockObserver);

            productStock.Remove(mockProduct);
            Assert.AreEqual(0, productStock.Count(mockProduct));
            Assert.AreEqual(0, mockProductStockObserver.NumberOfTimesProductStockUpdatedWasCalled);
        }
コード例 #4
0
        public void TestRemovingACandyDecrementsCountForCandyOnly()
        {
            ProductStock productStock = new ProductStock();

            productStock.Remove(Products.Candy);

            Assert.AreEqual(4, productStock.Count(Products.Candy));
            Assert.AreEqual(5, productStock.Count(Products.Cola));
            Assert.AreEqual(5, productStock.Count(Products.Chips));

            productStock.Remove(Products.Candy);

            Assert.AreEqual(3, productStock.Count(Products.Candy));
            Assert.AreEqual(5, productStock.Count(Products.Cola));
            Assert.AreEqual(5, productStock.Count(Products.Chips));
        }