Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        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 'Oragon.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 'Oragon.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 'Oragon.Spring.Objects.ITestObject'.");
        }