Пример #1
0
        public async void BuildingWithTopAndLargerPageSizeNextLink()
        {
            int    pageSize = 4;
            string query    = "/corebuilding?$top=3";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider,
                serviceProvider.GetRequiredService <IRouteBuilder>()
                                                       );

            Test(Get <CoreBuilding, TBuilding>(query, options, new QuerySettings {
                ODataSettings = new ODataSettings {
                    HandleNullPropagation = HandleNullPropagationOption.False, PageSize = pageSize
                }
            }));
            Test(await GetAsync <CoreBuilding, TBuilding>(query, options, new QuerySettings {
                ODataSettings = new ODataSettings {
                    HandleNullPropagation = HandleNullPropagationOption.False, PageSize = pageSize
                }
            }));

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Equal(3, collection.Count);
                Assert.Null(options.Request.ODataFeature().NextLink);
            }
        }
Пример #2
0
        public async void BuildingWithTopAndSmallerPageSizeNextLink()
        {
            int    pageSize = 2;
            string query    = "/corebuilding?$top=3";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider,
                serviceProvider.GetRequiredService <IRouteBuilder>()
                                                       );

            Test(Get <CoreBuilding, TBuilding>(query, options, new QuerySettings {
                ODataSettings = new ODataSettings {
                    HandleNullPropagation = HandleNullPropagationOption.False, PageSize = pageSize
                }
            }));
            Test(await GetAsync <CoreBuilding, TBuilding>(query, options, new QuerySettings {
                ODataSettings = new ODataSettings {
                    HandleNullPropagation = HandleNullPropagationOption.False, PageSize = pageSize
                }
            }));

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Equal(2, collection.Count);

                Uri nextPageLink = options.Request.ODataFeature().NextLink;

                Assert.NotNull(nextPageLink);
                Assert.Equal("localhost:16324/corebuilding?$top=1&$skip=2", nextPageLink.AbsoluteUri);
                Assert.Contains("$top=1", nextPageLink.Query);
                Assert.Contains("$skip=2", nextPageLink.Query);
            }
        }
Пример #3
0
        private async Task <ICollection <TModel> > Get <TModel, TData>(string query, ODataQueryOptions <TModel> options = null) where TModel : class where TData : class
        {
            return(await DoGet
                   (
                       serviceProvider.GetRequiredService <IMapper>(),
                       serviceProvider.GetRequiredService <TestDbContext>()
                   ));

            async Task <ICollection <TModel> > DoGet(IMapper mapper, TestDbContext context)
            {
                return(await context.Set <TData>().GetAsync
                       (
                           mapper,
                           options ?? ODataHelpers.GetODataQueryOptions <TModel>
                           (
                               query,
                               serviceProvider,
                               serviceProvider.GetRequiredService <IRouteBuilder>()
                           ),
                           new QuerySettings {
                    ODataSettings = new ODataSettings {
                        HandleNullPropagation = HandleNullPropagationOption.False
                    }
                }
                       ));
            }
        }
Пример #4
0
        public async void BuildingExpandBuilderTenantExpandCityOrderByBuilderNameSkip3Take1NoCount()
        {
            string query = "/corebuilding?$skip=4&$top=1&$expand=Builder($expand=City),Tenant&$orderby=Name desc,Identity";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider,
                serviceProvider.GetRequiredService <IRouteBuilder>()
                                                       );

            Test
            (
                await Get <CoreBuilding, TBuilding>
                (
                    query,
                    options
                )
            );

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Null(options.Request.ODataFeature().TotalCount);
                Assert.Equal(1, collection.Count);
                Assert.Equal("London", collection.First().Builder.City.Name);
                Assert.Equal("One L1", collection.First().Name);
            }
        }
Пример #5
0
        public async void BuildingExpandBuilderTenantExpandCityFilterOnNestedNestedPropertyWithCount()
        {
            string query = "/corebuilding?$top=5&$expand=Builder($expand=City),Tenant&$filter=Builder/City/Name eq 'Leeds'&$count=true";
            ODataQueryOptions <CoreBuilding> options = ODataHelpers.GetODataQueryOptions <CoreBuilding>
                                                       (
                query,
                serviceProvider,
                serviceProvider.GetRequiredService <IRouteBuilder>()
                                                       );

            Test
            (
                await Get <CoreBuilding, TBuilding>
                (
                    query,
                    options
                )
            );

            void Test(ICollection <CoreBuilding> collection)
            {
                Assert.Equal(2, options.Request.ODataFeature().TotalCount);
                Assert.Equal(2, collection.Count);
                Assert.Equal("Leeds", collection.First().Builder.City.Name);
            }
        }
Пример #6
0
        private ODataQueryOptions <TModel> GetODataQueryOptions <TModel>(string query) where TModel : class
        {
            if (_oDataQueryOptions == null)
            {
                _oDataQueryOptions = ODataHelpers.GetODataQueryOptions <TModel>
                                     (
                    query,
                    serviceProvider
                                     );
            }

            return((ODataQueryOptions <TModel>)_oDataQueryOptions);
        }
Пример #7
0
        private ODataQueryOptions <TModel> GetODataQueryOptions <TModel>(string query) where TModel : class
        {
            if (_oDataQueryOptions == null)
            {
                _oDataQueryOptions = ODataHelpers.GetODataQueryOptions <TModel>
                                     (
                    query,
                    serviceProvider,
                    serviceProvider.GetRequiredService <IRouteBuilder>()
                                     );
            }

            return((ODataQueryOptions <TModel>)_oDataQueryOptions);
        }