public async Task Categories_Query() { var queryBuilder = new CategoriesQueryBuilder() { Page = 1, PerPage = 15, OrderBy = TermsOrderBy.Id, Order = Order.DESC, }; var queryresult = await _clientAuth.Categories.Query(queryBuilder); Assert.AreEqual("?page=1&per_page=15&orderby=id", queryBuilder.BuildQueryURL()); Assert.IsNotNull(queryresult); Assert.AreNotSame(queryresult.Count(), 0); }
public async Task <IEnumerable <Category> > ListAsync(int Page = 1, int PerPage = 20, string Filter = "", DataSource DataSource = DataSource.Cloud) { IEnumerable <Category> categories = null; Filter = Filter.ToLower(); if (DataSource == DataSource.Cloud) { CategoriesQueryBuilder QueryBuilder = new CategoriesQueryBuilder { Page = Page, PerPage = PerPage, Search = Filter.ToLower() }; categories = await Query(QueryBuilder); if (categories != null) { foreach (var category in categories) { var LocalCategory = LocalCategories.FirstOrDefault(c => c.Id == category.Id); if (LocalCategory is Category) { LocalCategories.Remove(LocalCategory); LocalCategories.Add(category); } else { LocalCategories.Add(category); } } File.WriteAllText(_cachedPath, JsonConvert.SerializeObject(LocalCategories)); } } else { categories = LocalCategories.AsEnumerable(); if (!string.IsNullOrEmpty(Filter)) { categories = categories.Where(cat => cat.Name.ToLower().Contains(Filter) || cat.Description.ToLower().Contains(Filter)); } categories = categories.Skip((Page - 1) * PerPage).Take(PerPage); } return(categories); }
public async Task Categories_Query() { var client = await ClientHelper.GetAuthenticatedWordPressClient(); var queryBuilder = new CategoriesQueryBuilder() { Page = 1, PerPage = 15, OrderBy = TermsOrderBy.Id, Order = Order.DESC, }; var queryresult = await client.Categories.Query(queryBuilder); Assert.AreEqual(queryBuilder.BuildQueryURL(), "?page=1&per_page=15&orderby=id&order=desc"); Assert.IsNotNull(queryresult); Assert.AreNotSame(queryresult.Count(), 0); }
/// <summary> /// Create a parametrized query and get a result /// </summary> /// <param name="queryBuilder">Categories query builder with specific parameters</param> /// <param name="useAuth">Send request with authenication header</param> /// <returns>List of filtered categories</returns> public async Task <IEnumerable <Category> > Query(CategoriesQueryBuilder queryBuilder, bool useAuth = false) { return(await _httpHelper.GetRequest <IEnumerable <Category> >($"{_defaultPath}{_methodPath}{queryBuilder.BuildQueryURL()}", false, useAuth).ConfigureAwait(false)); }
public async Task <IEnumerable <Category> > Query(CategoriesQueryBuilder QueryBuilder) { return(await HttpHelper.GetRequests <IEnumerable <Category> >(_methodPath + "/" + QueryBuilder.BuildQueryURL())); }