Ejemplo n.º 1
0
        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());
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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());
        }