public Task GetSelectorsCallCounterBumpedOnUse() { return(RunCacheAndSessionTestAsync(async(cache, session, context) => { Async::System.Collections.Generic.IAsyncEnumerable <GetSelectorResult> enumerator = session.GetSelectors(context, Fingerprint.Random(), Token); await enumerator.ToList(CancellationToken.None); long counter = await GetCounterValue("GetSelectorsCall", cache, context); counter.Should().Be(1); })); }
/// <summary> /// Enumerates a given <paramref name="enumerable"/> until the predicate <paramref name="predicate"/> returns true. /// </summary> private static Async::System.Collections.Generic.IAsyncEnumerable <T> StopAfter <T>(this Async::System.Collections.Generic.IAsyncEnumerable <T> enumerable, Func <T, bool> predicate) { return(AsyncEnumerable.CreateEnumerable( () => { var enumerator = enumerable.GetEnumerator(); bool stop = false; return AsyncEnumerable.CreateEnumerator( async token => { if (stop) { return false; } if (await enumerator.MoveNext(token)) { if (!predicate(enumerator.Current)) { stop = true; } return true; } return false; }, () => enumerator.Current, () => enumerator.Dispose()); })); }