コード例 #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(MethodInvokingFactoryObject.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;
        }
コード例 #2
0
        public void AfterPropertiesSetMissingMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = this;
            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet());
        }
コード例 #3
0
        public void AfterPropertiesSetMissingMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = this;
            mcfo.AfterPropertiesSet();
        }
コード例 #4
0
        public void AfterPropertiesSetStaticMethodMissingArgs()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Method1";
            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet());
        }
コード例 #5
0
        public void AfterPropertiesSetBogusStaticMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

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

            mcfo.TargetObject = this;
            mcfo.TargetMethod = "whatever";
            mcfo.AfterPropertiesSet();
        }
コード例 #7
0
        public void AfterPropertiesSetBogusStaticMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "some.bogus.Method.name";
            mcfo.AfterPropertiesSet();
        }
コード例 #8
0
        public void AfterPropertiesSetStaticMethodMissingArgs()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Method1";
            mcfo.AfterPropertiesSet();
        }
コード例 #9
0
        public void AfterPropertiesSetBogusMethod()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetObject = this;
            mcfo.TargetMethod = "whatever";
            Assert.Throws <MissingMethodException>(() => mcfo.AfterPropertiesSet());
        }
コード例 #10
0
        public void InvokingAMethodThatHasAVoidReturnTypeReturnsNullPlaceHolder()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "VoidRetvalMethod";
            mcfo.AfterPropertiesSet();
            Assert.AreEqual(MethodInvoker.Void, mcfo.GetObject());
        }
コード例 #11
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" };
            mcfo.AfterPropertiesSet();
        }
コード例 #12
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.");
        }
コード例 #13
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());
        }
コード例 #14
0
        public void GetMisMatchedArgumentTypes()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.TargetType   = typeof(TestClass1);
            mcfo.TargetMethod = "Supertypes";
            mcfo.Arguments    = new Object[] { "1", "2", "3" };
            mcfo.AfterPropertiesSet();
            mcfo.Invoke();
        }
コード例 #15
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();
        }
コード例 #16
0
        public void InvokeGenericMethod()
        {
            TestClass1 tc1 = new TestClass1();
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
            mcfo.TargetType = typeof(Activator);
            mcfo.TargetMethod = "CreateInstance<Spring.Objects.TestObject>";
            mcfo.AfterPropertiesSet();

            object obj = mcfo.GetObject();
            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is TestObject);
        }
コード例 #17
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);
		}
コード例 #18
0
        public void InvokeGenericMethod()
        {
            TestClass1 tc1 = new TestClass1();
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

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

            object obj = mcfo.GetObject();

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is TestObject);
        }
コード例 #19
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);
        }
コード例 #20
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);
        }
コード例 #21
0
		public void AfterPropertiesSetMissingMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetObject = this;
			mcfo.AfterPropertiesSet();
		}
コード例 #22
0
        public void BailsIfTheTargetMethodPropertyAintSet()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            mcfo.AfterPropertiesSet();
        }
コード例 #23
0
		public void InvokingAMethodThatHasAVoidReturnTypeReturnsNullPlaceHolder()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "VoidRetvalMethod";
			mcfo.AfterPropertiesSet();
			Assert.AreEqual(MethodInvoker.Void, mcfo.GetObject());
		}
コード例 #24
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();
		}
コード例 #25
0
		public void GetMisMatchedArgumentTypes()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "Supertypes";
			mcfo.Arguments = new Object[] {"1", "2", "3"};
			mcfo.AfterPropertiesSet();
			mcfo.Invoke();
		}
コード例 #26
0
		public void BailsIfTheTargetMethodPropertyAintSet()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
            Assert.Throws<ArgumentException>(() => mcfo.AfterPropertiesSet(), "The 'TargetMethod' property is required.");
		}
コード例 #27
0
		public void AfterPropertiesSetBogusMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetObject = this;
			mcfo.TargetMethod = "whatever";
			mcfo.AfterPropertiesSet();
		}
コード例 #28
0
		public void AfterPropertiesSetBogusStaticMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "some.bogus.Method.name";
            Assert.Throws<MissingMethodException>(() => mcfo.AfterPropertiesSet());
		}
コード例 #29
0
		public void AfterPropertiesSetBogusMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetObject = this;
			mcfo.TargetMethod = "whatever";
            Assert.Throws<MissingMethodException>(() => mcfo.AfterPropertiesSet());
		}
コード例 #30
0
		public void AfterPropertiesSetStaticMethodMissingArgs()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "Method1";
            Assert.Throws<ArgumentException>(() => mcfo.AfterPropertiesSet());
		}
コード例 #31
0
        public void BailsIfTheTargetMethodPropertyAintSet()
        {
            MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();

            Assert.Throws <ArgumentException>(() => mcfo.AfterPropertiesSet(), "The 'TargetMethod' property is required.");
        }
コード例 #32
0
		public void AfterPropertiesSetMissingMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetObject = this;
            Assert.Throws<ArgumentException>(() => mcfo.AfterPropertiesSet());
		}
コード例 #33
0
		public void AfterPropertiesSetStaticMethodMissingArgs()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "Method1";
			mcfo.AfterPropertiesSet();
		}
コード例 #34
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;
		}
コード例 #35
0
		public void AfterPropertiesSetBogusStaticMethod()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.TargetType = typeof (TestClass1);
			mcfo.TargetMethod = "some.bogus.Method.name";
			mcfo.AfterPropertiesSet();
		}
コード例 #36
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());
		}
コード例 #37
0
		public void BailsIfTheTargetMethodPropertyAintSet()
		{
			MethodInvokingFactoryObject mcfo = new MethodInvokingFactoryObject();
			mcfo.AfterPropertiesSet();
		}
コード例 #38
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.");
		}
コード例 #39
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"};
			mcfo.AfterPropertiesSet();
		}
コード例 #40
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);
		}