public void CanUseConstructedObject() { IJellybeanDispenser dispenser = new AnyJellybeanDispenser(Jellybean.Cocoa); SweetShop sweetShop = new SweetShop(new SweetVendingMachine(dispenser)); Assert.AreEqual(Jellybean.Cocoa, sweetShop.DispenseJellyBean()); }
public void CanMakeSingletonJellybeanDispenser() { IJellybeanDispenser jellybeanDispenser = new StrawberryJellybeanDispenser(); SweetShop sweetShop = new SweetShop(new SweetVendingMachine(jellybeanDispenser)); SweetShop sweetShop2 = new SweetShop(new SweetVendingMachine(jellybeanDispenser)); Assert.AreNotSame(sweetShop, sweetShop2, "Root objects are equal"); Assert.AreNotSame(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine, "Contained objects are equal"); // should be same service Assert.AreSame(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser, "services are not equal"); }
public void JellybeanDispenserHasNewInstanceEachTime() { SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new StrawberryJellybeanDispenser())); SweetShop sweetShop2 = new SweetShop(new SweetVendingMachine(new StrawberryJellybeanDispenser())); Assert.AreNotSame(sweetShop, sweetShop2, "Root objects are equal"); Assert.AreNotSame(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine, "Contained objects are equal"); Assert.AreNotSame(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser, "services are equal"); }
public void CanUseFactoryMethod() { Func<IJellybeanDispenser> factoryFunc = () => new AnyJellybeanDispenser(Jellybean.Orange); SweetShop sweetShop = new SweetShop(new SweetVendingMachine(factoryFunc())); Assert.AreEqual(Jellybean.Orange, sweetShop.DispenseJellyBean()); }
public void CanUseAnyJellybeanDispenser() { SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new AnyJellybeanDispenser(Jellybean.Lemon))); Assert.AreEqual(Jellybean.Lemon, sweetShop.DispenseJellyBean()); }
public void CanMakeSweetShopWithVanillaJellybeans() { SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new VanillaJellybeanDispenser())); Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean()); }
public void CanMakeSweetShopWithStrawberryJellybeans() { SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new StrawberryJellybeanDispenser())); Assert.AreEqual(Jellybean.Strawberry, sweetShop.DispenseJellyBean()); }