Example #1
0
        public virtual async Task Execute <T, TResult>(QueryParametersScalar <T, TResult> parameters)
        {
            IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, false, 0).ConfigureAwait(false);

            ODataUri  odataUri   = ParseUri(parameters.RequestUri);
            IEdmModel dbEdmModel = TestHelper.GetEdmModel(DbEdmModel, odataUri.Path);

            Db.OeDataAdapter dbDataAdapter = DbEdmModel.GetDataAdapter(dbEdmModel.EntityContainer);

            IList fromDb;

            using (var dataContext = (DbContext)dbDataAdapter.CreateDataContext())
                fromDb = TestHelper.ExecuteDb(dbDataAdapter.EntitySetAdapters, dataContext, parameters.Expression);

            Console.WriteLine(parameters.RequestUri);
            TestHelper.Compare(fromDb, fromOe, null);
        }
Example #2
0
        public virtual async Task Execute <T, TResult>(QueryParameters <T, TResult> parameters)
        {
            IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, parameters.NavigationNextLink, parameters.PageSize).ConfigureAwait(false);

            ODataUri  odataUri   = ParseUri(parameters.RequestUri);
            IEdmModel dbEdmModel = TestHelper.GetEdmModel(DbEdmModel, odataUri.Path);

            Db.OeDataAdapter dbDataAdapter = DbEdmModel.GetDataAdapter(dbEdmModel.EntityContainer);

            IList fromDb;
            IReadOnlyList <EfInclude> includes;

            using (var dataContext = (DbContext)dbDataAdapter.CreateDataContext())
                fromDb = TestHelper.ExecuteDb(dbDataAdapter, dataContext, parameters.Expression, out includes);

            Console.WriteLine(parameters.RequestUri);
            TestHelper.Compare(fromDb, fromOe, includes);
        }
Example #3
0
        public async Task <IList> ExecuteOe <TResult>(String requestUri, bool navigationNextLink, int pageSize)
        {
            OeModelBoundProvider modelBoundProvider = ModelBoundProvider;

            if (modelBoundProvider == null)
            {
                var modelBoundProviderBuilder = new PageNextLinkModelBoundBuilder(OeEdmModel, IsSqlite);
                modelBoundProvider = modelBoundProviderBuilder.BuildProvider(pageSize, navigationNextLink);
            }

            OeParser         parser         = CreateParser(requestUri, modelBoundProvider);
            var              uri            = new Uri(parser.BaseUri, requestUri);
            OeRequestHeaders requestHeaders = OeRequestHeaders.JsonDefault.SetMaxPageSize(pageSize);

            long     count = -1;
            ODataUri odataUri;
            var      fromOe = new List <Object>();

            do
            {
                odataUri = ParseUri(uri.OriginalString);
                var response = new MemoryStream();
                await parser.ExecuteQueryAsync(odataUri, requestHeaders, response, CancellationToken.None).ConfigureAwait(false);

                response.Position = 0;

                List <Object>  result;
                ResponseReader responseReader;
                if (typeof(TResult).IsPrimitive)
                {
                    TypeConverter converter = TypeDescriptor.GetConverter(typeof(TResult));
                    return(new Object[] { converter.ConvertFromString(new StreamReader(response).ReadToEnd()) });
                }
                {
                    responseReader = new OpenTypeResponseReader(TestHelper.GetEdmModel(DbEdmModel, odataUri.Path), ServiceProvider);
                    result         = responseReader.Read(response).Cast <Object>().ToList();
                }

                if (pageSize > 0)
                {
                    Xunit.Assert.InRange(result.Count, 0, requestHeaders.MaxPageSize);
                }
                fromOe.AddRange(result);

                await responseReader.FillNextLinkProperties(parser, CancellationToken.None).ConfigureAwait(false);

                if (count < 0)
                {
                    count = responseReader.ResourceSet.Count.GetValueOrDefault();
                }

                uri = responseReader.ResourceSet.NextPageLink;
            }while (uri != null);

            if (odataUri.QueryCount != null)
            {
                Xunit.Assert.Equal(count, fromOe.Count);
            }

            return(fromOe);
        }