Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Nov 29, 2023
1 parent 69ad890 commit 61a083d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/_pages/objectgraphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ orderDto.Should().BeEquivalentTo(order, options =>
.Exclude(o => o.Name));
```

You can also use an anonymous object to exclude members. This can be useful if you want to exclude multiple (maybe nested) fields and avoid writing
`Excluding().Excuding().Excluding()...`.

```csharp
orderDto.Should().BeEquivalentTo(order, options =>
options.Excluding(o => new { o.Customer.Name, o.Customer.LastName, o.Vat }));
```

This is also possible after `.For()` like

```csharp
orderDto.Should().BeEquivalentTo(order, options =>
options.For(o => o.Products)
.Exclude(o => new { o.Name, o.Price }));
```

Of course, `Excluding()` and `ExcludingMissingMembers()` can be combined.

You can also take a different approach and explicitly tell Fluent Assertions which members to include. You can directly specify a property expression or use a predicate that acts on the provided `ISubjectInfo`.
Expand Down Expand Up @@ -191,6 +207,8 @@ orderDto.Should().BeEquivalentTo(order, options => options

This configuration affects the initial inclusion of members and happens before any `Exclude`s or other `IMemberSelectionRule`s. This configuration also affects matching. For example, that if properties are excluded, properties will not be inspected when looking for a match on the expected object.

The behavior with anonymous objects for selection also applies to `Include` how it does to `Exclude`.

### Comparing members with different names

Imagine you want to compare an `Order` and an `OrderDto` using `BeEquivalentTo`, but the first type has a `Name` property and the second has a `OrderName` property. You can map those using the following option:
Expand Down

0 comments on commit 61a083d

Please sign in to comment.