Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions Docs/pages/docs/expectations/07-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ You can verify that the collection contains an item that satisfies the expectati
IEnumerable<string> values = ["0th item", "1st item", "2nd item", "3rd item"];

await Expect.That(values).HasItem("1st item").AtIndex(1);
await Expect.That(values).HasItem(it => it.StartsWith("2nd")).AtAnyIndex();
await Expect.That(values).HasItem(it => it.StartsWith("2nd")); // at any index
```

You can also use expectations on the individual items.
Expand All @@ -505,7 +505,7 @@ You can also use expectations on the individual items.
IEnumerable<string> values = ["0th item", "1st item", "2nd item", "3rd item"];

await Expect.That(values).HasItemThat(it => it.IsEqualTo("1st item")).AtIndex(1);
await Expect.That(values).HasItemThat(it => it.StartsWith("2nd").And.EndsWith("item")).AtAnyIndex();
await Expect.That(values).HasItemThat(it => it.StartsWith("2nd").And.EndsWith("item")); // at any index
```

*Note: The same expectation works also for `IAsyncEnumerable<T>`.*
Expand Down
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;
Comment thread
vbreuss marked this conversation as resolved.

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

Expand Down
12 changes: 2 additions & 10 deletions Source/aweXpect.Core/Results/HasItemResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@ public class HasItemResult<TCollection>(
ExpectationBuilder expectationBuilder,
IThat<TCollection> collection,
CollectionIndexOptions collectionIndexOptions)
: AndOrResult<TCollection, IThat<TCollection>>(expectationBuilder, collection)
{
/// <summary>
/// …at any index.
/// </summary>
public AndOrResult<TCollection, IThat<TCollection>> AtAnyIndex()
{
collectionIndexOptions.SetIndexRange(null, null);
return new AndOrResult<TCollection, IThat<TCollection>>(expectationBuilder, collection);
}

/// <summary>
/// …at the given <paramref name="index" />.
/// </summary>
public AndOrResult<TCollection, IThat<TCollection>> AtIndex(int index)
{
collectionIndexOptions.SetIndexRange(index, index);
return new AndOrResult<TCollection, IThat<TCollection>>(expectationBuilder, collection);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1087,10 +1087,9 @@ namespace aweXpect.Results
public TSelf WithCancellation(System.Threading.CancellationToken cancellationToken) { }
public TSelf WithTimeout(System.TimeSpan timeout) { }
}
public class HasItemResult<TCollection>
public class HasItemResult<TCollection> : aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>>
{
public HasItemResult(aweXpect.Core.ExpectationBuilder expectationBuilder, aweXpect.Core.IThat<TCollection> collection, aweXpect.Options.CollectionIndexOptions collectionIndexOptions) { }
public aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>> AtAnyIndex() { }
public aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>> AtIndex(int index) { }
}
public class NullableNumberToleranceResult<TType, TThat> : aweXpect.Results.NullableNumberToleranceResult<TType, TThat, aweXpect.Results.NullableNumberToleranceResult<TType, TThat>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,9 @@ namespace aweXpect.Results
public TSelf WithCancellation(System.Threading.CancellationToken cancellationToken) { }
public TSelf WithTimeout(System.TimeSpan timeout) { }
}
public class HasItemResult<TCollection>
public class HasItemResult<TCollection> : aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>>
{
public HasItemResult(aweXpect.Core.ExpectationBuilder expectationBuilder, aweXpect.Core.IThat<TCollection> collection, aweXpect.Options.CollectionIndexOptions collectionIndexOptions) { }
public aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>> AtAnyIndex() { }
public aweXpect.Results.AndOrResult<TCollection, aweXpect.Core.IThat<TCollection>> AtIndex(int index) { }
}
public class NullableNumberToleranceResult<TType, TThat> : aweXpect.Results.NullableNumberToleranceResult<TType, TThat, aweXpect.Results.NullableNumberToleranceResult<TType, TThat>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task DoesNotEnumerateTwice()
ThrowWhenIteratingTwiceAsyncEnumerable subject = new();

async Task Act()
=> await That(subject).HasItem(_ => true).AtAnyIndex()
=> await That(subject).HasItem(_ => true)
.And.HasItem(_ => true).AtIndex(0);

await That(Act).DoesNotThrow();
Expand All @@ -31,7 +31,7 @@ public async Task DoesNotMaterializeEnumerable()
IAsyncEnumerable<int> subject = Factory.GetAsyncFibonacciNumbers();

async Task Act()
=> await That(subject).HasItem(a => a == 5).AtAnyIndex();
=> await That(subject).HasItem(a => a == 5);

await That(Act).DoesNotThrow();
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail()
IAsyncEnumerable<int> subject = ToAsyncEnumerable(Array.Empty<int>());

async Task Act()
=> await That(subject).HasItem(_ => true).AtAnyIndex();
=> await That(subject).HasItem(_ => true);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -110,7 +110,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IAsyncEnumerable<int>? subject = null;

