Back to Nunit

Attribute Constraint

docs/articles/nunit/writing-tests/constraints/AttributeConstraint.md

latest701 B
Original Source

Attribute Constraint

AttributeConstraint tests for the existence of an attribute on a Type and then applies a constraint to that attribute.

Constructor

csharp
AttributeConstraint(Type type, IConstraint baseConstraint)

Syntax

csharp
Has.Attribute(typeof(TestFixtureAttribute))...
Has.Attribute<TestFixtureAttribute>()...

Examples of Use

csharp
Assert.That(someObject, Has.Attribute(typeof(TestFixtureAttribute))
    .Property("Description").EqualTo("My description"));
Assert.That(someObject, Has.Attribute<TestFixtureAttribute>()
    .Property("Description").EqualTo("My description"));

See also