Beispiel #1
0
        public static void Verify_Invoke_ReturnsNewObject()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            Assert.Equal(cis.Length, 3);
            ConstructorInfoInvokeSample obj = (ConstructorInfoInvokeSample)cis[0].Invoke(null);

            Assert.NotNull(obj);
        }
Beispiel #2
0
        public static void TestInvoke_WrongParamType()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj = null;

            AssertExtensions.Throws <ArgumentException>(null, () => { obj = (ConstructorInfoInvokeSample)cis[1].Invoke(new object[] { "hello" }); });
        }
Beispiel #3
0
        public static void TestInvoke_ParamMismatch()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj = null;

            Assert.Throws <TargetParameterCountException>(() => { obj = (ConstructorInfoInvokeSample)cis[2].Invoke(new object[] { 121 }); });
        }
Beispiel #4
0
        public void TestInvoke1()
        {
            ConstructorInfo[] cis = GetConstructor(typeof(ConstructorInfoInvokeSample));
            Assert.Equal(cis.Length, 3);
            ConstructorInfoInvokeSample obj = (ConstructorInfoInvokeSample)cis[0].Invoke(null);

            Assert.NotNull(obj);
        }
Beispiel #5
0
        public void TestInvoke10()
        {
            ConstructorInfo[] cis = GetConstructor(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj = null;

            Assert.Throws <ArgumentException>(() => { obj = (ConstructorInfoInvokeSample)cis[1].Invoke(new object[] { "hello" }); });
        }
Beispiel #6
0
        public static void TestInvokeWithOneParam()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj = null;

            obj = (ConstructorInfoInvokeSample)cis[1].Invoke(new object[] { 100 });

            Assert.NotNull(obj);
            Assert.Equal(obj.intValue, 100);
        }
Beispiel #7
0
        public static void TestInvoke_ConstructorOnExistingInstance()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj1 = new ConstructorInfoInvokeSample(100, "hello");
            ConstructorInfoInvokeSample obj2 = null;

            obj2 = (ConstructorInfoInvokeSample)cis[2].Invoke(obj1, new object[] { 999, "initialized" });
            Assert.Null(obj2);
            Assert.Equal(obj1.intValue, 999);
            Assert.Equal(obj1.strValue, "initialized");
        }
Beispiel #8
0
        public static void TestInvokeWithTwoParams()
        {
            ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
            //try to invoke Array ctors with one param
            ConstructorInfoInvokeSample obj = null;

            obj = (ConstructorInfoInvokeSample)cis[2].Invoke(new object[] { 101, "hello" });

            Assert.NotNull(obj);
            Assert.Equal(obj.intValue, 101);
            Assert.Equal(obj.strValue, "hello");
        }
 public static void TestInvoke_ConstructorOnExistingInstance()
 {
     ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample));
     //try to invoke Array ctors with one param
     ConstructorInfoInvokeSample obj1 = new ConstructorInfoInvokeSample(100, "hello");
     ConstructorInfoInvokeSample obj2 = null;
     obj2 = (ConstructorInfoInvokeSample)cis[2].Invoke(obj1, new object[] { 999, "initialized" });
     Assert.Null(obj2);
     Assert.Equal(obj1.intValue, 999);
     Assert.Equal(obj1.strValue, "initialized");
 }