|
@@ -19,78 +19,6 @@ namespace Tests
|
|
|
{
|
|
|
private const int WaitTimeoutMs = 5000;
|
|
|
|
|
|
- [Fact]
|
|
|
- public async Task Count_Null()
|
|
|
- {
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(null));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(null, x => true));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(AsyncEnumerable.Return(42), default(Func<int, bool>)));
|
|
|
-
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(null, CancellationToken.None));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(null, x => true, CancellationToken.None));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.Count<int>(AsyncEnumerable.Return(42), default(Func<int, bool>), CancellationToken.None));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void Count1()
|
|
|
- {
|
|
|
- Assert.Equal(0, new int[0].ToAsyncEnumerable().Count().Result);
|
|
|
- Assert.Equal(3, new[] { 1, 2, 3 }.ToAsyncEnumerable().Count().Result);
|
|
|
- AssertThrows<AggregateException>(() => AsyncEnumerable.Throw<int>(new Exception("Bang!")).Count().Wait(WaitTimeoutMs));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void Count2()
|
|
|
- {
|
|
|
- Assert.Equal(0, new int[0].ToAsyncEnumerable().Count(x => x < 3).Result);
|
|
|
- Assert.Equal(2, new[] { 1, 2, 3 }.ToAsyncEnumerable().Count(x => x < 3).Result);
|
|
|
- AssertThrows<AggregateException>(() => AsyncEnumerable.Throw<int>(new Exception("Bang!")).Count(x => x < 3).Wait(WaitTimeoutMs));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void Count3()
|
|
|
- {
|
|
|
- var ex = new Exception("Bang!");
|
|
|
- var ys = new[] { 1, 2, 3 }.ToAsyncEnumerable().Count(new Func<int, bool>(x => { throw ex; }));
|
|
|
- AssertThrows<Exception>(() => ys.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public async Task LongCount_Null()
|
|
|
- {
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(null));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(null, x => true));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(AsyncEnumerable.Return(42), default(Func<int, bool>)));
|
|
|
-
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(null, CancellationToken.None));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(null, x => true, CancellationToken.None));
|
|
|
- await Assert.ThrowsAsync<ArgumentNullException>(() => AsyncEnumerable.LongCount<int>(AsyncEnumerable.Return(42), default(Func<int, bool>), CancellationToken.None));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void LongCount1()
|
|
|
- {
|
|
|
- Assert.Equal(0, new int[0].ToAsyncEnumerable().LongCount().Result);
|
|
|
- Assert.Equal(3, new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCount().Result);
|
|
|
- AssertThrows<AggregateException>(() => AsyncEnumerable.Throw<int>(new Exception("Bang!")).LongCount().Wait(WaitTimeoutMs));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void LongCount2()
|
|
|
- {
|
|
|
- Assert.Equal(0, new int[0].ToAsyncEnumerable().LongCount(x => x < 3).Result);
|
|
|
- Assert.Equal(2, new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCount(x => x < 3).Result);
|
|
|
- AssertThrows<AggregateException>(() => AsyncEnumerable.Throw<int>(new Exception("Bang!")).LongCount(x => x < 3).Wait(WaitTimeoutMs));
|
|
|
- }
|
|
|
-
|
|
|
- [Fact]
|
|
|
- public void LongCount3()
|
|
|
- {
|
|
|
- var ex = new Exception("Bang!");
|
|
|
- var ys = new[] { 1, 2, 3 }.ToAsyncEnumerable().LongCount(new Func<int, bool>(x => { throw ex; }));
|
|
|
- AssertThrows<Exception>(() => ys.Wait(WaitTimeoutMs), ex_ => ((AggregateException)ex_).Flatten().InnerExceptions.Single() == ex);
|
|
|
- }
|
|
|
-
|
|
|
[Fact]
|
|
|
public async Task All_Null()
|
|
|
{
|