Exemple #1
0
        public void Setup()
        {
            this.simpleFactory = ChefMariano.Instance;

            this.coffeeFM = CoffeeFactory.Instance;
            this.pizzaFM  = VegePizzaFactory.Instance;

            this.withRegistration = PizzaFactoryWithRegistration.Instance;

            withRegistration.Register("meat", () => new Capriciosa());
            withRegistration.Register("vege", () => new Margherita());

            this.withReflection = PastaFactoryWithReflection.Instance;
            withReflection.Register("meatDish", typeof(BologneseSpaghetti));
            withReflection.Register("vegeDish", typeof(PestoSpaghetti));
        }
        public void CheckIfFactoryPreparesGivenFoodTypeTest()
        {
            PizzaFactoryWithRegistration factory = PizzaFactoryWithRegistration.Instance;

            factory.Register("meatPizza", () => new Capriciosa());
            factory.Register("vegePizza", () =>
            {
                return(new Margherita
                {
                    WithOlive = true
                });
            });

            var meat = factory.PreparePizza("meatPizza");
            var vege = factory.PreparePizza("vegePizza");

            Assert.That(vege, Is.InstanceOf <Margherita>());
            Assert.That(meat, Is.InstanceOf <Capriciosa>());
        }
Exemple #3
0
 public void TearDown()
 {
     this.withReflection   = null;
     this.withRegistration = null;
 }