Esempio n. 1
0
        public void TestFactoryProductEquals()
        {
            var factory = new GenericFactory();

            var str = factory.CreateObject("System.String", parameters: TEST_STRING.ToCharArray());

            Assert.AreEqual(str, TEST_STRING);


            var dt1 = factory.CreateObject("System.DateTime", false, TEST_YEAR, TEST_MONTH, TEST_DAY);
            var dt2 = new DateTime(TEST_YEAR, TEST_MONTH, TEST_DAY);

            Assert.AreEqual(dt1, dt2);
        }
Esempio n. 2
0
        public void TestFactoryProductProperType()
        {
            var factory = new GenericFactory();

            var str = factory.CreateObject("System.String", parameters: new[] { 'z', 'c', 'v' });

            Assert.IsInstanceOfType(str, typeof(string));

            var dt = factory.CreateObject("System.DateTime");

            Assert.IsInstanceOfType(dt, typeof(DateTime));

            var genericFactory = factory.CreateObject("Zad2.GenericFactory");

            Assert.IsInstanceOfType(genericFactory, typeof(GenericFactory));
        }
Esempio n. 3
0
        public static void AbstractFactory()
        {
            // Language agnostic version
            CarFactory audiFactory = new AudiFactory();
            var driver1 = new Driver(audiFactory);
            driver1.CompareSpeed();
            ;

            CarFactory mercedesFactory = new MercedesFactory();
            var driver2 = new Driver(mercedesFactory);
            driver2.CompareSpeed();

            // C# specific version using generics
            var factory = new GenericFactory<MercedesSportsCar>();
            MercedesSportsCar mercedesSportsCar = factory.CreateObject();
            Console.WriteLine(mercedesSportsCar.GetType().ToString());

            Console.ReadKey();
        }
        public static void AbstractFactory()
        {
            // Language agnostic version
            CarFactory audiFactory = new AudiFactory();
            var        driver1     = new Driver(audiFactory);

            driver1.CompareSpeed();
            ;

            CarFactory mercedesFactory = new MercedesFactory();
            var        driver2         = new Driver(mercedesFactory);

            driver2.CompareSpeed();

            // C# specific version using generics
            var factory = new GenericFactory <MercedesSportsCar>();
            MercedesSportsCar mercedesSportsCar = factory.CreateObject();

            Console.WriteLine(mercedesSportsCar.GetType().ToString());

            Console.ReadKey();
        }
Esempio n. 5
0
        public void TestFactorySingletonFalseFlag()
        {
            var factory = new GenericFactory();
            var f1      = factory.CreateObject("Zad2.GenericFactory");
            var f2      = factory.CreateObject("Zad2.GenericFactory");

            Assert.AreNotSame(f1, f2);

            var str1 = factory.CreateObject("System.String", parameters: TEST_STRING.ToCharArray());
            var str2 = factory.CreateObject("System.String", parameters: TEST_STRING.ToCharArray());

            Assert.AreNotSame(str1, str2);

            var dt1 = factory.CreateObject("System.DateTime", false, TEST_YEAR, TEST_MONTH, TEST_DAY);
            var dt2 = factory.CreateObject("System.DateTime", false, TEST_YEAR, TEST_MONTH, TEST_DAY);

            Assert.AreNotSame(dt1, dt2);
        }
Esempio n. 6
0
        public void TestCreateObjectParametersException()
        {
            var factory = new GenericFactory();

            factory.CreateObject("System.String");
        }