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."); }
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."); }
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."); }
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."); }
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."); }
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."); }
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"); } }
public void AttributeSetterWithNonAttributeType() { AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut(); cut.Attribute = GetType(); }
public void AttributeSetterWithNullType() { AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut(); cut.Attribute = null; // must allow this (no Exception)... }
public void AttributeSetterWithASunnyDayAttributeType() { AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut(); cut.Attribute = typeof(SerializableAttribute); // must allow this too (no Exception)... }
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"); } }
public void AttributeSetterWithNonAttributeType() { AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut(); Assert.Throws <ArgumentException>(() => cut.Attribute = GetType()); }
public void AttributeSetterWithNonAttributeType() { AttributeMatchMethodPointcut cut = new AttributeMatchMethodPointcut(); Assert.Throws<ArgumentException>(() => cut.Attribute = GetType()); }