예제 #1
0
        public void UnbindUriFunctionName_FunctionNameStringEmpty()
        {
            MethodInfo padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            Action bindUriFunction = () =>
                                     UriFunctionsBinder.UnbindUriFunctionName(string.Empty, padRightStringMethodInfo);

            ExceptionAssert.ThrowsArgumentNull(bindUriFunction, "functionName");
        }
예제 #2
0
        public void UnbindUriFunctionName_CanUnbindExtensionStaticMethod()
        {
            const string FUNCTION_NAME = "addtwice";
            MethodInfo   addStrTwiceStaticExtensionMethodInfo =
                typeof(UriFunctionClrBinderTestsStaticExtensionMethods).GetMethod("AddStringTwice", BindingFlags.NonPublic | BindingFlags.Static);

            UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticExtensionMethodInfo);

            Assert.True(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticExtensionMethodInfo));

            MethodInfo resultMethoInfo;

            Assert.False(UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(string) }, out resultMethoInfo));

            Assert.Null(resultMethoInfo);
        }
예제 #3
0
        public void UnbindUriFunctionName_CanUnbindInstanceMethod()
        {
            const string FUNCTION_NAME            = "padright";
            MethodInfo   padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);

            Assert.True(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo));


            MethodInfo resultMethoInfo;

            Assert.False(UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(int) }, out resultMethoInfo));

            Assert.Null(resultMethoInfo);
        }
예제 #4
0
        public void UnbindUriFunctionName_CannotUnbindNotBindedFunction_DifferentFunctionName()
        {
            const string FUNCTION_NAME            = "padright";
            MethodInfo   padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);

                Assert.False(UriFunctionsBinder.UnbindUriFunctionName("AnotherFunctionName", padRightStringMethodInfo));
            }
            finally
            {
                Assert.True(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo));
            }
        }
예제 #5
0
        public void UnbindUriFunctionName_CannotUnbindWithDifferentMethod()
        {
            const string FUNCTION_NAME            = "padright";
            MethodInfo   padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);

                MethodInfo addStrTwiceStaticMethodInfo = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceStatic", BindingFlags.NonPublic | BindingFlags.Static);

                Assert.False(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo));
            }
            finally
            {
                UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);
            }
        }
예제 #6
0
        public void UnbindUriFunctionName_CannotUnbindNotBindedFunction_DifferentMethodInfo()
        {
            const string FUNCTION_NAME            = "padright";
            MethodInfo   padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);

                MethodInfo differentMethodInfo = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceInstance", BindingFlags.NonPublic | BindingFlags.Instance);

                Assert.False(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, differentMethodInfo));
            }
            finally
            {
                Assert.True(UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo));
            }
        }
예제 #7
0
        public void BindUriFunctionName_CanBindStaticMethod()
        {
            const string FUNCTION_NAME = "addtwice";
            MethodInfo   addStrTwiceStaticMethodInfo = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceStatic", BindingFlags.NonPublic | BindingFlags.Static);

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo);
                MethodInfo resultMethoInfo;
                UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(string) }, out resultMethoInfo);
                Assert.Equal(addStrTwiceStaticMethodInfo, resultMethoInfo);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo));
            }
        }
예제 #8
0
        public void BindUriFunctionName_CannotBindStaticAndInstanceMethodWithSameArguments()
        {
            const string FUNCTION_NAME              = "padright";
            MethodInfo   padRightStaticMethodInfo   = typeof(UriFunctionBinderTests).GetMethod("PadRightStatic", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo   padRightInstanceMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStaticMethodInfo);
                Action bindingInstance = () => UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightInstanceMethodInfo);

                ExceptionAssert.Throws <ODataException>(bindingInstance);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStaticMethodInfo));
            }
        }
예제 #9
0
        public void BindUriFunctionName_CanBind()
        {
            const string FUNCTION_NAME            = "padright";
            MethodInfo   padRightStringMethodInfo = typeof(string).GetMethod("PadRight", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo);

                MethodInfo resultMethoInfo;
                UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(int) }, out resultMethoInfo);

                Assert.Equal(padRightStringMethodInfo, resultMethoInfo);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightStringMethodInfo));
            }
        }
예제 #10
0
        public void BindUriFunctionName_CannotBindIfAlreadyBinded()
        {
            const string FUNCTION_NAME = "addtwice";
            MethodInfo   addStrTwiceStaticMethodInfo = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceStatic", BindingFlags.NonPublic | BindingFlags.Static);

            try
            {
                // Add for the first time
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo);

                // Add for the second time
                Action bindExisting = () => UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo);

                ExceptionAssert.Throws <ODataException>(bindExisting);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addStrTwiceStaticMethodInfo));
            }
        }
예제 #11
0
        public void BindUriFunctionName_CannotBindInstanceMethodOfDifferentDeclaringType()
        {
            const string FUNCTION_NAME = "addtwice";
            MethodInfo   addTwiceInstanceThisDelcaringTypeMethodInfo =
                typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceInstance", BindingFlags.NonPublic | BindingFlags.Instance);

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addTwiceInstanceThisDelcaringTypeMethodInfo);

                MethodInfo resultMethoInfo;
                bool       couldFindBinding =
                    UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(string) }, out resultMethoInfo);

                Assert.False(couldFindBinding);
                Assert.Null(resultMethoInfo);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addTwiceInstanceThisDelcaringTypeMethodInfo));
            }
        }
예제 #12
0
        public void BindUriFunctionName_CanBindInstanceMethod()
        {
            // this test originally used "padright" as case, it has a running conflict with 'CustomMethod_InstanceMethodOfDeclaringType' in 'FilterBinderTests"
            // Therefore, let's change it to use "PadLeft" as case.
            // TODO: need to refactor the static logic for UriFunctionsBinder.
            const string FUNCTION_NAME = "padLeft";
            MethodInfo   padRightInstanceMethodInfo = typeof(string).GetMethod("PadLeft", new Type[] { typeof(int) });

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, padRightInstanceMethodInfo);

                MethodInfo resultMethoInfo;
                UriFunctionsBinder.TryGetMethodInfo(FUNCTION_NAME, new Type[] { typeof(string), typeof(int) }, out resultMethoInfo);

                Assert.Equal(padRightInstanceMethodInfo, resultMethoInfo);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, padRightInstanceMethodInfo));
            }
        }