Legacy Documentation. View NUnit 3 Documentation

Property Constraints (NUnit 2.4.2)

Property constraints are used to test for the existence of a named property and optionally to test its value. It may also be used as a prefix for other constraints to be applied to the property.

PropertyExistsConstraint

Action

Tests for the existence of a named property on an object.

Constructor

PropertyExistsConstraint(string name)

Syntax

Has.Property( string )

Examples of Use

Assert.That( someObject, Has.Property( "Version" ) );

PropertyConstraint

Action

Tests for the existence of a named property on an object and causes subsequent allows tests to be made on the property value.

Constructor

PropertyConstraint(string name)

Syntax

Has.Property(string)...

Examples of Use

Assert.That(someObject, Has.Property("Version").EqualTo("2.0"));
Assert.That(collection, Has.Property("Count").GreaterThan(10));

Special Properties

Certain common properties are known to NUnit and may be tested using the following syntax...

Has.Length...
Has.Count...
Has.Message...
Has.InnerException...