async Task Act()
=> await That(subject).HasItem(_ => true).AtAnyIndex();
=> await That(subject).HasItem(_ => true);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task WithMultipleFailures_ShouldIncludeCollectionOnlyOnce()
async Task Act()
=> await That(subject).HasItem(_ => false).AtIndex(0).And.HasItem(_ => false).AtIndex(1).And
.HasItem(_ => false)
.AtAnyIndex();
;

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -170,7 +170,7 @@ public async Task DoesNotEnumerateTwice()
ThrowWhenIteratingTwiceAsyncEnumerable subject = new();

async Task Act()
=> await That(subject).HasItem(1).AtAnyIndex()
=> await That(subject).HasItem(1)
.And.HasItem(1).AtIndex(0);

await That(Act).DoesNotThrow();
Expand All @@ -182,7 +182,7 @@ public async Task DoesNotMaterializeEnumerable()
IAsyncEnumerable<int> subject = Factory.GetAsyncFibonacciNumbers();

async Task Act()
=> await That(subject).HasItem(5).AtAnyIndex();
=> await That(subject).HasItem(5);

await That(Act).DoesNotThrow();
}
Expand Down Expand Up @@ -243,7 +243,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail(int expected)
IAsyncEnumerable<int> subject = ToAsyncEnumerable(Array.Empty<int>());

async Task Act()
=> await That(subject).HasItem(expected).AtAnyIndex();
=> await That(subject).HasItem(expected);

await That(Act).Throws<XunitException>()
.WithMessage($"""
Expand All @@ -263,7 +263,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IAsyncEnumerable<int>? subject = null;

async Task Act()
=> await That(subject).HasItem(expected).AtAnyIndex();
=> await That(subject).HasItem(expected);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -297,7 +297,7 @@ public async Task WithMultipleFailures_ShouldIncludeCollectionOnlyOnce()

async Task Act()
=> await That(subject).HasItem(4).AtIndex(0).And.HasItem(5).AtIndex(1).And.HasItem(6)
.AtAnyIndex();
;

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -614,7 +614,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail()
IAsyncEnumerable<string?> subject = ToAsyncEnumerable(Array.Empty<string>());

async Task Act()
=> await That(subject).HasItem("foo").AtAnyIndex();
=> await That(subject).HasItem("foo");

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -633,7 +633,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IAsyncEnumerable<string>? subject = null;

async Task Act()
=> await That(subject!).HasItem("foo").AtAnyIndex();
=> await That(subject!).HasItem("foo");

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -700,7 +700,7 @@ public async Task WithMultipleFailures_ShouldIncludeCollectionOnlyOnce()

async Task Act()
=> await That(subject).HasItem("d").AtIndex(0).And.HasItem("e").AtIndex(1).And.HasItem("f")
.AtAnyIndex();
;

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -728,7 +728,7 @@ public async Task WhenEquivalentItemIsFound_ShouldSucceed()
MyClass expected = new(5);

async Task Act()
=> await That(subject).HasItem(expected).Equivalent().AtAnyIndex();
=> await That(subject).HasItem(expected).Equivalent();

await That(Act).DoesNotThrow();
}
Expand All @@ -741,7 +741,7 @@ public async Task WhenEquivalentItemIsNotFound_ShouldFail()
MyClass expected = new(4);

async Task Act()
=> await That(subject).HasItem(expected).Equivalent().AtAnyIndex();
=> await That(subject).HasItem(expected).Equivalent();

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -808,7 +808,7 @@ public async Task WithAllDifferentComparer_ShouldFail()
IAsyncEnumerable<int> subject = Factory.GetAsyncFibonacciNumbers(20);

async Task Act()
=> await That(subject).HasItem(1).Using(new AllDifferentComparer()).AtAnyIndex();
=> await That(subject).HasItem(1).Using(new AllDifferentComparer());

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -839,7 +839,7 @@ public async Task WithAllEqualComparer_ShouldSucceed()
IAsyncEnumerable<int> subject = Factory.GetAsyncFibonacciNumbers(20);

async Task Act()
=> await That(subject).HasItem(4).Using(new AllEqualComparer()).AtAnyIndex();
=> await That(subject).HasItem(4).Using(new AllEqualComparer());

await That(Act).DoesNotThrow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task DoesNotMaterializeEnumerable()
IAsyncEnumerable<int> subject = Factory.GetAsyncFibonacciNumbers();

async Task Act()
=> await That(subject).HasItemThat(it => it.IsEqualTo(5)).AtAnyIndex();
=> await That(subject).HasItemThat(it => it.IsEqualTo(5));

await That(Act).DoesNotThrow();
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail()
IAsyncEnumerable<int> subject = ToAsyncEnumerable(Array.Empty<int>());

async Task Act()
=> await That(subject).HasItemThat(it => it.IsNotEqualTo(0)).AtAnyIndex();
=> await That(subject).HasItemThat(it => it.IsNotEqualTo(0));

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -96,7 +96,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IAsyncEnumerable<int>? subject = null;

async Task Act()
=> await That(subject).HasItemThat(it => it.IsNotEqualTo(0)).AtAnyIndex();
=> await That(subject).HasItemThat(it => it.IsNotEqualTo(0));

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task DoesNotEnumerateTwice()
IEnumerable subject = new ThrowWhenIteratingTwiceEnumerable();

async Task Act()
=> await That(subject).HasItem(_ => true).AtAnyIndex()
=> await That(subject).HasItem(_ => true)
.And.HasItem(_ => true).AtIndex(0);

await That(Act).DoesNotThrow();
Expand All @@ -31,7 +31,7 @@ public async Task DoesNotMaterializeEnumerable()
IEnumerable subject = Factory.GetFibonacciNumbers();

async Task Act()
=> await That(subject).HasItem(a => 5.Equals(a)).AtAnyIndex();
=> await That(subject).HasItem(a => 5.Equals(a));

await That(Act).DoesNotThrow();
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail()
IEnumerable subject = Array.Empty<int>();

async Task Act()
=> await That(subject).HasItem(_ => true).AtAnyIndex();
=> await That(subject).HasItem(_ => true);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -110,7 +110,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IEnumerable? subject = null;

async Task Act()
=> await That(subject!).HasItem(_ => true).AtAnyIndex();
=> await That(subject!).HasItem(_ => true);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task WithMultipleFailures_ShouldIncludeCollectionOnlyOnce()
async Task Act()
=> await That(subject).HasItem(_ => false).AtIndex(0).And.HasItem(_ => false).AtIndex(1).And
.HasItem(_ => false)
.AtAnyIndex();
;

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -170,7 +170,7 @@ public async Task DoesNotEnumerateTwice()
IEnumerable subject = new ThrowWhenIteratingTwiceEnumerable();

async Task Act()
=> await That(subject).HasItem(1).AtAnyIndex()
=> await That(subject).HasItem(1)
.And.HasItem(1).AtIndex(0);

await That(Act).DoesNotThrow();
Expand All @@ -182,7 +182,7 @@ public async Task DoesNotMaterializeEnumerable()
IEnumerable subject = Factory.GetFibonacciNumbers();

async Task Act()
=> await That(subject).HasItem(5).AtAnyIndex();
=> await That(subject).HasItem(5);

await That(Act).DoesNotThrow();
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public async Task WhenEnumerableIsEmpty_ShouldFail(int expected)
IEnumerable subject = Array.Empty<int>();

async Task Act()
=> await That(subject).HasItem(expected).AtAnyIndex();
=> await That(subject).HasItem(expected);

await That(Act).Throws<XunitException>()
.WithMessage($"""
Expand All @@ -274,7 +274,7 @@ public async Task WhenSubjectIsNull_WithAnyIndex_ShouldFail()
IEnumerable? subject = null;

async Task Act()
=> await That(subject!).HasItem(expected).AtAnyIndex();
=> await That(subject!).HasItem(expected);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -308,7 +308,7 @@ public async Task WithMultipleFailures_ShouldIncludeCollectionOnlyOnce()

async Task Act()
=> await That(subject).HasItem("d").AtIndex(0).And.HasItem("e").AtIndex(1).And.HasItem("f")
.AtAnyIndex();
;

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand All @@ -335,7 +335,7 @@ public async Task WhenEquivalentItemIsFound_ShouldSucceed()
MyClass expected = new(5);

async Task Act()
=> await That(subject).HasItem(expected).Equivalent().AtAnyIndex();
=> await That(subject).HasItem(expected).Equivalent();

await That(Act).DoesNotThrow();
}
Expand All @@ -347,7 +347,7 @@ public async Task WhenEquivalentItemIsNotFound_ShouldFail()
MyClass expected = new(4);

async Task Act()
=> await That(subject).HasItem(expected).Equivalent().AtAnyIndex();
=> await That(subject).HasItem(expected).Equivalent();

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -414,7 +414,7 @@ public async Task WithAllDifferentComparer_ShouldFail()
IEnumerable subject = Factory.GetFibonacciNumbers(20);

async Task Act()
=> await That(subject).HasItem(1).Using(new AllDifferentComparer()).AtAnyIndex();
=> await That(subject).HasItem(1).Using(new AllDifferentComparer());

await That(Act).Throws<XunitException>()
.WithMessage("""
Expand Down Expand Up @@ -445,7 +445,7 @@ public async Task WithAllEqualComparer_ShouldSucceed()
IEnumerable subject = Factory.GetFibonacciNumbers(20);

async Task Act()
=> await That(subject).HasItem(4).Using(new AllEqualComparer()).AtAnyIndex();
=> await That(subject).HasItem(4).Using(new AllEqualComparer());

await That(Act).DoesNotThrow();
}
Expand Down
Loading
Loading