2009-09-18

A NUnit Custom Constraint together with a String Extension Method

[Test]

public void WhenMyStringPropertyIsEmptyThenMyEntityMustBeInvalid()

{

var myEntity = new Entity { MyStringProperty = string.Empty };


Assert.That(myEntity, "MyStringProperty".IsIncludedInBrokenRules());

}


IsIncludedInBrokenRules() is an extension method that returns an instance of a class that inherits Constraint.

No comments:

Post a Comment