public async Task NavigationNextLink() { String request = "Categories?$expand=Children"; OeParser parser = Fixture.CreateParser(request, Fixture.ModelBoundProvider); ODataUri odataUri = Fixture.ParseUri(request); var response = new MemoryStream(); await parser.ExecuteQueryAsync(odataUri, OeRequestHeaders.JsonDefault, response, CancellationToken.None).ConfigureAwait(false); response.Position = 0; var reader = new ResponseReader(parser.EdmModel); List <Object> categories = reader.Read(response).Cast <Object>().ToList(); foreach (dynamic category in categories) { ResponseReader.NavigationInfo navigationInfo = reader.GetNavigationInfo(category.Children); String actual = Uri.UnescapeDataString(navigationInfo.NextPageLink.OriginalString); String expected = $"http://dummy/Categories?$filter=ParentId eq {category.Id}&$select=DateTime,Id,Name,ParentId"; ODataUri actualOdataUri = Fixture.ParseUri(actual); var selectedItems = actualOdataUri.SelectAndExpand.SelectedItems.Cast <PathSelectItem>().OrderBy(i => ((PropertySegment)i.SelectedPath.FirstSegment).Property.Name); actualOdataUri.SelectAndExpand = new SelectExpandClause(selectedItems, actualOdataUri.SelectAndExpand.AllSelected); actual = Uri.UnescapeDataString(actualOdataUri.BuildUri(ODataUrlKeyDelimiter.Parentheses).OriginalString); Assert.Equal(expected, actual); } }
public async Task NavigationNextLink() { String request = "Categories?$expand=Children"; OeParser parser = Fixture.CreateParser(request, Fixture.ModelBoundProvider); ODataUri odataUri = Fixture.ParseUri(request); var response = new MemoryStream(); await parser.ExecuteQueryAsync(odataUri, OeRequestHeaders.JsonDefault, response, CancellationToken.None).ConfigureAwait(false); response.Position = 0; var reader = new ResponseReader(parser.EdmModel); List <Object> categories = reader.Read(response).Cast <Object>().ToList(); foreach (dynamic category in categories) { ResponseReader.NavigationInfo navigationInfo = reader.GetNavigationInfo(category.Children); String actual = Uri.UnescapeDataString(navigationInfo.NextPageLink.OriginalString); String expected = $"http://dummy/Categories?$filter=ParentId eq {category.Id}"; Assert.Equal(expected, actual); } }
internal static async Task <List <Object> > OrdersCountItemsCount(DbFixture fixture, String request, Func <Model.OrderItem, bool> orderItemPredicate, int maxPageSize, bool navigationNextLink) { Query.OeModelBoundProvider modelBoundProvider = fixture.ModelBoundProvider; if (modelBoundProvider == null) { var modelBoundProviderBuilder = new PageNextLinkModelBoundBuilder(fixture.OeEdmModel, fixture.IsSqlite); modelBoundProvider = modelBoundProviderBuilder.BuildProvider(maxPageSize, navigationNextLink); } OeParser parser = fixture.CreateParser(request, modelBoundProvider); Uri uri = new Uri(parser.BaseUri, request); int expectedCount; long count = -1; var fromOe = new List <Object>(); do { var response = new MemoryStream(); await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault.SetMaxPageSize(maxPageSize), response, CancellationToken.None).ConfigureAwait(false); response.Position = 0; var reader = new ResponseReader(parser.EdmModel); List <Object> result = reader.Read(response).Cast <Object>().ToList(); fromOe.AddRange(result); if (maxPageSize > 0) { Assert.InRange(result.Count, 0, maxPageSize); } var navigationPropertyParser = new OeParser(parser.BaseUri, parser.EdmModel, fixture.ModelBoundProvider); foreach (dynamic order in result) { using (var dbContext = fixture.CreateContext()) { String orderName = order.Name; expectedCount = dbContext.OrderItems.Where(i => i.Order.Name == orderName).ToList().Where(orderItemPredicate).Count(); } var navigationProperty = (IEnumerable)order.Items; ResponseReader.NavigationInfo info = reader.GetNavigationInfo(navigationProperty); if (!navigationNextLink && !uri.OriginalString.Contains("$skiptoken=")) { Assert.Equal(expectedCount, info.Count); } var navigationPropertyResponse = new MemoryStream(); await navigationPropertyParser.ExecuteGetAsync(info.NextPageLink, OeRequestHeaders.JsonDefault, navigationPropertyResponse, CancellationToken.None).ConfigureAwait(false); navigationPropertyResponse.Position = 0; var navigationPropertyReader = new ResponseReader(parser.EdmModel); foreach (dynamic orderItem in navigationPropertyReader.Read(navigationPropertyResponse)) { order.Items.Add(orderItem); } if (navigationNextLink) { Assert.Equal(expectedCount, navigationPropertyReader.ResourceSet.Count); } } if (count < 0) { count = reader.ResourceSet.Count.GetValueOrDefault(); } uri = reader.ResourceSet.NextPageLink; }while (uri != null); using (var dbContext = fixture.CreateContext()) expectedCount = dbContext.Orders.Count(); Assert.Equal(expectedCount, count); return(fromOe); }