public void DefaultConstructor_WithoutType()
        {
            var cd = TestClassType.DefaultContructor();

            Assert.IsNotNull(cd);
            Assert.IsNotNull(cd());
            Assert.IsInstanceOfType(cd(), TestClassType);
        }
        public void DefaultConstructor_ByDelegate_WithType_ByDelegate()
        {
            var cd = TestClassType.Contructor <Func <TestClass> >();

            Assert.IsNotNull(cd);
            Assert.IsNotNull(cd());
            Assert.IsInstanceOfType(cd(), TestClassType);
        }
        public void DefaultConstructor_WithType()
        {
            var cd = DelegateFactory.DefaultContructor <TestClass>();

            Assert.IsNotNull(cd);
            Assert.IsNotNull(cd());
            Assert.IsInstanceOfType(cd(), TestClassType);
        }
        public void ConstructorByDelegateWithType_WithCustomDelegate_NoParams()
        {
            var cd = DelegateFactory.Contructor <CustomCtr>();

            Assert.IsNotNull(cd);
            Assert.IsNotNull(cd());
            Assert.IsInstanceOfType(cd(), TestClassType);
        }
        public void ConstructorByDelegateWithType_NoParams()
        {
            var c = DelegateFactory.Contructor <Func <TestClass> >();

            Assert.IsNotNull(c);
            Assert.IsNotNull(c());
            Assert.IsInstanceOfType(c(), TestClassType);
        }
        public void ConstructorByDelegateWithType_IntParam_FromStruct()
        {
            var c = DelegateFactory.Contructor <Func <int, TestStruct> >();

            Assert.IsNotNull(c);
            var instance = c(0);

            Assert.IsInstanceOfType(instance, TestStructType);
        }
        public void ConstructorByExtensionMethodAndObject_BoolParam()
        {
            var c = TestClassType.Contructor <Func <bool, object> >();

            Assert.IsNotNull(c);
            var instance = c(false);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByObjects_StringParam()
        {
            var c = TestClassType.Contructor(typeof(string));

            Assert.IsNotNull(c);
            var instance = c(new object[] { "s" });

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByObjects_NoParam()
        {
            var c = TestClassType.Contructor();

            Assert.IsNotNull(c);
            var instance = c(null);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByObjects_IntParam_FromStruct()
        {
            var c = TestStructType.Contructor(typeof(int));

            Assert.IsNotNull(c);
            var instance = c(new object[] { 0 });

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestStructType);
        }
        public void ConstructorByObjects_BoolParam()
        {
            var c = TestClassType.Contructor(typeof(bool));

            Assert.IsNotNull(c);
            var instance = c(new object[] { false });

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByExtensionMethodAndType_StringParam()
        {
            var c = TestClassType.Contructor <Func <string, TestClass> >();

            Assert.IsNotNull(c);
            var instance = c("s");

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByExtensionMethodAndObject_IntParam_FromStruct()
        {
            var c = TestStructType.Contructor <Func <int, object> >();

            Assert.IsNotNull(c);
            var instance = c(0);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestStructType);
        }
        public void ConstructorByDelegateWithType_BoolParam()
        {
            var c = DelegateFactory.Contructor <Func <bool, TestClass> >();

            Assert.IsNotNull(c);
            var instance = c(false);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByDelegateWithType_StringParam()
        {
            var c = DelegateFactory.Contructor <Func <string, TestClass> >();

            Assert.IsNotNull(c);
            var instance = c("s");

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void ConstructorByDelegateWithType_WithCustomDelegate_SingleParam()
        {
            var cd = DelegateFactory.Contructor <CustomCtrSingleParam>();

            Assert.IsNotNull(cd);
            var instance = cd(0);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, TestClassType);
        }
        public void Public_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.InstanceMethod <Func <TestClass, TestClass>, TestClass>("PublicInstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjectAndTypes_WithCast()
        {
            var m = _testClassType.InstanceMethod <Func <object, TestClass>, TestClass>("PrivateInstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
Esempio n. 19
0
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjectAndTypes()
        {
            var m = _testClassType.StaticMethod <Func <TestClass>, TestClass>("PrivateStaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m();

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
Esempio n. 20
0
        public void Internal_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByTypes()
        {
            var m = DelegateFactory.StaticMethod <TestClass, Func <TestClass>, TestClass>("InternalStaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m();

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
Esempio n. 21
0
        public void Private_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("PrivateStaticGenericMethod", null,
                                                       new[] { _testClassType });

            Assert.IsNotNull(m);
            var result = m(new object[] { });

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
        }
        public void Protected_GenericMethod_NoVoid_NoParameter_OneTypeParameter_ByObjects()
        {
            var m = _testClassType.InstanceGenericMethod("ProtectedInstanceGenericMethod", null,
                                                         new[] { _testClassType });

            Assert.IsNotNull(m);
            var result = m(_testClassInstance, new object[] { _testClassInstance });

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
        }
Esempio n. 23
0
        public void GenericMethod_NoVoid_NoParameter_2TypeParameters_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("StaticGenericMethod", null,
                                                       new[] { _testClassType, _testStructType });

            Assert.IsNotNull(m);
            var result = m(new object[0]);

            Assert.AreEqual(null, TestClass.StaticPublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), TestClass.StaticPublicTypeParams[1]);
        }
        public void GenericMethod_NoVoid_NoParameter_2TypeParameters_ByObjectAndTypes()
        {
            var m = _testClassType.InstanceMethod <Func <TestClass, TestClass>, TestClass, TestStruct>
                        ("InstanceGenericMethod");

            Assert.IsNotNull(m);
            var result = m(_testClassInstance);

            Assert.AreEqual(null, _testClassInstance.PublicParams);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), _testClassInstance.PublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), _testClassInstance.PublicTypeParams[1]);
        }
        public void EventAdd_ByTypes_Private()
        {
            var accessor = DelegateFactory.EventAdd <TestClass, TestClass.PrivateEventArgs>("PrivateEvent");

            Assert.IsNotNull(accessor);
            var eventExecuted = false;

            accessor(_testClassInstance, (sender, args) =>
            {
                eventExecuted = true;
                Assert.IsInstanceOfType(args, typeof(TestClass.PrivateEventArgs));
            });
            _testClassInstance.InvokePrivateEvent();
            Assert.IsTrue(eventExecuted);
        }
        public void EventAdd_ByObjects_Protected()
        {
            var accessor = _testClassType.EventAdd("ProtectedEvent");

            Assert.IsNotNull(accessor);
            var eventExecuted = false;

            accessor(_testClassInstance, (sender, args) =>
            {
                eventExecuted = true;
                Assert.IsInstanceOfType(args, typeof(TestClass.ProtectedEventArgs));
            });
            _testClassInstance.InvokeProtectedEvent();
            Assert.IsTrue(eventExecuted);
        }
        public void EventAdd_ByObjectAndType_Internal()
        {
            var accessor = _testClassType.EventAdd <TestClass.InternalEventArgs>("InternalEvent");

            Assert.IsNotNull(accessor);
            var eventExecuted = false;

            accessor(_testClassInstance, (sender, args) =>
            {
                eventExecuted = true;
                Assert.IsInstanceOfType(args, typeof(TestClass.InternalEventArgs));
            });
            _testClassInstance.InvokeInternalEvent();
            Assert.IsTrue(eventExecuted);
        }
Esempio n. 28
0
        public void GenericMethod_NoVoid_SingleParameter_3TypeParameters_ByObjects()
        {
            var m = _testClassType.StaticGenericMethod("StaticGenericMethod", new[] { typeof(int) },
                                                       new[] { _testClassType, _testStructType, typeof(TestClassNoDefaultCtor) });

            Assert.IsNotNull(m);
            var result = m(new object[] { 0 });

            Assert.AreEqual(1, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(0, TestClass.StaticPublicParams[0]);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), TestClass.StaticPublicTypeParams[1]);
            Assert.AreEqual(typeof(TestClassNoDefaultCtor), TestClass.StaticPublicTypeParams[2]);
        }
Esempio n. 29
0
        public void GenericMethod_NoVoid_SingleParameter_3TypeParameters_ByObjectAndTypes()
        {
            var m = _testClassType.StaticMethod <Func <int, TestClass>, TestClass, TestStruct, TestClassNoDefaultCtor>
                        ("StaticGenericMethod");

            Assert.IsNotNull(m);
            var result = m(0);

            Assert.AreEqual(1, TestClass.StaticPublicParams.Length);
            Assert.AreEqual(0, TestClass.StaticPublicParams[0]);
            Assert.IsInstanceOfType(result, typeof(TestClass));
            Assert.AreEqual(typeof(TestClass), TestClass.StaticPublicTypeParams[0]);
            Assert.AreEqual(typeof(TestStruct), TestClass.StaticPublicTypeParams[1]);
            Assert.AreEqual(typeof(TestClassNoDefaultCtor), TestClass.StaticPublicTypeParams[2]);
        }
Esempio n. 30
0
        public static void ThrowsException <TException>(Action action)
        {
            Exception exp = null;

            try
            {
                action();
            }
            catch (Exception e)
            {
                exp = e;
            }
            Assert.IsNotNull(exp);
            Assert.IsInstanceOfType(exp, typeof(TException));
        }