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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ public static AndOrExpectationResult<TCollection, IThat<TCollection>>
doNotPopulateThisValue,
source.Quantity,
(a, c) => source.Quantity.GetEvaluator<TItem, TCollection>(a, c)))
.AppendGenericMethodStatement<TCollection, IThat<TCollection>>(
nameof(Satisfy), doNotPopulateThisValue),
source.Result);

/// <summary>
/// ...satisfy the <paramref name="predicate" />.
/// </summary>
public static AndOrExpectationResult<IEnumerable<TItem>, IThat<IEnumerable<TItem>>>
Satisfy<TItem>(
this QuantifiedCollectionResult<IThat<IEnumerable<TItem>>> source,
Func<TItem, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> new(source.ExpectationBuilder
.AddConstraint(
new ThatQuantifiedCollectionResultShould.SatisfyConstraint<TItem,
IEnumerable<TItem>>(
predicate,
doNotPopulateThisValue,
source.Quantity,
(a, c) => source.Quantity.GetEvaluator<TItem, IEnumerable<TItem>>(a, c)))
.AppendMethodStatement(nameof(Satisfy), doNotPopulateThisValue),
source.Result);
}
Expand All @@ -54,6 +75,29 @@ public static AndOrExpectationResult<TCollection, IThat<TCollection>>
doNotPopulateThisValue,
source.Quantity,
(a, c) => source.Quantity.GetAsyncEvaluator<TItem, TCollection>(a, c)))
.AppendGenericMethodStatement<TCollection, IThat<TCollection>>(
nameof(Satisfy), doNotPopulateThisValue),
source.Result);

/// <summary>
/// ...satisfy the <paramref name="predicate" />.
/// </summary>
public static AndOrExpectationResult<IAsyncEnumerable<TItem>, IThat<IAsyncEnumerable<TItem>>>
Satisfy<TItem>(
this QuantifiedCollectionResult<IThat<IAsyncEnumerable<TItem>>> source,
Func<TItem, bool> predicate,
[CallerArgumentExpression("predicate")]
string doNotPopulateThisValue = "")
=> new(source.ExpectationBuilder
.AddConstraint(
new ThatQuantifiedCollectionResultShould.SatisfyConstraint<TItem,
IAsyncEnumerable<TItem>>(
predicate,
doNotPopulateThisValue,
source.Quantity,
(a, c)
=> source.Quantity.GetAsyncEvaluator<TItem, IAsyncEnumerable<TItem>>(a,
c)))
.AppendMethodStatement(nameof(Satisfy), doNotPopulateThisValue),
source.Result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ namespace Testably.Expectations
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> BeEquivalentTo<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, TItem expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<System.Collections.Generic.IAsyncEnumerable<TItem>, Testably.Expectations.Core.IThat<System.Collections.Generic.IAsyncEnumerable<TItem>>> Satisfy<TItem>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<System.Collections.Generic.IAsyncEnumerable<TItem>>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> Satisfy<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
}
Expand All @@ -355,6 +356,7 @@ namespace Testably.Expectations
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> BeEquivalentTo<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, TItem expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<System.Collections.Generic.IEnumerable<TItem>, Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> Satisfy<TItem>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> Satisfy<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ namespace Testably.Expectations
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> BeEquivalentTo<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, TItem expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<System.Collections.Generic.IAsyncEnumerable<TItem>, Testably.Expectations.Core.IThat<System.Collections.Generic.IAsyncEnumerable<TItem>>> Satisfy<TItem>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<System.Collections.Generic.IAsyncEnumerable<TItem>>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> Satisfy<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IAsyncEnumerable<TItem> { }
}
Expand All @@ -355,6 +356,7 @@ namespace Testably.Expectations
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> BeEquivalentTo<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, TItem expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<System.Collections.Generic.IEnumerable<TItem>, Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> Satisfy<TItem>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> Satisfy<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ namespace Testably.Expectations
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> BeEquivalentTo<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, TItem expected, [System.Runtime.CompilerServices.CallerArgumentExpression("expected")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
public static Testably.Expectations.Results.AndOrExpectationResult<System.Collections.Generic.IEnumerable<TItem>, Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> Satisfy<TItem>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<System.Collections.Generic.IEnumerable<TItem>>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "") { }
public static Testably.Expectations.Results.AndOrExpectationResult<TCollection, Testably.Expectations.Core.IThat<TCollection>> Satisfy<TItem, TCollection>(this Testably.Expectations.QuantifiedCollectionResult<Testably.Expectations.Core.IThat<TCollection>> source, System.Func<TItem, bool> predicate, [System.Runtime.CompilerServices.CallerArgumentExpression("predicate")] string doNotPopulateThisValue = "")
where TCollection : System.Collections.Generic.IEnumerable<TItem> { }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ at Expect.That(subject).Should().All().Be(1)
""");
}

[Fact]
public async Task WhenCollectionIsEmpty_ShouldSucceed()
{
bool[] subject = [];

async Task Act()
=> await That(subject).Should().All().Be(true);

await That(Act).Should().NotThrow();
}

[Fact]
public async Task WhenCollectionOnlyContainsEqualValues_ShouldSucceed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ at Expect.That(subject).Should().None().Be(1)
""");
}

