コード例 #1
0
        public void TestResolveMethodNotFound()
        {
            bool[] allowEventBeanType = new bool[10];
            Type   declClass          = typeof(string);
            string methodName         = "trim";

            Type[] args = null;
            try
            {
                MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null);
                Assert.Fail();
            }
            catch (MethodResolverNoSuchMethodException)
            {
                // Expected
            }

            declClass  = typeof(Math);
            methodName = "moox";
            args       = new Type[] { typeof(int), typeof(int) };
            try
            {
                MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null);
                Assert.Fail();
            }
            catch (MethodResolverNoSuchMethodException)
            {
                // Expected
            }

            methodName = "max";
            args       = new Type[] { typeof(bool), typeof(bool) };
            try
            {
                MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null);
                Assert.Fail();
            }
            catch (MethodResolverNoSuchMethodException)
            {
                // Expected
            }

            methodName = "max";
            args       = new Type[] { typeof(int), typeof(int), typeof(bool) };
            try
            {
                MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null);
                Assert.Fail();
            }
            catch (MethodResolverNoSuchMethodException)
            {
                // Expected
            }
        }
コード例 #2
0
        public void TestResolveMethodStaticAndInstance()
        {
            bool[] allowEventBeanType = new bool[10];
            Type   declClass          = typeof(Math);
            string methodName         = "Max";

            Type[] args     = new Type[] { typeof(int), typeof(int) };
            var    expected = typeof(Math).GetMethod(methodName, args);

            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, true, null, null));

            declClass  = typeof(string);
            methodName = "Trim";
            args       = new Type[0];
            expected   = typeof(string).GetMethod(methodName, args);
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, true, null, null));
        }
コード例 #3
0
        public void TestResolveMethodStaticOnly()
        {
            Type   declClass  = typeof(Math);
            string methodName = "Max";

            Type[] args     = new Type[] { typeof(int), typeof(int) };
            var    expected = typeof(Math).GetMethod(methodName, args);

            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));

            args     = new Type[] { typeof(long), typeof(long) };
            expected = typeof(Math).GetMethod(methodName, args);
            args     = new Type[] { typeof(int), typeof(long) };
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));

            args     = new Type[] { typeof(int), typeof(int) };
            expected = typeof(Math).GetMethod(methodName, args);
            args     = new Type[] { typeof(int?), typeof(int?) };
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));

            args     = new Type[] { typeof(long), typeof(long) };
            expected = typeof(Math).GetMethod(methodName, args);
            args     = new Type[] { typeof(int?), typeof(long?) };
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));

            args     = new Type[] { typeof(float), typeof(float) };
            expected = typeof(Math).GetMethod(methodName, args);
            args     = new Type[] { typeof(int?), typeof(float?) };
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));

            declClass  = typeof(DateTimeHelper);
            methodName = "GetCurrentTimeMillis";
            args       = new Type[0];
            expected   = typeof(DateTimeHelper).GetMethod(methodName, args);
            Assert.AreEqual(expected, MethodResolver.ResolveMethod(declClass, methodName, args, false, null, null));
        }