public void TestRemovingAProductNotifesAllObservers() { ProductStock productStock = new ProductStock(); MockProductStockObserver mockProductStockObserverOne = new MockProductStockObserver(); MockProductStockObserver mockProductStockObserverTwo = new MockProductStockObserver(); productStock.RegisterObserver(mockProductStockObserverOne); productStock.RegisterObserver(mockProductStockObserverTwo); productStock.Remove(Products.Cola); Assert.AreEqual(1, mockProductStockObserverOne.NumberOfTimesProductStockUpdatedWasCalled); Assert.AreEqual(Products.Cola, mockProductStockObserverOne.LastProductPassedToProductStockUpdated); Assert.AreEqual(1, mockProductStockObserverTwo.NumberOfTimesProductStockUpdatedWasCalled); Assert.AreEqual(Products.Cola, mockProductStockObserverTwo.LastProductPassedToProductStockUpdated); productStock.Remove(Products.Candy); Assert.AreEqual(2, mockProductStockObserverOne.NumberOfTimesProductStockUpdatedWasCalled); Assert.AreEqual(Products.Candy, mockProductStockObserverOne.LastProductPassedToProductStockUpdated); Assert.AreEqual(2, mockProductStockObserverTwo.NumberOfTimesProductStockUpdatedWasCalled); Assert.AreEqual(Products.Candy, mockProductStockObserverTwo.LastProductPassedToProductStockUpdated); }
public void RemoveMethod_RemovesProductIfExists(string label) { productStock.Add(new Product("exists", 2.2m, 3)); productStock.Add(new Product("exists2", 12.2m, 23)); productStock.Add(new Product("exists3", 22.2m, 33)); productStock.Add(new Product("exists4", 2.2m, 7)); Assert.That(productStock.Count == 4); var productToRemove = new Product(label, 2.2m, 3); Assert.IsTrue(productStock.Remove(productToRemove)); Assert.AreEqual(productStock.Count, 3); }
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)); }
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))); }
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); } }
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); }
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); }
public void Remove_NonExistingProductShouldReturnFalse() { Assert.IsFalse(productStock.Remove(product)); }