private HttpActionExecutedContext CreateActionExecutedContext(IDbAsyncEnumerator <Dummy> asyncEnumerator)
        {
            var mockSet = new Mock <DbSet <Dummy> >();

            mockSet.As <IDbAsyncEnumerable <Dummy> >()
            .Setup(m => m.GetAsyncEnumerator())
            .Returns(asyncEnumerator);

            mockSet.As <IQueryable <Dummy> >()
            .Setup(m => m.Provider)
            .Returns(new TestDbAsyncQueryProvider <Dummy>(_fixtures.Provider));

            mockSet.As <IQueryable <Dummy> >().Setup(m => m.Expression).Returns(_fixtures.Expression);
            mockSet.As <IQueryable <Dummy> >().Setup(m => m.ElementType).Returns(_fixtures.ElementType);
            mockSet.As <IQueryable <Dummy> >().Setup(m => m.GetEnumerator()).Returns(_fixtures.GetEnumerator());

            var formatter = new JsonMediaTypeFormatter();

            var httpContent = new ObjectContent(typeof(IQueryable <Dummy>), mockSet.Object, formatter);

            return(new HttpActionExecutedContext
            {
                ActionContext = new HttpActionContext
                {
                    ControllerContext = new HttpControllerContext
                    {
                        Request = new HttpRequestMessage(HttpMethod.Get, "http://api.example.com/dummies")
                    }
                },
                Response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = httpContent
                }
            });
        }
        public static async Task <List <T> > ToListAsync <T>(this IDbAsyncEnumerator <T> enumerator, CancellationToken cancellationToken)
        {
            Debug.Assert(enumerator != null);

            var resultList = new List <T>();

            while (await enumerator.MoveNextAsync(cancellationToken))
            {
                resultList.Add(enumerator.Current);
            }

            return(resultList);
        }
Beispiel #3
0
        private async Task <bool> FirstMoveNextAsync(CancellationToken cancellationToken)
        {
            ObjectResult <T> objectResult = await this._getObjectResultAsync(cancellationToken).WithCurrentCulture <ObjectResult <T> >();

            try
            {
                this._objectResultAsyncEnumerator = ((IDbAsyncEnumerable <T>)objectResult).GetAsyncEnumerator();
            }
            catch
            {
                objectResult.Dispose();
                throw;
            }
            return(await this._objectResultAsyncEnumerator.MoveNextAsync(cancellationToken).WithCurrentCulture <bool>());
        }
