Skip to content
Cyrille DUPUYDAUBY edited this page Feb 21, 2018 · 5 revisions

NFluent allows to perform checks using specific fields/properties from the sut. It simplifies several testing scenarii such as DTO testing. Or typeless TDD.

Considering

Considering() allows you to specify which members should be evaluated/considered for the check. It will be followed by one or more member selectors.

Check.That(sut).Considering()...

Visibility selector

Those keywords can be used to specify the desired members' visibility. If not specified, Considering() assumes Public visibility.

Public

Specifies you are interested in public members. In C#, a member is considered public if it is declared as: public, protected or internal.

Check.That(sut).Considering().Public....

NonPublic

Specifies you are interested in non public members. In C#, a member is considered nonpublic if it is declared as: private.

Check.That(sut).Considering().NonPublic...

All

Specifies you are interested in all public members, public or not.

Check.That(sut).Considering().All...

Members kind

Fields

Specifies you are interested in fields.

// specify you want to consider only public fields in the comparison
Check.That(sut).Considering().Fields.IsEqualTo(...);
// verbose syntax
Check.That(sut).Considering().Public.Fields.IsEqualTo(...);

Properties

Specifies you are interested in properties.

// specify you want to consider only public properties in the comparison
Check.That(sut).Considering().Properties.IsEqualTo(...);
// verbose syntax
Check.That(sut).Considering().Public.Properties.IsEqualTo(...);

Other

And

Allows to chain selection criteria.

// specify you want to consider both public properties and fields in the comparison
Check.That(sut).Considering().Properties.And.Fields.IsEqualTo(...);
// complex selection
Check.That(sut).Considering().Public.Fields.And.Private.Properties.IsEqualTo(...);

Excluding

Allows to give the name of members that must be excluded from the checks. You can use dotted name to list sub members.

// specify you do not want some fields
Check.That(sut).Considering().Fields.Excluding("someField", "member.someOtherField").IsEqualTo(...);
Clone this wiki locally