/
EnumerableEquivalencyValidatorExtensions.cs
44 lines (41 loc) · 1.79 KB
/
EnumerableEquivalencyValidatorExtensions.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
using System;
using System.Collections.Generic;
using FluentAssertions.Execution;
namespace FluentAssertions.Equivalency
{
internal static class EnumerableEquivalencyValidatorExtensions
{
public static Continuation AssertEitherCollectionIsNotEmpty<T>(this IAssertionScope scope, ICollection<object> subject, ICollection<T> expectation)
{
return scope
.ForCondition((subject.Count > 0) || (expectation.Count == 0))
.FailWith(", but found an empty collection.")
.Then
.ForCondition((subject.Count == 0) || (expectation.Count > 0))
.FailWith(", but {0}{2}contains {1} item(s).",
subject,
subject.Count,
Environment.NewLine);
}
public static Continuation AssertCollectionHasEnoughItems<T>(this IAssertionScope scope, ICollection<object> subject, ICollection<T> expectation)
{
return scope
.ForCondition(subject.Count >= expectation.Count)
.FailWith(", but {0}{3}contains {1} item(s) less than{3}{2}.",
subject,
expectation.Count - subject.Count,
expectation,
Environment.NewLine);
}
public static Continuation AssertCollectionHasNotTooManyItems<T>(this IAssertionScope scope, ICollection<object> subject, ICollection<T> expectation)
{
return scope
.ForCondition(subject.Count <= expectation.Count)
.FailWith(", but {0}{3}contains {1} item(s) more than{3}{2}.",
subject,
subject.Count - expectation.Count,
expectation,
Environment.NewLine);
}
}
}