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 TestRegisterObserverAddsObserverToList() { ProductStock productStock = new ProductStock(); List <IProductStockObserver> productStockObservers = productStock.Observers; Assert.AreEqual(0, productStockObservers.Count); productStock.RegisterObserver(new MockProductStockObserver()); Assert.AreEqual(1, productStockObservers.Count); }
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); }