Esempio n. 1
0
        public void CanUseConstructedObject()
        {
            IJellybeanDispenser dispenser = new AnyJellybeanDispenser(Jellybean.Cocoa);
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(dispenser));

            Assert.AreEqual(Jellybean.Cocoa, sweetShop.DispenseJellyBean());
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
        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");
        }
Esempio n. 4
0
        public void CanUseFactoryMethod()
        {
            Func<IJellybeanDispenser> factoryFunc = () => new AnyJellybeanDispenser(Jellybean.Orange);
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(factoryFunc()));

            Assert.AreEqual(Jellybean.Orange, sweetShop.DispenseJellyBean());
        }
Esempio n. 5
0
        public void CanUseAnyJellybeanDispenser()
        {
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new AnyJellybeanDispenser(Jellybean.Lemon)));

            Assert.AreEqual(Jellybean.Lemon, sweetShop.DispenseJellyBean());
        }
Esempio n. 6
0
        public void CanMakeSweetShopWithVanillaJellybeans()
        {
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new VanillaJellybeanDispenser()));

            Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean());
        }
Esempio n. 7
0
        public void CanMakeSweetShopWithStrawberryJellybeans()
        {
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new StrawberryJellybeanDispenser()));

            Assert.AreEqual(Jellybean.Strawberry, sweetShop.DispenseJellyBean());
        }