Example #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);
        }
Example #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));
        }
        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();
        }
Example #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);
        }
Example #6
0
        public void TestCreateObjectParametersException()
        {
            var factory = new GenericFactory();

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