async Task ExecuteLoadItemsCommand(bool more = false) { if (IsBusy) { return; } IsBusy = true; try { Expression <Func <Item, bool> > filter = (Item x) => true; if (more) { var lastItem = Items[Items.Count - 1]; filter = (Item x) => x.DateCreated < lastItem.DateCreated; } else { Items.Clear(); } var sort = OrderByDefinition <Item> .OrderByDescending(x => x.DateCreated); var items = await App.Connection.Meshes.SearchAsync(filter, sort, 1, 10); if (items.TotalRecords > 0) { foreach (var item in items.Results) { Items.Add(item); } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public async Task ShouldSearchCompiledRequestHasCorrectQueryString() { var requestService = new Mock <IRequestService>(); var passedUrl = string.Empty; requestService.Setup(x => x.GetRequest <PageResult <MeshNameAttributeClassTest> >(It.IsAny <string>())).Callback((string url) => { passedUrl = url; }).Returns(() => { return(Task.FromResult(It.IsAny <PageResult <MeshNameAttributeClassTest> >())); }).Verifiable(); var service = new MeshesService(requestService.Object); var pageNumber = new Random().Next(); var pageSize = new Random().Next(); await service.SearchAsync <MeshNameAttributeClassTest>(x => x.FavoriteNumber > 5000, OrderByDefinition <MeshNameAttributeClassTest> .OrderByDescending("FavoriteNumber"), pageNumber, pageSize).ConfigureAwait(false); var encodedFilter = WebUtility.UrlEncode("{ \"FavoriteNumber\" : { \"$gt\" : 5000 } }"); var encodedOrderBy = WebUtility.UrlEncode("{ FavoriteNumber:-1 }"); Assert.Equal($"meshes/{MeshName.ToLowerInvariant()}?filter={encodedFilter}&orderby={encodedOrderBy}&page={pageNumber}&pageSize={pageSize}", passedUrl); requestService.VerifyAll(); }