Beispiel #4
0
        /// <summary>
        /// Sets the underling value after the query has been executed.
        /// </summary>
        /// <param name="dataContext">The data context to translate the results with.</param>
        /// <param name="reader">The <see cref="DbDataReader" /> to get the result from.</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">The future query is not of type ObjectQuery.</exception>
        protected virtual async Task SetResultAsync(ObjectContext dataContext, DbDataReader reader, CancellationToken cancellationToken = default(CancellationToken))
        {
            _isLoaded = true;

            try
            {
                IFutureQuery futureQuery = this;
                var          source      = futureQuery.Query;

                var q = source as ObjectQuery;
                if (q == null)
                {
                    throw new InvalidOperationException("The future query is not of type ObjectQuery.");
                }

                // create execution plan
                dynamic queryProxy = new DynamicProxy(q);
                // ObjectQueryState
                dynamic queryState = queryProxy.QueryState;

                // ObjectQueryExecutionPlan
                dynamic executionPlan = queryState.GetExecutionPlan(null);

                // ShaperFactory
                dynamic shaperFactory = executionPlan.ResultShaperFactory;
                // Shaper<T>
                dynamic shaper = shaperFactory.Create(reader, dataContext, dataContext.MetadataWorkspace,
                                                      MergeOption.AppendOnly, false, true, false);

                var list = new List <T>();
                // Shaper<T> GetEnumerator method return IDbEnumerator<T>, which implements publicly accessible IDbAsyncEnumerator<T>
                IDbAsyncEnumerator <T> enumerator = shaper.GetEnumerator();
                while (await enumerator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
                {
                    list.Add(enumerator.Current);
                }

                _result = list;

                // translate has issue with column names not matching
                //var resultSet = dataContext.Translate<T>(reader);
                //_result = resultSet.ToList();
            }
            catch (Exception ex)
            {
                Exception = ex;
            }
        }
        private IQueryable<Dummy> CreateQueryable(IDbAsyncEnumerator<Dummy> asyncEnumerator)
        {
            var mockSet = new Mock<DbSet<Dummy>>();
            mockSet.As<IDbAsyncEnumerable<Dummy>>()
                .Setup(m => m.GetAsyncEnumerator())
                .Returns(asyncEnumerator);

            mockSet.As<IQueryable<Dummy>>()
                .Setup(m => m.Provider)
                .Returns(new TestDbAsyncQueryProvider<Dummy>(_fixtures.Provider));

            mockSet.As<IQueryable<Dummy>>().Setup(m => m.Expression).Returns(_fixtures.Expression);
            mockSet.As<IQueryable<Dummy>>().Setup(m => m.ElementType).Returns(_fixtures.ElementType);
            mockSet.As<IQueryable<Dummy>>().Setup(m => m.GetEnumerator()).Returns(_fixtures.GetEnumerator());

            return mockSet.Object;
        }
        private IQueryable <Dummy> CreateQueryable(IDbAsyncEnumerator <Dummy> asyncEnumerator)
        {
            var mockSet = new Mock <DbSet <Dummy> >();

            mockSet.As <IDbAsyncEnumerable <Dummy> >()
            .Setup(m => m.GetAsyncEnumerator())
            .Returns(asyncEnumerator);

            mockSet.As <IQueryable <Dummy> >()
            .Setup(m => m.Provider)
            .Returns(new TestDbAsyncQueryProvider <Dummy>(_fixtures.Provider));

            mockSet.As <IQueryable <Dummy> >().Setup(m => m.Expression).Returns(_fixtures.Expression);
            mockSet.As <IQueryable <Dummy> >().Setup(m => m.ElementType).Returns(_fixtures.ElementType);
            mockSet.As <IQueryable <Dummy> >().Setup(m => m.GetEnumerator()).Returns(_fixtures.GetEnumerator());

            return(mockSet.Object);
        }
Beispiel #7
0
 internal static async Task ForEachAsync(this IDbAsyncEnumerable source, Action <object> action, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     using (IDbAsyncEnumerator asyncEnumerator = source.GetAsyncEnumerator())
     {
         if (await TaskExtensions.WithCurrentCulture <bool>(asyncEnumerator.MoveNextAsync(cancellationToken)))
         {
             Task <bool> moveNextTask;
             do
             {
                 cancellationToken.ThrowIfCancellationRequested();
                 object current = asyncEnumerator.Current;
                 moveNextTask = asyncEnumerator.MoveNextAsync(cancellationToken);
                 action(current);
             }while (await TaskExtensions.WithCurrentCulture <bool>(moveNextTask));
         }
     }
 }
Beispiel #8
0
        private async Task <bool> FirstMoveNextAsync(CancellationToken cancellationToken)
        {
            var objectResult = await _getObjectResultAsync(cancellationToken).WithCurrentCulture();

            DebugCheck.NotNull(objectResult); // await _getObjectResultAsync should never return null
            try
            {
                _objectResultAsyncEnumerator = ((IDbAsyncEnumerable <T>)objectResult).GetAsyncEnumerator();
            }
            catch
            {
                // if there is a problem creating the enumerator, we should dispose
                // the enumerable (if there is no problem, the enumerator will take
                // care of the dispose)
                objectResult.Dispose();
                throw;
            }
            return(await _objectResultAsyncEnumerator.MoveNextAsync(cancellationToken).WithCurrentCulture());
        }
Beispiel #9
0
 public OeEf6EntityAsyncEnumerator(IDbAsyncEnumerator asyncEnumerator, CancellationToken cancellationToken)
 {
     _asyncEnumerator   = asyncEnumerator;
     _cancellationToken = cancellationToken;
 }
 public AsyncQueryable(IQueryable <T> queryable)
 {
     this.queryable            = queryable;
     this.dbAsyncQueryProvider = new DbAsyncQueryProvider <T>(queryable.Provider);
     this.dbAsyncEnumerator    = new DbAsyncEnumerator <T>(queryable.GetEnumerator());
 }
            public CastDbAsyncEnumerator(IDbAsyncEnumerator sourceEnumerator)
            {
                DebugCheck.NotNull(sourceEnumerator);

                _underlyingEnumerator = sourceEnumerator;
            }
        internal static IDbAsyncEnumerator <TResult> Cast <TResult>(this IDbAsyncEnumerator source)
        {
            DebugCheck.NotNull(source);

            return(new CastDbAsyncEnumerator <TResult>(source));
        }
        // <summary>
        // Advances the enumerator to the next element in the sequence, returning the result asynchronously.
        // </summary>
        // <returns> A Task containing the result of the operation: true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the sequence. </returns>
        public static Task <bool> MoveNextAsync(this IDbAsyncEnumerator enumerator)
        {
            Check.NotNull(enumerator, "enumerator");

            return(enumerator.MoveNextAsync(CancellationToken.None));
        }
Beispiel #14
0
 public OeEf6AsyncEnumerator(IDbAsyncEnumerator asyncEnumerator, CancellationToken cancellationToken)
     : base(cancellationToken)
 {
     _asyncEnumerator = asyncEnumerator;
 }
 public static Task <List <T> > ToListAsync <T>(this IDbAsyncEnumerator <T> enumerator)
 {
     return(enumerator.ToListAsync(CancellationToken.None));
 }
Beispiel #16
0
 public OeEf6AsyncEnumerator(IDbAsyncEnumerable asyncEnumerable)
 {
     _asyncEnumerator = asyncEnumerable.GetAsyncEnumerator();
 }
Beispiel #17
0
 public CastDbAsyncEnumerator(IDbAsyncEnumerator sourceEnumerator)
 {
     this._underlyingEnumerator = sourceEnumerator;
 }
Beispiel #18
0
 internal static IDbAsyncEnumerator <TResult> Cast <TResult>(
     this IDbAsyncEnumerator source)
 {
     return((IDbAsyncEnumerator <TResult>) new IDbAsyncEnumeratorExtensions.CastDbAsyncEnumerator <TResult>(source));
 }