Skip to content

Commit

Permalink
LongCountAsync code coverage,
Browse files Browse the repository at this point in the history
  • Loading branch information
bartdesmet committed Feb 19, 2019
1 parent 368b760 commit d403d11
Showing 1 changed file with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,122 @@ namespace Tests
public class LongCount : AsyncEnumerableTests
{
[Fact]
public async Task LongCount_Null()
public async Task LongCountAsync_Simple_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => true).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, bool>)).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => true, CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, bool>), CancellationToken.None).AsTask());
}

[Fact]
public async Task LongCount1()
public async Task LongCountAsync_Simple()
{
Assert.Equal(0, await new int[0].ToAsyncEnumerable().LongCountAsync());
Assert.Equal(3, await new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync());
}

[Fact]
public async Task LongCount2()
public async Task LongCountAsync_Simple_Throws_Source()
{
var ex = new Exception("Bang!");
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync(), ex);
}

[Fact]
public async Task LongCountAsync_Predicate_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => true).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, bool>)).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => true, CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, bool>), CancellationToken.None).AsTask());
}

[Fact]
public async Task LongCountAsync_Predicate_Simple()
{
Assert.Equal(0, await new int[0].ToAsyncEnumerable().LongCountAsync(x => x < 3));
Assert.Equal(2, await new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync(x => x < 3));
}

[Fact]
public async Task LongCount3Async()
public async Task LongCountAsync_Predicate_Throws_Predicate()
{
var ex = new Exception("Bang!");
var ys = new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync(new Func<int, bool>(x => { throw ex; }));
await AssertThrowsAsync(ys, ex);
}

[Fact]
public async Task LongCount4Async()
public async Task LongCountAsync_Predicate_Throws_Source()
{
var ex = new Exception("Bang!");
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync(), ex);
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync(x => x < 3), ex);
}

[Fact]
public async Task LongCountAsync_AsyncPredicate_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, ValueTask<bool>>)).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, x => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, ValueTask<bool>>), CancellationToken.None).AsTask());
}

[Fact]
public async Task LongCountAsync_AsyncPredicate()
{
Assert.Equal(0, await new int[0].ToAsyncEnumerable().LongCountAsync(x => new ValueTask<bool>(x < 3)));
Assert.Equal(2, await new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync(x => new ValueTask<bool>(x < 3)));
}

[Fact]
public async Task LongCount5Async()
public async Task LongCountAsync_AsyncPredicate_Throws_Predicate()
{
var ex = new Exception("Bang!");
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync(x => x < 3), ex);
var ys = new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync(new Func<int, ValueTask<bool>>(x => { throw ex; }));
await AssertThrowsAsync(ys, ex);
}

[Fact]
public async Task LongCountAsync_AsyncPredicate_Throws_Source()
{
var ex = new Exception("Bang!");
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync(x => new ValueTask<bool>(x < 3)), ex);
}

#if !NO_DEEP_CANCELLATION
[Fact]
public async Task LongCountAsync_AsyncPredicateCancel_Null()
{
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, (x, ct) => new ValueTask<bool>(true)).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, CancellationToken, ValueTask<bool>>)).AsTask());

await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync<int>(default, (x, ct) => new ValueTask<bool>(true), CancellationToken.None).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCountAsync(Return42, default(Func<int, CancellationToken, ValueTask<bool>>), CancellationToken.None).AsTask());
}

[Fact]
public async Task LongCountAsync_AsyncPredicateCancel()
{
Assert.Equal(0, await new int[0].ToAsyncEnumerable().LongCountAsync((x, ct) => new ValueTask<bool>(x < 3)));
Assert.Equal(2, await new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync((x, ct) => new ValueTask<bool>(x < 3)));
}

[Fact]
public async Task LongCountAsync_AsyncPredicateCancel_Throws_Predicate()
{
var ex = new Exception("Bang!");
var ys = new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCountAsync(new Func<int, CancellationToken, ValueTask<bool>>((x, ct) => { throw ex; }));
await AssertThrowsAsync(ys, ex);
}

[Fact]
public async Task LongCountAsync_AsyncPredicateCancel_Throws_Source()
{
var ex = new Exception("Bang!");
await AssertThrowsAsync(Throw<int>(ex).LongCountAsync((x, ct) => new ValueTask<bool>(x < 3)), ex);
}
#endif
}
}

0 comments on commit d403d11

Please sign in to comment.