Example #1
0
        public async void GetItemsPageNumberPagination()
        {
            string endPoint                     = "http://MyRestApiEndPoint.com";
            var    maxRecordsParam              = 20;
            var    paginationParameterName      = "page";
            var    pageSizeParemeterName        = "limit";
            var    orderByParameterName         = "order_by";
            var    orderByParameterValue        = "date";
            var    orderDirectionParameterName  = "order";
            var    orderDirectionParameterValue = "DESC";

            var paginationConfig = new PageNumberPagination(paginationParameterName, false, 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);
            }
        }
Example #2
0
        public async Task TestValidateConfig_GetApiDataAsync()
        {
            var config       = new RestApiDataConfig();
            var dataProvider = new RestApiDataProvider();
            ConfigParameterNullException exception = await ExceptionsAssert.ThrowsAsync <ConfigParameterNullException>(async() => await dataProvider.GetApiDataAsync(config, 20, new WordPress.WordPressParser()));

            Assert.IsTrue(exception.Message.Contains(nameof(RestApiDataConfig.Url)));
        }
Example #3
0
 public async Task TestGetMoreApiDataAsyncInvalidOperation()
 {
     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();
     InvalidOperationException exception = await ExceptionsAssert.ThrowsAsync <InvalidOperationException>(async() => await dataProvider.GetMoreApiDataAsync <WordPress.WordPressSchema>());
 }
Example #4
0
 public async Task TestNullParser_GetApiDataAsync()
 {
     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();
     ParserNullException exception = await ExceptionsAssert.ThrowsAsync <ParserNullException>(async() => await dataProvider.GetApiDataAsync <WordPress.WordPressSchema>(config, 20, null));
 }
Example #5
0
        public async Task TestGetApiDataAsync()
        {
            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();
            var data         = await dataProvider.GetApiDataAsync(config, 20, new WordPress.WordPressParser());

            Assert.AreEqual((int)HttpStatusCode.Ok, data.HttpStatusCode);
        }
Example #6
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>());
        }
Example #7
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());
        }
Example #8
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);
        }
Example #9
0
        public async Task LoadDataNextPageUrlPagination_NextPagePath()
        {
            var pagination = new NextPageUrlPagination("invalid", null);
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://graph.facebook.com/v2.5/8195378771/posts?&access_token=351842111678417|74b187b46cf37a8ef6349b990bc039c2&fields=id,message,from,created_time,link,full_picture"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <Facebook.FacebookSchema> data = await dataProvider.LoadDataAsync(config, 20, new Facebook.FacebookParser());

            Assert.IsTrue(dataProvider.HasMoreItems, $"{nameof(dataProvider.HasMoreItems)} is false");
            ArgumentNullException exception = await ExceptionsAssert.ThrowsAsync <ArgumentNullException>(async() => await dataProvider.LoadMoreDataAsync <Facebook.FacebookSchema>());
        }
Example #10
0
        public async Task LoadDataNoPagination()
        {
            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, 20, new WordPress.WordPressParser());

            Assert.IsFalse(dataProvider.HasMoreItems, $"{nameof(dataProvider.HasMoreItems)} is true");

            Assert.IsNotNull(data);
            Assert.AreNotEqual(data.Count(), 0);
        }
Example #11
0
        public async Task LoadData_Headers()
        {
            var headers = new Dictionary <string, string>();

            var config = new RestApiDataConfig
            {
                Url     = new Uri("https://www.googleapis.com/youtube/v3/search?q=Windows&part=snippet&key=AIzaSyDdOl3JfYah7b74Bz6BN9HzsnewSqVTItQ&type=video&maxResults=20&order=date"),
                Headers = headers
            };

            headers["Accept-Encoding"] = "gzip";
            headers["User-Agent"]      = "Mozilla/5.0 (gzip)";
            headers["Test-Header"]     = "Test header";
            var dataProvider = new RestApiDataProvider();
            IEnumerable <YouTube.YouTubeSchema> result = await dataProvider.LoadDataAsync(config, 20, new YouTube.YouTubeSearchParser());
        }
Example #12
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);
        }
Example #13
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);
        }
Example #14
0
        public async Task LoadDataItemOffsetPagination_NullParameters()
        {
            var pagination = new ItemOffsetPagination(null, true, null, 20);
            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);
        }
Example #15
0
        public async Task LoadDataNextPageUrlPagination()
        {
            var pagination = new NextPageUrlPagination("paging.next", string.Empty);
            var config     = new RestApiDataConfig
            {
                Url = new Uri(@"https://graph.facebook.com/v2.5/8195378771/posts?&access_token=351842111678417|74b187b46cf37a8ef6349b990bc039c2&fields=id,message,from,created_time,link,full_picture"),
                PaginationConfig = pagination
            };

            var dataProvider = new RestApiDataProvider();
            IEnumerable <Facebook.FacebookSchema> data = await dataProvider.LoadDataAsync(config, 20, new Facebook.FacebookParser());

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

            Assert.IsNotNull(data);
            Assert.AreNotEqual(data.Count(), 0);
        }
Example #16
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);
        }
Example #17
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);
            }
        }
Example #18
0
 private void InitializeDataProvider()
 {
     restApiDataProvider = new RestApiDataProvider();
     rawDataProvider     = new RestApiDataProvider();
 }
Example #19
0
 public async Task TestNullConfig()
 {
     var dataProvider = new RestApiDataProvider();
     ConfigNullException exception = await ExceptionsAssert.ThrowsAsync <ConfigNullException>(async() => await dataProvider.LoadDataAsync(null, 20, new WordPress.WordPressParser()));
 }
 public UserService(RestApiDataProvider dataProvider)
 {
     _dataProvider = dataProvider ?? throw new ArgumentNullException(nameof(dataProvider));
 }
Example #21
0
 private void InitializeDataProvider()
 {
     restApiDataProvider = new RestApiDataProvider();
     rawDataProvider = new RestApiDataProvider();
 }