Understands() public static method

Checks, whether method may be invoked on target. Supports testing transparent proxies.
/// if is null /// /// if it is not possible to invoke on ///
public static Understands ( object target, string targetName, MethodBase method ) : void
target object the target instance or null
targetName string the name of the target to be used in error messages
method System.Reflection.MethodBase the method to test for
return void
        private void AssertNotUnderstandsMethod(object target, string targetName, MethodBase method, Type exceptionType, string partialMessage)
        {
            try
            {
                AssertUtils.Understands(target, targetName, method);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                if (ex.GetType() != exceptionType)
                {
                    Assert.Fail("Expected Exception of type {0}, but was {1}", exceptionType, ex.GetType());
                }

                if (-1 == ex.Message.IndexOf(partialMessage))
                {
                    Assert.Fail("Expected Message '{0}', but got '{1}'", partialMessage, ex.Message);
                }
            }
        }
        public void UnderstandsMethod()
        {
            MethodInfo getDescriptionMethod = typeof(ITestObject).GetMethod("GetDescription", new Type[0]);
            MethodInfo understandsMethod    = typeof(AssertUtils).GetMethod("Understands", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(object), typeof(string), typeof(MethodBase) }, null);

            // null target, static method
            AssertUtils.Understands(null, "target", understandsMethod);
            // null target, instance method
            AssertNotUnderstandsMethod(null, "target", getDescriptionMethod, typeof(NotSupportedException), "Target 'target' is null and target method 'Spring.Objects.ITestObject.GetDescription' is not static.");
            // compatible target, instance method
            AssertUtils.Understands(new TestObject(), "target", getDescriptionMethod);
            // incompatible target, instance method
            AssertNotUnderstandsMethod(new object(), "target", getDescriptionMethod, typeof(NotSupportedException), "Target 'target' of type 'System.Object' does not support methods of 'Spring.Objects.ITestObject'.");
            // compatible transparent proxy, instance method
            object compatibleProxy = new TestProxy(new TestObject()).GetTransparentProxy();

            AssertUtils.Understands(compatibleProxy, "compatibleProxy", getDescriptionMethod);
            // incompatible transparent proxy, instance method
            object incompatibleProxy = new TestProxy(new object()).GetTransparentProxy();

            AssertNotUnderstandsMethod(incompatibleProxy, "incompatibleProxy", getDescriptionMethod, typeof(NotSupportedException), "Target 'incompatibleProxy' is a transparent proxy that does not support methods of 'Spring.Objects.ITestObject'.");
        }