Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for
OccurrenceConstraint
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
Tests/FluentAssertions.Specs/OccurrenceConstraintSpecs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using FluentAssertions.Execution; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace FluentAssertions.Specs | ||
{ | ||
public class OccurrenceConstraintSpecs | ||
{ | ||
public static object[][] PassingConstraints() => new object[][] | ||
{ | ||
new object[] { AtLeast.Once(), 1 }, | ||
new object[] { AtLeast.Once(), 2 }, | ||
new object[] { AtLeast.Twice(), 2 }, | ||
new object[] { AtLeast.Twice(), 3 }, | ||
new object[] { AtLeast.Thrice(), 3 }, | ||
new object[] { AtLeast.Thrice(), 4 }, | ||
new object[] { AtLeast.Times(4), 4 }, | ||
new object[] { AtLeast.Times(4), 5 }, | ||
|
||
new object[] { AtMost.Once(), 0 }, | ||
new object[] { AtMost.Once(), 1 }, | ||
new object[] { AtMost.Twice(), 1 }, | ||
new object[] { AtMost.Twice(), 2 }, | ||
new object[] { AtMost.Thrice(), 2 }, | ||
new object[] { AtMost.Thrice(), 3 }, | ||
new object[] { AtMost.Times(4), 3 }, | ||
new object[] { AtMost.Times(4), 4 }, | ||
|
||
new object[] { Exactly.Once(), 1 }, | ||
new object[] { Exactly.Twice(), 2 }, | ||
new object[] { Exactly.Thrice(), 3 }, | ||
new object[] { Exactly.Times(4), 4 }, | ||
|
||
new object[] { LessThan.Twice(), 1 }, | ||
new object[] { LessThan.Thrice(), 2 }, | ||
new object[] { LessThan.Times(4), 3 }, | ||
|
||
new object[] { MoreThan.Once(), 2 }, | ||
new object[] { MoreThan.Twice(), 3 }, | ||
new object[] { MoreThan.Thrice(), 4 }, | ||
new object[] { MoreThan.Times(4), 5 }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(PassingConstraints))] | ||
public void Occurrence_constraint_passes(OccurrenceConstraint constraint, int occurrences) | ||
{ | ||
// Act / Assert | ||
Execute.Assertion | ||
.ForConstraint(constraint, occurrences) | ||
.FailWith(""); | ||
} | ||
|
||
public static object[][] FailingConstraints() => new object[][] | ||
{ | ||
new object[] { AtLeast.Once(), 0 }, | ||
new object[] { AtLeast.Twice(), 1 }, | ||
new object[] { AtLeast.Thrice(), 2 }, | ||
new object[] { AtLeast.Times(4), 3 }, | ||
|
||
new object[] { AtMost.Once(), 2 }, | ||
new object[] { AtMost.Twice(), 3 }, | ||
new object[] { AtMost.Thrice(), 4 }, | ||
new object[] { AtMost.Times(4), 5 }, | ||
|
||
new object[] { Exactly.Once(), 0 }, | ||
new object[] { Exactly.Once(), 2 }, | ||
new object[] { Exactly.Twice(), 1 }, | ||
new object[] { Exactly.Twice(), 3 }, | ||
new object[] { Exactly.Thrice(), 2 }, | ||
new object[] { Exactly.Thrice(), 4 }, | ||
new object[] { Exactly.Times(4), 3 }, | ||
new object[] { Exactly.Times(4), 5 }, | ||
|
||
new object[] { LessThan.Twice(), 2 }, | ||
new object[] { LessThan.Twice(), 3 }, | ||
new object[] { LessThan.Thrice(), 3 }, | ||
new object[] { LessThan.Thrice(), 4 }, | ||
new object[] { LessThan.Times(4), 4 }, | ||
new object[] { LessThan.Times(4), 5 }, | ||
|
||
new object[] { MoreThan.Once(), 0 }, | ||
new object[] { MoreThan.Once(), 1 }, | ||
new object[] { MoreThan.Twice(), 1 }, | ||
new object[] { MoreThan.Twice(), 2 }, | ||
new object[] { MoreThan.Thrice(), 2 }, | ||
new object[] { MoreThan.Thrice(), 3 }, | ||
new object[] { MoreThan.Times(4), 3 }, | ||
new object[] { MoreThan.Times(4), 4 }, | ||
}; | ||
|
||
[Theory] | ||
[MemberData(nameof(FailingConstraints))] | ||
public void Occurrence_constraint_fails(OccurrenceConstraint constraint, int occurrences) | ||
{ | ||
// Act | ||
Action act = () => Execute.Assertion | ||
.ForConstraint(constraint, occurrences) | ||
.FailWith($"Expected occurrence to be {constraint.Mode} {constraint.ExpectedCount}, but it was {occurrences}"); | ||
|
||
// Assert | ||
act.Should().Throw<XunitException>() | ||
.WithMessage("Expected occurrence to be *, but it was *"); | ||
} | ||
} | ||
} |