Exemplo 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());
        }
Exemplo 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");
        }
Exemplo 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");
        }
Exemplo 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());
        }
Exemplo n.º 5
0
        public void CanUseAnyJellybeanDispenser()
        {
            SweetShop sweetShop = new SweetShop(new SweetVendingMachine(new AnyJellybeanDispenser(Jellybean.Lemon)));

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

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

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