public void GetAttributeUsage_WithNoAttribute() { var attribute = AttributeUtility.GetAttributeUsage(typeof(object)); Assert.That(attribute, Is.Not.Null); Assert.That(attribute, Is.EqualTo(new AttributeUsageAttribute(AttributeTargets.All))); }
public void GetAttributeUsage_NeverNull() { var attribute = AttributeUtility.GetAttributeUsage(typeof(ImplicitUsageAttribute)); Assert.That(attribute, Is.Not.Null); Assert.That(attribute, Is.EqualTo(new AttributeUsageAttribute(AttributeTargets.All))); }
public void GetAttributeUsage_ReturnsCopy() { var multipleAttribute1 = AttributeUtility.GetAttributeUsage(typeof(MultipleAttribute)); var multipleAttribute2 = AttributeUtility.GetAttributeUsage(typeof(MultipleAttribute)); Assert.That(multipleAttribute2, Is.Not.SameAs(multipleAttribute1)); Assert.That(multipleAttribute1.AllowMultiple, Is.True); Assert.That(multipleAttribute1.ValidOn, Is.EqualTo(AttributeTargets.Assembly)); var notInheritedAttribute1 = AttributeUtility.GetAttributeUsage(typeof(NotInheritedAttribute)); var notInheritedAttribute2 = AttributeUtility.GetAttributeUsage(typeof(NotInheritedAttribute)); Assert.That(notInheritedAttribute2, Is.Not.SameAs(notInheritedAttribute1)); Assert.That(notInheritedAttribute1.Inherited, Is.False); Assert.That(notInheritedAttribute1.ValidOn, Is.EqualTo(AttributeTargets.Method)); }
private void AnalyzeMemberAttributeIntroductions(TargetClassDefinition classDefinition) { // Check that SuppressAttributesAttribute cannot be applied to methods, properties, and fields. // As long as this holds, we don't need to deal with potential suppressors here. const AttributeTargets memberTargets = AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field; Assertion.IsTrue((AttributeUtility.GetAttributeUsage(typeof(SuppressAttributesAttribute)).ValidOn & memberTargets) == 0, "TargetClassDefinitionBuilder must be updated with AddPotentialSuppressors once SuppressAttributesAttribute supports members"); foreach (MemberDefinitionBase member in classDefinition.GetAllMembers()) { if (member.Overrides.Count != 0) { var introductionBuilder = new AttributeIntroductionDefinitionBuilder(member); foreach (MemberDefinitionBase overrider in member.Overrides) { introductionBuilder.Apply(overrider); } } } }
public void GetAttributeUsage_ParameterIsNull_ThrowsArgumentNullException() { Assert.That( () => AttributeUtility.GetAttributeUsage(null), Throws.TypeOf <ArgumentNullException>().With.Message.EqualTo("Value cannot be null.\r\nParameter name: attributeType")); }
public void GetAttributeUsage() { var attribute = AttributeUtility.GetAttributeUsage(typeof(MultipleAttribute)); Assert.That(attribute, Is.EqualTo(typeof(MultipleAttribute).GetCustomAttributes(typeof(AttributeUsageAttribute), true)[0])); }