Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipeline/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ partial class Build : NukeBuild
/// <para />
/// Afterward, you can update the package reference in `Directory.Packages.props` and reset this flag.
/// </summary>
readonly BuildScope BuildScope = BuildScope.Default;
readonly BuildScope BuildScope = BuildScope.CoreOnly;

[Parameter("Github Token")] readonly string GithubToken;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public bool VerifyComplete(string it, IOptionsEquality<T2> options, int maximumN
}

List<string> errors = new();
errors.AddRange(IncorrectItemsError(_incorrectItems, _expectedItems, _equivalenceRelations));
errors.AddRange(IncorrectItemsError(_incorrectItems));
if (!_equivalenceRelations.HasFlag(EquivalenceRelations.Contains))
{
errors.AddRange(AdditionalItemsError(_additionalItems));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public bool VerifyComplete(string it, IOptionsEquality<T2> options, int maximumN
}

List<string> errors = new();
errors.AddRange(IncorrectItemsError(_incorrectItems, _expectedDistinctItems, _equivalenceRelations));
errors.AddRange(IncorrectItemsError(_incorrectItems));
if (!_equivalenceRelations.HasFlag(EquivalenceRelations.Contains))
{
errors.AddRange(AdditionalItemsError(_additionalItems));
Expand Down
10 changes: 1 addition & 9 deletions Source/aweXpect.Core/Options/CollectionMatchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,13 @@ private static IEnumerable<string> AdditionalItemsError<T>(Dictionary<int, T> ad
}
}

private static IEnumerable<string> IncorrectItemsError<T>(Dictionary<int, (T Item, T Expected)> incorrectItems,
T[] expectedItems,
EquivalenceRelations equivalenceRelation)
private static IEnumerable<string> IncorrectItemsError<T>(Dictionary<int, (T Item, T Expected)> incorrectItems)
{
bool hasIncorrectItems = incorrectItems.Any();
if (hasIncorrectItems)
{
foreach (KeyValuePair<int, (T Item, T Expected)> incorrectItem in incorrectItems)
{
if (equivalenceRelation.HasFlag(EquivalenceRelations.Contains) &&
!expectedItems.Contains(incorrectItem.Value.Item))
{
continue;
}

yield return
$"contained item {Formatter.Format(incorrectItem.Value.Item)} at index {incorrectItem.Key} instead of {Formatter.Format(incorrectItem.Value.Expected)}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -669,11 +672,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -1922,12 +1928,14 @@ await That(Act).Throws<XunitException>()
Expected that subject
contains collection expected and at least one additional item in order,
but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
did not contain any additional items and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -2433,11 +2441,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected and at least one additional item in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -670,11 +673,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -1924,12 +1930,14 @@ await That(Act).Throws<XunitException>()
Expected that subject
contains collection expected and at least one additional item in order,
but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
did not contain any additional items and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -2436,11 +2444,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected and at least one additional item in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -671,11 +674,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -1925,12 +1931,14 @@ await That(Act).Throws<XunitException>()
Expected that subject
contains collection expected and at least one additional item in order,
but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
did not contain any additional items and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -2437,11 +2445,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected and at least one additional item in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,31 @@ Expected that subject
""");
}


[Fact]
public async Task WhenExpectedContainsDuplicateButMissingItems_ShouldFail()
{
int[] collection = [1, 2, 1, 3, 12, 2, 2,];

async Task Act()
=> await That(collection).Contains([1, 2, 1, 1, 2,]);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that collection
contains collection [1, 2, 1, 1, 2,] in order,
but it
contained item 3 at index 3 instead of 1 and
contained item 12 at index 4 instead of 2

Collection:
[1, 2, 1, 3, 12, 2, 2]

Expected:
[1, 2, 1, 1, 2]
""");
Comment thread
vbreuss marked this conversation as resolved.
}

[Fact]
public async Task WhenExpectedIsNull_ShouldFail()
{
Expand Down Expand Up @@ -189,11 +214,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -669,11 +697,14 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"

but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
"a",
Expand Down Expand Up @@ -1923,6 +1954,8 @@ await That(Act).Throws<XunitException>()
Expected that subject
contains collection expected and at least one additional item in order,
but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
did not contain any additional items and
lacked 3 of 6 expected items:
"x",
Expand Down Expand Up @@ -2435,10 +2468,13 @@ await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
contains collection expected and at least one additional item in order ignoring duplicates,
but it lacked 3 of 6 expected items:
"x",
"y",
"z"
but it
contained item "d" at index 3 instead of "x" and
contained item "e" at index 4 instead of "y" and
lacked 3 of 6 expected items:
"x",
"y",
"z"

Collection:
[
Expand Down