Back to Nunit

Property Constraint

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

latest787 B
Original Source

Property Constraint

PropertyConstraint tests for the existence of a named property on an object and then applies a constraint test to the property value.

Constructor

csharp
PropertyConstraint(string name, IConstraint baseConstraint)

Syntax

csharp
Has.Property(string name)... // followed by further constraint syntax

Examples of Use

[!code-csharpPropertyConstraintExamples]

As shown in the example, certain common properties are known to NUnit and may be tested using a shorter form. The following properties are supported:

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

See also