コード例 #1
0
        public void ShouldFindAttributesInInterfaceAndClass()
        {
            CustomInterceptor interceptor = new CustomInterceptor();
            MethodInfo        method      = typeof(IInterfaceWithAttribute).GetMethod("DoSomething");
            IInvocation       invocation  = Substitute.For <IInvocation>();

            invocation.Request.Method.Returns(method);
            AttributeInheritedAndReproduced instance = new AttributeInheritedAndReproduced();

            invocation.Request.Target.Returns(instance);
            CustomAttribute[] attributes = interceptor.GetAllAttributes(invocation);

            Assert.AreEqual(2, attributes.Length, "The wrong number of attributes were found.");
        }
コード例 #2
0
        public void ShouldFindAttributeOnAbstractClass()
        {
            CustomInterceptor interceptor = new CustomInterceptor();
            MethodInfo        method      = typeof(AbstractClassWithAttribute).GetMethod("DoSomething");
            IInvocation       invocation  = Substitute.For <IInvocation>();

            invocation.Request.Method.Returns(method);
            ImplementsAbstractClass instance = new ImplementsAbstractClass();

            invocation.Request.Target.Returns(instance);
            CustomAttribute[] attributes = interceptor.GetAllAttributes(invocation);

            Assert.AreEqual(1, attributes.Length, "The wrong number of attributes were found.");
        }