Beispiel #1
0
        public void TestInvalidInvokeConstructor()
        {
            // No Ctor
            try
            {
                ConstructorHelper.InvokeConstructor(typeof(SupportCtorNone), new Object[0]);
                Assert.Fail();
            }
            catch (MissingMethodException)
            {
                // Expected
            }

            // Not matching Ctor - number of paramList
            try
            {
                ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new Object[0]);
                Assert.Fail();
            }
            catch (MissingMethodException)
            {
                // Expected
            }

            // Type not matching
            try
            {
                ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new Object[] { "a" });
                Assert.Fail();
            }
            catch (MissingMethodException)
            {
                // Expected
            }
        }
Beispiel #2
0
        public void TestValidInvokeConstructor()
        {
            Object[] paramList            = new Object[] { "test", 1 };
            SupportCtorObjectArray objOne = (SupportCtorObjectArray)ConstructorHelper.InvokeConstructor(typeof(SupportCtorObjectArray), paramList);

            Assert.AreEqual(paramList, objOne.Arguments);

            SupportCtorInt objTwo = (SupportCtorInt)ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new Object[] { 99 });

            Assert.AreEqual(99, objTwo.SomeValue);
            objTwo = (SupportCtorInt)ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new Object[] { 13 });
            Assert.AreEqual(13, objTwo.SomeValue);

            SupportCtorIntObjectArray objThree = (SupportCtorIntObjectArray)ConstructorHelper.InvokeConstructor(typeof(SupportCtorIntObjectArray), new Object[] { 1 });

            Assert.AreEqual(1, objThree.SomeValue);
            objThree = (SupportCtorIntObjectArray)ConstructorHelper.InvokeConstructor(typeof(SupportCtorIntObjectArray), paramList);
            Assert.AreEqual(paramList, objThree.Arguments);
        }