示例#1
0
        public void MatchesWithAMethodThatDontMatchTheAttributeTypeAndNoInheritance()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute = typeof(MarkupAttribute);
            bool matches = cut.Matches(typeof(WithMarkup).GetMethod("RiloKiley"), null);

            Assert.IsFalse(matches, "Method was not decorated with the target attribute, so this must not match.");
        }
示例#2
0
        public void MatchesWithASunnyDayAttributeTypeAndInheritance()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute = typeof(MarkupAttribute);
            bool matches = cut.Matches(typeof(InheritedWithMarkup).GetMethod("Bing"), null);

            Assert.IsTrue(matches, "Inherited method was decorated with the target attribute, so this must match.");
        }
示例#3
0
        public void MatchesWithAnInterfaceMethodThatMatchesTheAttributeTypeAndNoCheckInterfaces()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute       = typeof(MarkupAttribute);
            cut.CheckInterfaces = false;
            bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("OtherTestMethod"), null);

            Assert.IsFalse(matches, "Implementing method was not decorated with the target attribute, so this must not match since CheckInterfaces is false.");
        }
示例#4
0
        public void MatchesWithAnIndirectInterfaceMethodFromSubclassThatMatchesTheAttributeTypeAndCheckInterfaces()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute       = typeof(MarkupAttribute);
            cut.CheckInterfaces = true;
            bool matches = cut.Matches(typeof(InheritedImplementingClass).GetMethod("TestMethod", new Type[] { }), null);

            Assert.IsTrue(matches, "Implementing method from subclass was not decorated with the target attribute " +
                          "but the method from an indirectly implemented interface was, so this must match.");
        }
示例#5
0
        public void MatchesWithAnOverloadedInterfaceMethod()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute       = typeof(MarkupAttribute);
            cut.CheckInterfaces = true;
            bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("TestMethod", new Type[] { typeof(string) }), null);

            Assert.IsFalse(matches, "Overloaded method from an implemented interface is not decorated with" +
                           " the attribute, so should not match.");
        }
示例#6
0
        public void MatchesWithAnInterfaceMethodThatMatchesTheAttributeTypeAndCheckInterfaces()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute       = typeof(MarkupAttribute);
            cut.CheckInterfaces = true;
            bool matches = cut.Matches(typeof(ImplementingClass).GetMethod("OtherTestMethod"), null);

            Assert.IsTrue(matches, "Implementing method was not decorated with the target attribute, " +
                          "but the method from the interface was, so this must match.");
        }
示例#7
0
        public void MatchesWhenExplicitlyImplemed()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute       = typeof(MarkupAttribute);
            cut.CheckInterfaces = true;

            // Only methods implemented expicitly are marked with attribute
            foreach (MethodInfo mi in typeof(ExplicitlyImplementingClass).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic))
            {
                if (mi.Name.IndexOf('.') == -1)
                {
                    continue;
                }
                bool matches = cut.Matches(mi, null);
                Assert.IsTrue(matches, "Explicitly implemented method must match");
            }
        }
示例#8
0
        public void AttributeSetterWithASunnyDayAttributeType()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute = typeof(SerializableAttribute);             // must allow this too (no Exception)...
        }
示例#9
0
        public void AttributeSetterWithNullType()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            cut.Attribute = null;             // must allow this (no Exception)...
        }
示例#10
0
        public void AttributeSetterWithNonAttributeType()
        {
            AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut();

            Assert.Throws <ArgumentException>(() => cut.Attribute = GetType());
        }