// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Xunit; namespace Tests { public partial class AsyncTests { [Fact] public void Create_Null() { AssertThrows(() => AsyncEnumerable.CreateEnumerable(default(Func>))); AssertThrows(() => AsyncEnumerable.CreateEnumerator(null, () => 3, () => Task.FromResult(true))); } [Fact] public void Create_Iterator_Throws() { var iter = AsyncEnumerable.CreateEnumerator(() => Task.FromResult(true), () => 3, () => Task.FromResult(true)); var enu = (IAsyncEnumerable)iter; AssertThrows(() => enu.GetAsyncEnumerator()); } [Fact] public void Return() { var xs = AsyncEnumerable.Return(42); HasNext(xs.GetAsyncEnumerator(), 42); } [Fact] public async Task Never() { var xs = AsyncEnumerableEx.Never(); var e = xs.GetAsyncEnumerator(); Assert.False(e.MoveNextAsync().IsCompleted); // Very rudimentary check AssertThrows(() => Nop(e.Current)); await e.DisposeAsync(); } [Fact] public void Throw_Null() { AssertThrows(() => AsyncEnumerable.Throw(null)); } [Fact] public void Throw() { var ex = new Exception("Bang"); var xs = AsyncEnumerable.Throw(ex); var e = xs.GetAsyncEnumerator(); AssertThrows(() => e.MoveNextAsync().Wait(WaitTimeoutMs), (Exception ex_) => ((AggregateException)ex_).InnerExceptions.Single() == ex); AssertThrows(() => Nop(e.Current)); } private void Nop(object o) { } } }