Exemple #1
0
        public void BindUriFunctionName_CanBindStaticAndInstanceOfDifferentDeclerationType()
        {
            const string FUNCTION_NAME              = "addtwice";
            MethodInfo   addTwiceStaticMethodInfo   = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceStatic", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo   addTwiceInstanceMethodInfo = typeof(UriFunctionBinderTests).GetMethod("AddStringTwiceInstance", BindingFlags.NonPublic | BindingFlags.Instance);

            try
            {
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addTwiceStaticMethodInfo);
                UriFunctionsBinder.BindUriFunctionName(FUNCTION_NAME, addTwiceInstanceMethodInfo);

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

                Assert.Equal(addTwiceStaticMethodInfo, resultMethoInfoStatic);

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

                Assert.Equal(addTwiceInstanceMethodInfo, resultMethoInfoInstance);
            }
            finally
            {
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addTwiceStaticMethodInfo));
                Assert.True(
                    UriFunctionsBinder.UnbindUriFunctionName(FUNCTION_NAME, addTwiceInstanceMethodInfo));
            }
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
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));
            }
        }
Exemple #5
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));
            }
        }
Exemple #6
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));
            }
        }