Exemple #1
0
        public void GetObjectType()
        {
            TestClass1 tc1 = new TestClass1();
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = tc1;
            mcfo.TargetMethod = "Method1";
            mcfo.AfterPropertiesSet();
            Assert.IsTrue(typeof(int).Equals(mcfo.ObjectType));

            mcfo              = new MethodInvokingFactoryObject();
            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "VoidRetvalMethod";
            mcfo.AfterPropertiesSet();
            Type objType = mcfo.ObjectType;

            Assert.IsTrue(objType.Equals(MethodInvoker.Void.GetType()));

            // verify that we can call a method with args that are subtypes of the
            // target method arg types
            TestClass1._staticField1 = 0;
            mcfo              = new MethodInvokingFactoryObject();
            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Supertypes";
            mcfo.Arguments    = new Object[] { new ArrayList(), new ArrayList(), "hello" };
            mcfo.AfterPropertiesSet();
            objType = mcfo.ObjectType;
        }
Exemple #2
0
        public void AfterPropertiesSetMissingMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = this;
            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet());
        }
Exemple #3
0
        public void AfterPropertiesSetStaticMethodMissingArgs()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Method1";
            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet());
        }
Exemple #4
0
        public void AfterPropertiesSetBogusStaticMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "some.bogus.Method.name";
            Assert.Throws <MissingMethodException>(() => mcfo.AfterPropertiesSet());
        }
Exemple #5
0
        public void AfterPropertiesSetBogusMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = this;
            mcfo.TargetMethod = "whatever";
            Assert.Throws <MissingMethodException>(() => mcfo.AfterPropertiesSet());
        }
Exemple #6
0
        public void GetMisMatchedArgumentTypes()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Supertypes";
            mcfo.Arguments    = new Object[] { "1", "2", "3" };
            Assert.Throws <TypeMismatchException>(() => mcfo.AfterPropertiesSet());
        }
Exemple #7
0
        public void GetSupertypesTooManyArgs()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Supertypes2";
            mcfo.Arguments    = new Object[] { new ArrayList(), new ArrayList(), "hello", "bogus" };
            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet(), "Unable to determine which exact method to call; found '2' matches.");
        }
Exemple #8
0
        public void InvokingAMethodThatHasAVoidReturnTypeReturnsNullPlaceHolder()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "VoidRetvalMethod";
            mcfo.AfterPropertiesSet();
            Assert.AreEqual(MethodInvoker.Void, mcfo.GetObject());
        }
Exemple #9
0
        public void ObjectTypeIsNullIfAfterPropertiesSetHasNotYetBeenInvoked()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "VoidRetvalMethod";
            Assert.IsNull(mcfo.ObjectType,
                          "ObjectType property value must only be set to a non null value " +
                          "AFTER the AfterPropertiesSet() method has been invoked.");
        }
Exemple #10
0
        public void GetSupertypesMatchNumArgs()
        {
            TestClass1._staticField1 = 0;
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Supertypes";
            mcfo.Arguments    = new Object[] { new ArrayList(), new ArrayList(), "hello" };
            // should pass
            mcfo.AfterPropertiesSet();
        }
Exemple #11
0
        public void InvokeGenericMethod()
        {
            TestClass1 tc1 = new TestClass1();
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(Activator);
            mcfo.TargetMethod = "CreateInstance<Oragon.Spring.Objects.TestObject>";
            mcfo.AfterPropertiesSet();

            object obj = mcfo.GetObject();

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is TestObject);
        }
Exemple #12
0
        public void GetSingletonStatic()
        {
            TestClass1._staticField1 = 0;
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "StaticMethod1";
            mcfo.AfterPropertiesSet();
            int i = (int)mcfo.GetObject();

            Assert.IsTrue(i == 1);
            i = (int)mcfo.GetObject();
            Assert.IsTrue(i == 1);
            Assert.IsTrue(mcfo.IsSingleton);
        }
Exemple #13
0
        public void GetSingletonNonStatic()
        {
            TestClass1 tc1 = new TestClass1();
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = tc1;
            mcfo.TargetMethod = "Method1";
            mcfo.AfterPropertiesSet();
            int i = (int)mcfo.GetObject();

            Assert.IsTrue(i == 1);
            i = (int)mcfo.GetObject();
            Assert.IsTrue(i == 1);
            Assert.IsTrue(mcfo.IsSingleton);
        }
Exemple #14
0
        public void BailsIfTheTargetMethodPropertyAintSet()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet(), "The 'TargetMethod' property is required.");
        }