Ejemplo n.º 1
0
        private IPagination GetPaginationConfig()
        {
            IPagination pagination = null;

            switch (PaginationParameterType)
            {
            case PaginationParameterType.PageNumber:
                pagination = new PageNumberPagination(PaginationParameterName, IsZeroIndexed, PageSizeParameterName);
                break;

            case PaginationParameterType.ItemOffset:
                pagination = new ItemOffsetPagination(PaginationParameterName, IsZeroIndexed, PageSizeParameterName, MaxRecordsParam);
                break;

            case PaginationParameterType.Token:
                pagination = new TokenPagination(PaginationParameterName, ResponseTokenName, PageSizeParameterName);
                break;

            case PaginationParameterType.NextPageUrl:
                pagination = new NextPageUrlPagination(ResponseTokenName, PageSizeParameterName);
                break;

            case PaginationParameterType.None:
            default:
                return(null);
            }

            pagination = GetSorting(pagination);
            return(pagination);
        }
Ejemplo n.º 2
0
        public async Task LoadMoreDataInvalidOperation()
        {
            var pagination = new TokenPagination("page_handle", "next_page", string.Empty);
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            InvalidOperationException exception = await ExceptionsAssert.ThrowsAsync <InvalidOperationException>(async() => await dataProvider.LoadMoreDataAsync <WordPress.WordPressSchema>());
        }
Ejemplo n.º 3
0
        public async Task TestMaxRecordsRestApiDataProvider_Min()
        {
            int maxRecords = 1;
            var pagination = new TokenPagination(string.Empty, string.Empty, "number");
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/")
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <WordPress.WordPressSchema> data = await dataProvider.LoadDataAsync(config, maxRecords, new WordPress.WordPressParser());

            Assert.AreEqual(maxRecords, data.Count());
        }
Ejemplo n.º 4
0
        public async Task TestMaxRecordsRestApiDataProvider_QueryString()
        {
            int maxRecords = 50;
            var pagination = new TokenPagination(string.Empty, string.Empty, "number");
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/?tag=wordpress"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <WordPress.WordPressSchema> data = await dataProvider.LoadDataAsync(config, maxRecords, new WordPress.WordPressParser());

            Assert.IsTrue(data.Count() > 20);
        }
Ejemplo n.º 5
0
        public async Task TestRestApiDataProvider_Sorting()
        {
            int maxRecords = 50;
            var pagination = new TokenPagination(string.Empty, string.Empty, "number");
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/?tag=wordpress"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <WordPress.WordPressSchema> sortedData = await dataProvider.LoadDataAsync(config, maxRecords, new SortingParser());

            IEnumerable <WordPress.WordPressSchema> data = await dataProvider.LoadDataAsync(config, maxRecords, new WordPress.WordPressParser());

            Assert.AreNotEqual(data.FirstOrDefault().Title, sortedData.FirstOrDefault().Title);
        }
Ejemplo n.º 6
0
        public async Task TestGetMoreApiDataAsync()
        {
            var pagination = new TokenPagination("page_handle", "next_page", string.Empty);
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/"),
                PaginationConfig = pagination
            };
            var dataProvider = new RestApiDataProvider();
            var data         = await dataProvider.GetApiDataAsync(config, 20, new WordPress.WordPressParser());

            Assert.IsTrue(dataProvider.HasMoreItems, $"{nameof(dataProvider.HasMoreItems)} is false");

            data = await dataProvider.GetMoreApiDataAsync <WordPress.WordPressSchema>();

            Assert.AreEqual((int)HttpStatusCode.Ok, data.HttpStatusCode);
        }
Ejemplo n.º 7
0
        public async Task LoadDataTokenPagination_QueryString()
        {
            var pagination = new TokenPagination("page_handle", "next_page", "number");
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/?tag=wordpress"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <WordPress.WordPressSchema> data = await dataProvider.LoadDataAsync(config, 20, new WordPress.WordPressParser());

            Assert.IsTrue(dataProvider.HasMoreItems, $"{nameof(dataProvider.HasMoreItems)} is false");
            data = await dataProvider.LoadMoreDataAsync <WordPress.WordPressSchema>();

            Assert.IsNotNull(data);
            Assert.AreNotEqual(data.Count(), 0);
        }
Ejemplo n.º 8
0
        public async Task LoadDataTokenPagination_InvalidTokenPathName()
        {
            var pagination = new TokenPagination(null, "invalid", null);
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://public-api.wordpress.com/rest/v1.1/sites/en.blog.wordpress.com/posts/"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <WordPress.WordPressSchema> data = await dataProvider.LoadDataAsync(config, 20, new WordPress.WordPressParser());

            Assert.IsTrue(dataProvider.HasMoreItems, $"{nameof(dataProvider.HasMoreItems)} is false");
            data = await dataProvider.LoadMoreDataAsync <WordPress.WordPressSchema>();

            Assert.IsNotNull(data);
            Assert.AreNotEqual(data.Count(), 0);
        }
Ejemplo n.º 9
0
        public async void GetItemsTokenPagination()
        {
            string endPoint                     = "http://MyRestApiEndPoint.com";
            var    maxRecordsParam              = 20;
            var    paginationParameterName      = "token";
            var    pageSizeParemeterName        = "limit";
            var    responseTokenName            = "meta.next_token";
            var    orderByParameterName         = "order_by";
            var    orderByParameterValue        = "date";
            var    orderDirectionParameterName  = "order";
            var    orderDirectionParameterValue = "DESC";


            var paginationConfig = new TokenPagination(paginationParameterName, responseTokenName, pageSizeParemeterName)
            {
                OrderByParameterName         = orderByParameterName,
                OrderByParameterValue        = orderByParameterValue,
                OrderDirectionParameterName  = orderDirectionParameterName,
                OrderDirectionParameterValue = orderDirectionParameterValue
            };


            var config = new RestApiDataConfig()
            {
                Url = new Uri(endPoint),
                PaginationConfig = paginationConfig
            };

            var parser = new JsonParser <MySchema>();

            _dataProvider = new RestApiDataProvider();
            var items = await _dataProvider.LoadDataAsync(config, maxRecordsParam, parser);

            foreach (var item in items)
            {
                Items.Add(item);
            }
        }