예제 #1
0
        public void TestInvalidInvokeConstructor()
        {
            // No Ctor
            Assert.That(
                () => ConstructorHelper.InvokeConstructor(typeof(SupportCtorNone), new object[0]),
                Throws.InstanceOf <MissingMethodException>());

            // Not matching Ctor - number of params
            Assert.That(
                () => ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new object[0]),
                Throws.InstanceOf <MissingMethodException>());

            // Type not matching
            Assert.That(
                () => ConstructorHelper.InvokeConstructor(typeof(SupportCtorInt), new object[] { "a" }),
                Throws.InstanceOf <MissingMethodException>());
        }
예제 #2
0
        public void TestValidInvokeConstructor()
        {
            object[] parameters           = new object[] { "test", 1 };
            SupportCtorObjectArray objOne = (SupportCtorObjectArray)ConstructorHelper.InvokeConstructor(typeof(SupportCtorObjectArray), parameters);

            Assert.AreEqual(parameters, 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[] { new int?(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), parameters);
            Assert.AreEqual(parameters, objThree.Arguments);
        }