In Part 1 we created a custom NUnit constraint but you where limited in using the constraint. You could only write:
// Instantiate the constraint.
Assert.That(expected, new EquivalentPropertyWiseToConstraint(actual));
// Matches syntax.
Assert.That(expected, Is.Not.Matches(new EquivalentPropertyWiseToConstraint(actual)));
It would be nice to write:
// Directly access the constraint from Is.
Assert.That(expected, Is.EquivalentPropertyWiseTo(actual));
// Chain the constraint in Is.
Assert.That(expected, Is.Not.EquivalentPropertyWiseTo(actual));
To do that you should read the documentation. End of blog post.
So is that joke still funny? No, OK, no more. Lets get back to what we are doing. To access the method using Is you need to override the Is class and add a static method. I recommended making the method name similar to your constraint name. For example:
[Read More]