Ejemplo n.º 1
0
        public async Task ElementAtOrDefaultAsyncWithInt32SourceWithIndexCanceledCancellationTokenThrowsOperationCanceledExceptionTest()
        {
            // Arrange

            // Arrange 'queryAdapter' parameter
            var queryAdapter = await GetQueryAdapterAsync(DisallowAll);

            // Arrange 'asyncSource' parameter
            var asyncSource = queryAdapter.GetAsyncQueryable <int>();

            // Arrange 'index' parameter
            var index = 5;

            // Arrange 'cancellationToken' parameter
            using var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken = cancellationTokenSource.Token;

            cancellationTokenSource.Cancel();

            // Act
            // -

            // Assert
            await Assert.ThrowsAsync <OperationCanceledException>(async() =>
            {
                await AsyncQueryable.ElementAtOrDefaultAsync <int>(asyncSource, index, cancellationToken).ConfigureAwait(false);
            });
        }
Ejemplo n.º 2
0
        public async Task ElementAtOrDefaultAsyncWithInt32SourceWithIndexNullSourceThrowsArgumentNullExceptionTest()
        {
            // Arrange

            // Arrange 'queryAdapter' parameter
            var queryAdapter = await GetQueryAdapterAsync(DisallowAll);

            // Arrange 'asyncSource' parameter
            IAsyncQueryable <int> asyncSource = null !;

            // Arrange 'index' parameter
            var index = 5;

            // Arrange 'cancellationToken' parameter
            var cancellationToken = CancellationToken.None;

            // Act
            // -

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await AsyncQueryable.ElementAtOrDefaultAsync <int>(asyncSource, index, cancellationToken).ConfigureAwait(false);
            });
        }
Ejemplo n.º 3
0
        public async Task ElementAtOrDefaultAsyncWithInt32SourceWithIndexIsEquivalentToElementAtOrDefaultTest()
        {
            // Arrange

            // Arrange 'queryAdapter' parameter
            var queryAdapter = await GetQueryAdapterAsync(DisallowAll);

            // Arrange 'source' parameter
            var source = GetQueryable <int>();

            // Arrange 'asyncSource' parameter
            var asyncSource = queryAdapter.GetAsyncQueryable <int>();

            // Arrange 'index' parameter
            var index = 5;

            // Arrange 'cancellationToken' parameter
            var cancellationToken = CancellationToken.None;

            // Arrange 'expectedResult' parameter
            var expectedResult = Enumerable.ElementAtOrDefault <int>(source, index);

            // Act
            var result = await AsyncQueryable.ElementAtOrDefaultAsync <int>(asyncSource, index, cancellationToken).ConfigureAwait(false);

            // Assert
            Assert.Equal(expectedResult, result);
        }