public async ValueTask ContainsAsync_SelectorAt_With_Comparer_And_NotContains_Must_ReturnFalse(int[] source, SelectorAt <int, string> selector) { // Arrange var value = "!"; var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ContainsAsync(value, EqualityComparer <string> .Default); // Assert _ = result.Must() .BeFalse(); }
public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .FirstAsync(); // Assert _ = result.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }
public async ValueTask ContainsAsync_SelectorAt_With_Null_And_Contains_Must_ReturnFalse(int[] source, SelectorAt <int, string> selector) { // Arrange var value = System.Linq.Enumerable.Last( System.Linq.Enumerable.Select(source, selector.AsFunc())); var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ContainsAsync(value, null); // Assert _ = result.Must() .BeTrue(); }
public async ValueTask ToArrayAsync_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.ToArray( System.Linq.Enumerable.Select(source, selector.AsFunc())); // Act var result = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ToArrayAsync(); // Assert _ = result.Must() .BeArrayOf <string>() .BeEqualTo(expected); }
public async ValueTask FirstAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable.First( System.Linq.Enumerable.Select(source, selector.AsFunc())); // Act var result = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .FirstAsync(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }
public async ValueTask ForEachAsync_Action_Selector_With_ValidData_Must_Succeed(int[] source, Selector <int, string> selector) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); var result = new List <string>(); var expected = new List <string>(); System.Linq.EnumerableEx.ForEach( System.Linq.Enumerable.Select(source, selector.AsFunc()), item => expected.Add(item)); // Act await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ForEachAsync((item, cancellationToken) => { result.Add(item); return(new ValueTask()); }); // Assert _ = result.Must() .BeEnumerableOf <string>() .BeEqualTo(expected); }
public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, SelectorAt <int, string> selector) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); // Act var optionNegative = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ElementAtAsync(-1); var optionTooLarge = await AsyncValueEnumerable .Select <Wrap.AsyncValueEnumerable <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ElementAtAsync(source.Length); // Assert _ = optionNegative.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); _ = optionTooLarge.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }