コード例 #1
0
        public void IsInstanceOfType_False()
        {
            AttributeWithMetadata attribute = new AttributeWithMetadata(typeof(BaseClassWithAttribute), new DerivedNonInheritedAttribute("X"));

            Assert.That(attribute.IsInstanceOfType(typeof(BaseInheritedAttribute)), Is.False);
            Assert.That(attribute.IsInstanceOfType(typeof(ICustomAttribute)), Is.False);
        }
コード例 #2
0
        public void Suppress_DoesSuppressDerivedAttribute_OnDifferentType()
        {
            AttributeWithMetadata[] attributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new DerivedInheritedAttribute("X")),
            };
            AttributeWithMetadata[] suppressAttributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(string), new SuppressAttributesAttribute(typeof(BaseInheritedAttribute))),
            };
            AttributeWithMetadata[] expectedAttributes = new AttributeWithMetadata[] {
            };

            AttributeWithMetadata[] filteredAttributes = AttributeWithMetadata.Suppress(attributes, suppressAttributes).ToArray();
            Assert.That(filteredAttributes, Is.EqualTo(expectedAttributes));
        }
コード例 #3
0
        public void Suppress_DoesNotSuppressAnythingOnSameType()
        {
            AttributeWithMetadata[] attributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new BaseInheritedAttribute("X")),
            };
            AttributeWithMetadata[] suppressAttributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new SuppressAttributesAttribute(typeof(BaseInheritedAttribute))),
            };
            AttributeWithMetadata[] expectedAttributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new BaseInheritedAttribute("X")),
            };

            AttributeWithMetadata[] filteredAttributes = AttributeWithMetadata.Suppress(attributes, suppressAttributes).ToArray();
            Assert.That(filteredAttributes, Is.EqualTo(expectedAttributes));
        }
コード例 #4
0
        public void ExcludeAll()
        {
            AttributeWithMetadata[] attributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new BaseInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new BaseNonInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new DerivedInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new DerivedNonInheritedAttribute("X")),
            };
            AttributeWithMetadata[] expectedAttributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new BaseNonInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new DerivedNonInheritedAttribute("X")),
            };

            AttributeWithMetadata[] filteredAttributes = AttributeWithMetadata.ExcludeAll(attributes, typeof(ICustomAttribute)).ToArray();
            Assert.That(filteredAttributes, Is.EqualTo(expectedAttributes));
        }
コード例 #5
0
        public void ExtractInstances()
        {
            AttributeWithMetadata[] attributes = new AttributeWithMetadata[] {
                new AttributeWithMetadata(typeof(object), new BaseInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new BaseNonInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new DerivedInheritedAttribute("X")),
                new AttributeWithMetadata(typeof(object), new DerivedNonInheritedAttribute("X")),
            };
            object[] expectedInstances = new object[]
            {
                attributes[0].AttributeInstance,
                attributes[1].AttributeInstance,
                attributes[2].AttributeInstance,
                attributes[3].AttributeInstance,
            };

            object[] instances = AttributeWithMetadata.ExtractInstances(attributes).ToArray();
            Assert.That(instances, Is.EqualTo(expectedInstances));
        }