public async ValueTask ElementAtAsync_SelectorAt_With_ValidData_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = Enumerable .Select(source, selector.AsFunc()) .ToList(); for (var index = 0; index < source.Length; index++) { // Act var result = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ElementAtAsync(index); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected[index]), () => throw new Exception()); } }
public void Select_Selector_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap.AsAsyncValueEnumerable(source); var expected = System.Linq.Enumerable .Select(source, selector.AsFunc()); // Act var result = AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()); // Assert _ = result.Must() .BeAsyncEnumerableOf <string>() .BeEqualTo(expected); }
public async void ElementAtAsync_SelectorAt_With_OutOfRange_Must_Return_None(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); // Act var optionNegative = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ElementAtAsync(-1); var optionTooLarge = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <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); }
public async ValueTask ToArrayAsync_SelectorAt_MemoryPool_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var pool = MemoryPool <string> .Shared; var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = Enumerable .Select(source, selector.AsFunc()) .ToArray(); // Act var result = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ToArrayAsync(pool); // Assert _ = result.Memory .SequenceEqual(expected); }
public async ValueTask ToArrayAsync_SelectorAt_With_ValidData_Must_Succeed(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = Enumerable .Select(source, selector.AsFunc()) .ToArray(); // Act var result = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .ToArrayAsync(); // Assert _ = result.Must() .BeArrayOf <string>() .BeEqualTo(expected); }
public async void FirstAsync_SelectorAt_With_Empty_Must_Return_None(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); // Act var result = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .FirstAsync(); // Assert _ = result.Must() .BeOfType <Option <string> >() .EvaluateTrue(option => option.IsNone); }
public async ValueTask SingleAsync_SelectorAt_With_SingleAsync_Must_Return_Some(int[] source, NullableSelectorAt <int, string> selector) { // Arrange var wrapped = Wrap .AsAsyncValueEnumerable(source); var expected = Enumerable .Select(source, selector.AsFunc()) .Single(); // Act var result = await AsyncValueEnumerableExtensions .Select <Wrap.AsyncValueEnumerableWrapper <int>, Wrap.AsyncEnumerator <int>, int, string>(wrapped, selector.AsAsync()) .SingleAsync(); // Assert _ = result.Match( value => value.Must().BeEqualTo(expected), () => throw new Exception()); }