[Fact]
public async Task WhenCollectionIsEmpty_ShouldSucceed()
{
bool[] subject = [];

async Task Act()
=> await That(subject).Should().None().Be(true);

await That(Act).Should().NotThrow();
}

[Fact]
public async Task WhenCollectionOnlyContainsDifferentValues_ShouldSucceed()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System.Collections.Generic;
using Testably.Expectations.Tests.TestHelpers;
// ReSharper disable PossibleMultipleEnumeration

namespace Testably.Expectations.Tests.ThatTests.Collections;

public sealed partial class EnumerableShould
{
public sealed class AllTests
{
[Fact]
public async Task DoesNotEnumerateTwice()
{
ThrowWhenIteratingTwiceEnumerable subject = new();

async Task Act()
=> await That(subject).Should().All().Satisfy(_ => true)
.And.All().Satisfy(_ => true);

await That(Act).Should().NotThrow();
}

[Fact]
public async Task DoesNotMaterializeEnumerable()
{
IEnumerable<int> subject = Factory.GetFibonacciNumbers();

async Task Act()
=> await That(subject).Should().All().Be(1);

await That(Act).Should().Throw<XunitException>()
.WithMessage("""
Expected subject to
have all items equal to 1,
but not all items were equal
at Expect.That(subject).Should().All().Be(1)
""");
}

[Fact]
public async Task WhenEnumerableContainsDifferentValues_ShouldFail()
{
IEnumerable<int> subject = ToEnumerable([1, 1, 1, 1, 2, 2, 3]);

async Task Act()
=> await That(subject).Should().All().Be(1);

await That(Act).Should().Throw<XunitException>()
.WithMessage("""
Expected subject to
have all items equal to 1,
but not all items were equal
at Expect.That(subject).Should().All().Be(1)
""");
}

[Fact]
public async Task WhenEnumerableIsEmpty_ShouldSucceed()
{
IEnumerable<int> subject = ToEnumerable([]);

async Task Act()
=> await That(subject).Should().All().Be(0);

await That(Act).Should().NotThrow();
}

[Fact]
public async Task WhenEnumerableOnlyContainsEqualValues_ShouldSucceed()
{
IEnumerable<int> subject = ToEnumerable([1, 1, 1, 1, 1, 1, 1]);

async Task Act()
=> await That(subject).Should().All().Be(1);

await That(Act).Should().NotThrow();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ at Expect.That(subject).Should().None().Be(1)
""");
}

[Fact]
public async Task WhenEnumerableIsEmpty_ShouldSucceed()
{
IEnumerable<int> subject = ToEnumerable([]);

async Task Act()
=> await That(subject).Should().None().Be(0);

await That(Act).Should().NotThrow();
}

[Fact]
public async Task WhenEnumerableOnlyContainsDifferentValues_ShouldSucceed()
{
Expand Down
Loading