forked from fluentassertions/fluentassertions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NestedExclusionOptionBuilder.cs
46 lines (41 loc) · 1.9 KB
/
NestedExclusionOptionBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FluentAssertions.Common;
using FluentAssertions.Equivalency.Selection;
namespace FluentAssertions.Equivalency
{
public class NestedExclusionOptionBuilder<TExpectation, TCurrent>
{
/// <summary>
/// The selected path starting at the first <see cref="EquivalencyAssertionOptions{TExpectation}.For{TNext}"/>.
/// </summary>
private readonly ExcludeMemberByPathSelectionRule currentPathSelectionRule;
private readonly EquivalencyAssertionOptions<TExpectation> capturedAssertionOptions;
internal NestedExclusionOptionBuilder(EquivalencyAssertionOptions<TExpectation> capturedAssertionOptions,
ExcludeMemberByPathSelectionRule currentPathSelectionRule)
{
this.capturedAssertionOptions = capturedAssertionOptions;
this.currentPathSelectionRule = currentPathSelectionRule;
}
/// <summary>
/// Selects a nested property to exclude. This ends the <see cref="For{TNext}"/> chain.
/// </summary>
public EquivalencyAssertionOptions<TExpectation> Exclude(Expression<Func<TCurrent, object>> expression)
{
var nextPath = expression.GetMemberPath();
currentPathSelectionRule.AppendPath(nextPath);
return capturedAssertionOptions;
}
/// <summary>
/// Adds the selected collection to the <see cref="For{TNext}"/> chain.
/// </summary>
public NestedExclusionOptionBuilder<TExpectation, TNext> For<TNext>(
Expression<Func<TCurrent, IEnumerable<TNext>>> expression)
{
var nextPath = expression.GetMemberPath();
currentPathSelectionRule.AppendPath(nextPath);
return new NestedExclusionOptionBuilder<TExpectation, TNext>(capturedAssertionOptions, currentPathSelectionRule);
}
}
}