Search Results for

    Show / Hide Table of Contents

    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

    PropertyConstraint(string name, IConstraint baseConstraint)
    

    Syntax

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

    Examples of Use

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

    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:

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

    See also

    • PropertyExistsConstraint
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0