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"); }
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); }
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); }
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)); } }
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); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }
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)); } }