Exemple #1
0
        public void CollectionTest_CollectionItems_True()
        {
            var collection = new CarCollection();
            var factory    = new CarFactory();

            collection.AddItem(factory.CreateInstance(CarType.Smart));
            collection.AddItem(factory.CreateInstance(CarType.Smart));
            collection.AddItem(factory.CreateInstance(CarType.Diesel));
            collection.AddItem(factory.CreateInstance(CarType.Electric));
            collection.AddItem(factory.CreateInstance(CarType.Smart));

            foreach (ICar sensor in collection)
            {
                sensor.Run();
            }
        }
Exemple #2
0
        public void GenericTest()
        {
            var collection = new CarCollection();

            collection.AddItem(new ElectricCar(new ActiveCarState()));
            collection.AddItem(new DieselCar(new WarningCarState()));
            collection.AddItem(new SmartCar(new BrokenCarState()));

            for (var i = 0; i < 5; i++)
            {
                foreach (ICar sensor in collection)
                {
                    sensor.Run();
                }
                Console.WriteLine("_______________________________________");
            }
        }