Storyteller 4.1.0


Async Grammars


Creating Complex Objects

Verifying Object Properties Edit on GitHub

If you need to assert the values of several object properties in one logical step, the Fixture.VerifyPropertiesOf<T>() method is a helper to quickly put together a paragraph grammer to verify multiple properties.

Using the same Address type from the previous section (Creating Complex Objects), you could build a grammar like this one:

public IGrammar TheAddressShouldBe()
    return VerifyPropertiesOf<Address>("then the new address properties should be", x =>
        x.Check(o => o.Address1);
        x.Check(o => o.Address2);
        x.Check(o => o.City);

In usage, a specification using that grammar will render results like this below:

You can use multiple "dots" in the call to Check(expression) and even verify the result of a method with no arguments. So Check(o => o.Property1.Property2.Property3) or Check(o => o.IsActive()) are both valid. As of now, only properties and methods are supported. Support for fields will be added later.