/
EquivalencyAssertionOptions.cs
102 lines (89 loc) · 3.58 KB
/
EquivalencyAssertionOptions.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#region
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using FluentAssertions.Common;
using FluentAssertions.Equivalency.Ordering;
using FluentAssertions.Equivalency.Selection;
#endregion
namespace FluentAssertions.Equivalency
{
// REFACTOR rename to EquivalencyOptions
/// <summary>
/// Represents the run-time type-specific behavior of a structural equivalency assertion.
/// </summary>
public class EquivalencyAssertionOptions<TExpectation> :
SelfReferenceEquivalencyAssertionOptions<EquivalencyAssertionOptions<TExpectation>>
{
public EquivalencyAssertionOptions()
{
}
internal EquivalencyAssertionOptions(IEquivalencyAssertionOptions defaults)
: base(defaults)
{
}
/// <summary>
/// Excludes the specified (nested) member from the structural equality check.
/// </summary>
public EquivalencyAssertionOptions<TExpectation> Excluding(Expression<Func<TExpectation, object>> expression)
{
AddSelectionRule(new ExcludeMemberByPathSelectionRule(expression.GetMemberPath()));
return this;
}
/// <summary>
/// Includes the specified member in the equality check.
/// </summary>
/// <remarks>
/// This overrides the default behavior of including all declared members.
/// </remarks>
public EquivalencyAssertionOptions<TExpectation> Including(Expression<Func<TExpectation, object>> expression)
{
AddSelectionRule(new IncludeMemberByPathSelectionRule(expression.GetMemberPath()));
return this;
}
/// <summary>
/// Includes the specified member in the equality check.
/// </summary>
/// <remarks>
/// This overrides the default behavior of including all declared members.
/// </remarks>
public EquivalencyAssertionOptions<TExpectation> Including(Expression<Func<IMemberInfo, bool>> predicate)
{
AddSelectionRule(new IncludeMemberByPredicateSelectionRule(predicate));
return this;
}
/// <summary>
/// Causes the collection identified by <paramref name="expression"/> to be compared in the order
/// in which the items appear in the expectation.
/// </summary>
public EquivalencyAssertionOptions<TExpectation> WithStrictOrderingFor(
Expression<Func<TExpectation, object>> expression)
{
string expressionMemberPath = expression.GetMemberPath().ToString();
orderingRules.Add(new PathBasedOrderingRule(expressionMemberPath));
return this;
}
/// <summary>
/// Creates a new set of options based on the current instance which acts on a <see cref="IEnumerable{TSubject}"/>
/// </summary>
/// <returns></returns>
public EquivalencyAssertionOptions<IEnumerable<TExpectation>> AsCollection()
{
return new EquivalencyAssertionOptions<IEnumerable<TExpectation>>(
new CollectionMemberAssertionOptionsDecorator(this));
}
}
/// <summary>
/// Represents the run-time type-agnostic behavior of a structural equivalency assertion.
/// </summary>
public class EquivalencyAssertionOptions : SelfReferenceEquivalencyAssertionOptions<EquivalencyAssertionOptions>
{
public EquivalencyAssertionOptions()
{
IncludingNestedObjects();
IncludingFields();
IncludingProperties();
RespectingDeclaredTypes();
}
}
}