public async virtual Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe; try { fromOe = await ExecuteOe <T, TResult>(parameters.Expression, parameters.PageSize); } catch (NotSupportedException e) { if (parameters.RequestUri.Contains("$apply=")) { throw; } fromOe = await ExecuteOeViaHttpClient(parameters, null); TestWriteException(e, ConsoleColor.Green); } IReadOnlyList <EfInclude> includes; IList fromDb; using (var dataContext = new OrderContext(OrderContextOptions.Create(true))) fromDb = TestHelper.ExecuteDb(DataAdapter, dataContext, parameters.Expression, out includes); TestHelper.Compare(fromDb, fromOe, includes); }
public async Task NextPageLink() { String request = "OrderItems?$orderby=Id&$count=true"; ODataUri odataUri = Fixture.ParseUri(request); var parser = new OeParser(odataUri.ServiceRoot, Fixture.OeDataAdapter, Fixture.EdmModel); var uri = new Uri(odataUri.ServiceRoot, request); OeRequestHeaders requestHeaders = OeRequestHeaders.JsonDefault.SetMaxPageSize(2); long count = -1; var fromOe = new List<Object>(); do { var response = new MemoryStream(); await parser.ExecuteGetAsync(uri, requestHeaders, response, CancellationToken.None).ConfigureAwait(false); var reader = new ResponseReader(Fixture.EdmModel, Fixture.OeDataAdapter); response.Position = 0; List<Object> result = reader.Read(response).Cast<Object>().ToList(); Assert.InRange(result.Count, 0, requestHeaders.MaxPageSize); fromOe.AddRange(result); if (count < 0) count = reader.ResourceSet.Count.GetValueOrDefault(); uri = reader.ResourceSet.NextPageLink; } while (uri != null); Assert.Equal(count, fromOe.Count); IList fromDb; using (var context = Fixture.CreateContext()) fromDb = context.OrderItems.OrderBy(i => i.Id).ToList(); TestHelper.Compare(fromDb, fromOe, null); }
public async Task NavigationNextPageLink() { String request = "Orders?$expand=Items($filter=Count gt 0 or Count eq null;$orderby=Id;$count=true)&$orderby=Id&$count=true"; ODataUri odataUri = Fixture.ParseUri(request); var parser = new OeParser(odataUri.ServiceRoot, Fixture.OeDataAdapter, Fixture.EdmModel); var requestUri = new Uri(odataUri.ServiceRoot, request); Uri uri = requestUri; OeRequestHeaders requestHeaders = OeRequestHeaders.JsonDefault.SetMaxPageSize(1).SetNavigationNextLink(true); long count = -1; var fromOe = new List<Object>(); do { var response = new MemoryStream(); await parser.ExecuteGetAsync(uri, requestHeaders, response, CancellationToken.None).ConfigureAwait(false); response.Position = 0; var reader = new ResponseReader(Fixture.EdmModel, Fixture.OeDataAdapter); List<Object> result = reader.Read(response).Cast<Object>().ToList(); Assert.InRange(result.Count, 0, requestHeaders.MaxPageSize); fromOe.AddRange(result); var navigationPropertyParser = new OeParser(odataUri.ServiceRoot, Fixture.OeDataAdapter, Fixture.EdmModel); foreach (dynamic order in result) { var navigationProperty = (IEnumerable)order.Items; ODataResourceSetBase resourceSet = reader.GetResourceSet(navigationProperty); var navigationPropertyResponse = new MemoryStream(); await navigationPropertyParser.ExecuteGetAsync(resourceSet.NextPageLink, OeRequestHeaders.JsonDefault, navigationPropertyResponse, CancellationToken.None).ConfigureAwait(false); navigationPropertyResponse.Position = 0; var navigationPropertyReader = new ResponseReader(Fixture.EdmModel, Fixture.OeDataAdapter); foreach (dynamic orderItem in navigationPropertyReader.Read(navigationPropertyResponse)) order.Items.Add(orderItem); Assert.Equal(navigationPropertyReader.ResourceSet.Count, order.Items.Count); } if (count < 0) count = reader.ResourceSet.Count.GetValueOrDefault(); uri = reader.ResourceSet.NextPageLink; } while (uri != null); Assert.Equal(count, fromOe.Count); var exprectedResponse = new MemoryStream(); var expectedParser = new OeParser(odataUri.ServiceRoot, Fixture.OeDataAdapter, Fixture.EdmModel); await expectedParser.ExecuteGetAsync(requestUri, OeRequestHeaders.JsonDefault, exprectedResponse, CancellationToken.None).ConfigureAwait(false); exprectedResponse.Position = 0; var exprectedReader = new ResponseReader(Fixture.EdmModel, Fixture.OeDataAdapter); List<Object> expectedResult = exprectedReader.Read(exprectedResponse).Cast<Object>().ToList(); TestHelper.Compare(expectedResult, fromOe, null); }
private static async Task <Object[]> Execute <T>(String request, Object requestData, Func <OrderContext, IEnumerable <T> > fromDbFunc) { var fixture = new RDBNull_DbFixtureInitDb(); await fixture.Initalize().ConfigureAwait(false); var responseStream = new MemoryStream(); OeParser parser = fixture.CreateParser(request, null); ODataUri odataUri = fixture.ParseUri(request); var requestUri = new Uri(parser.BaseUri, request); if (requestData == null) { await parser.ExecuteOperationAsync(odataUri, OeRequestHeaders.JsonDefault, null, responseStream, CancellationToken.None).ConfigureAwait(false); } else { String data = fixture.SerializeRequestData(requestData); var requestStream = new MemoryStream(Encoding.UTF8.GetBytes(data)); await parser.ExecuteOperationAsync(odataUri, OeRequestHeaders.JsonDefault, requestStream, responseStream, CancellationToken.None).ConfigureAwait(false); } ODataPath path = OeParser.ParsePath(fixture.DbEdmModel, parser.BaseUri, requestUri); var reader = new ResponseReader(fixture.DbEdmModel.GetEdmModel(path), fixture.ServiceProvider); responseStream.Position = 0; Object[] fromOe; if (typeof(T) == typeof(int)) { String count = new StreamReader(responseStream).ReadToEnd(); fromOe = count == "" ? null : new Object[] { int.Parse(count) }; } else if (typeof(T) == typeof(String)) { String json = new StreamReader(responseStream).ReadToEnd(); var jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(json); var jarray = (Newtonsoft.Json.Linq.JArray)jobject["value"]; fromOe = jarray.Select(j => (String)j).ToArray(); } else { fromOe = reader.Read(responseStream).Cast <Object>().ToArray(); } if (fromDbFunc == null) { return(fromOe); } T[] fromDb; using (OrderContext orderContext = fixture.CreateContext()) fromDb = fromDbFunc(orderContext).ToArray(); TestHelper.Compare(fromDb, fromOe, null); return(fromOe); }
public async virtual Task Execute <T, TResult>(QueryParametersScalar <T, TResult> parameters) { IList fromOe = await ExecuteOe <T, TResult>(parameters.Expression, 0); IList fromDb; using (var dataContext = new OrderContext(OrderContextOptions.Create(true, null))) fromDb = TestHelper.ExecuteDb(DataAdapter.EntitySetAdapters, dataContext, parameters.Expression); TestHelper.Compare(fromDb, fromOe, DataAdapter.EntitySetAdapters.EdmModelMetadataProvider, null); }
public async virtual Task Execute <T, TResult>(QueryParametersScalar <T, TResult> parameters) { IList fromOe = await ExecuteOe <T, TResult>(parameters.Expression, 0); IList fromDb; using (var dataContext = OrderContext.Create(_databaseName)) fromDb = TestHelper.ExecuteDb <T, TResult>(dataContext, parameters.Expression); TestHelper.Compare(fromDb, fromOe, null); }
public virtual async Task Execute <T, TResult>(QueryParametersScalar <T, TResult> parameters) { IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, false, 0).ConfigureAwait(false); IList fromDb; using (var dataContext = (DbContext)DbDataAdapter.CreateDataContext()) fromDb = TestHelper.ExecuteDb(DbDataAdapter.EntitySetAdapters, dataContext, parameters.Expression); Console.WriteLine(parameters.RequestUri); TestHelper.Compare(fromDb, fromOe, null); }
public virtual async Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, parameters.NavigationNextLink, parameters.PageSize).ConfigureAwait(false); IList fromDb; IReadOnlyList <IncludeVisitor.Include> includes; using (var dataContext = (DbContext)DbDataAdapter.CreateDataContext()) fromDb = TestHelper.ExecuteDb(DbDataAdapter.EntitySetAdapters, dataContext, parameters.Expression, out includes); Console.WriteLine(parameters.RequestUri); TestHelper.Compare(fromDb, fromOe, includes); }
public virtual async Task Execute <T, TResult>(QueryParametersScalar <T, TResult> parameters) { IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, false, 0).ConfigureAwait(false); ODataUri odataUri = ParseUri(parameters.RequestUri); IEdmModel dbEdmModel = TestHelper.GetEdmModel(DbEdmModel, odataUri.Path); Db.OeDataAdapter dbDataAdapter = DbEdmModel.GetDataAdapter(dbEdmModel.EntityContainer); IList fromDb; using (var dataContext = (DbContext)dbDataAdapter.CreateDataContext()) fromDb = TestHelper.ExecuteDb(dbDataAdapter.EntitySetAdapters, dataContext, parameters.Expression); Console.WriteLine(parameters.RequestUri); TestHelper.Compare(fromDb, fromOe, null); }
public virtual async Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, parameters.NavigationNextLink, parameters.PageSize).ConfigureAwait(false); ODataUri odataUri = ParseUri(parameters.RequestUri); IEdmModel dbEdmModel = TestHelper.GetEdmModel(DbEdmModel, odataUri.Path); Db.OeDataAdapter dbDataAdapter = DbEdmModel.GetDataAdapter(dbEdmModel.EntityContainer); IList fromDb; IReadOnlyList <EfInclude> includes; using (var dataContext = (DbContext)dbDataAdapter.CreateDataContext()) fromDb = TestHelper.ExecuteDb(dbDataAdapter, dataContext, parameters.Expression, out includes); Console.WriteLine(parameters.RequestUri); TestHelper.Compare(fromDb, fromOe, includes); }
public async Task NextPageLink() { String request = "OrderItems?$orderby=Id&$count=true"; const int pageSize = 2; var pageNextLinkModelBoundBuilder = new PageNextLinkModelBoundBuilder(Fixture.OeEdmModel, Fixture.IsSqlite); Query.OeModelBoundProvider modelBoundProvider = pageNextLinkModelBoundBuilder.BuildProvider(pageSize, false); OeParser parser = Fixture.CreateParser(request, modelBoundProvider); var uri = new Uri(parser.BaseUri, request); long count = -1; var fromOe = new List <Object>(); do { var response = new MemoryStream(); await parser.ExecuteGetAsync(uri, OeRequestHeaders.JsonDefault, response, CancellationToken.None).ConfigureAwait(false); var reader = new ResponseReader(parser.EdmModel); response.Position = 0; List <Object> result = reader.Read(response).Cast <Object>().ToList(); Assert.InRange(result.Count, 0, pageSize); fromOe.AddRange(result); if (count < 0) { count = reader.ResourceSet.Count.GetValueOrDefault(); } uri = reader.ResourceSet.NextPageLink; }while (uri != null); Assert.Equal(count, fromOe.Count); IList fromDb; using (var context = Fixture.CreateContext()) fromDb = context.OrderItems.OrderBy(i => i.Id).ToList(); TestHelper.Compare(fromDb, fromOe, null); }
public async virtual Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe = await ExecuteOe <T, TResult>(parameters.Expression, parameters.PageSize); List <IncludeVisitor.Include> includes = GetIncludes(parameters.Expression); if (typeof(TResult) == typeof(Object)) { fromOe = TestHelper.ToOpenType(fromOe); } IList fromDb; using (var dataContext = OrderContext.Create(_databaseName)) { fromDb = TestHelper.ExecuteDb <T, TResult>(dataContext, parameters.Expression, out IReadOnlyList <IncludeVisitor.Include> includesDb); includes.AddRange(includesDb); } TestHelper.Compare(fromDb, fromOe, includes); }
public async Task NavigationNextPageLink() { String request = "Orders?$expand=Items($filter=Count gt 0 or Count eq null;$orderby=Id;$count=true)&$orderby=Id&$count=true"; ODataUri odataUri = Fixture.ParseUri(request); IEdmModel edmModel = Fixture.OeEdmModel.GetEdmModel(odataUri.Path); var requestUri = new Uri(odataUri.ServiceRoot, request); var expectedResponse = new MemoryStream(); var expectedParser = new OeParser(odataUri.ServiceRoot, edmModel); await expectedParser.ExecuteGetAsync(requestUri, OeRequestHeaders.JsonDefault, expectedResponse, CancellationToken.None).ConfigureAwait(false); expectedResponse.Position = 0; var exprectedReader = new ResponseReader(edmModel); List <Object> expectedResult = exprectedReader.Read(expectedResponse).Cast <Object>().ToList(); List <Object> fromOe = await OrdersCountItemsCount(Fixture, request, i => i.Count == null || i.Count > 0, 1, true); TestHelper.Compare(expectedResult, fromOe, null); }
public async virtual Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe; try { fromOe = await ExecuteOe <T, TResult>(parameters.Expression, parameters.PageSize); } catch (NotSupportedException e) { if (parameters.RequestUri.Contains("$apply=")) { throw; } fromOe = await ExecuteOeViaHttpClient(parameters); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(e.Message); Console.ResetColor(); } List <IncludeVisitor.Include> includes = GetIncludes(DataAdapter, parameters.Expression); if (typeof(TResult) == typeof(Object)) { fromOe = TestHelper.ToOpenType(fromOe); } IList fromDb; using (var dataContext = new OrderContext(OrderContextOptions.Create(true, null))) { fromDb = TestHelper.ExecuteDb(DataAdapter, dataContext, parameters.Expression, out IReadOnlyList <IncludeVisitor.Include> includesDb); includes.AddRange(includesDb); } TestHelper.Compare(fromDb, fromOe, DataAdapter.EntitySetAdapters.EdmModelMetadataProvider, includes); }
public async virtual Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe; try { fromOe = await ExecuteOe <T, TResult>(parameters.Expression, parameters.PageSize); } catch (NotSupportedException e) { if (parameters.RequestUri.Contains("$apply=")) { throw; } if (parameters.RequestUri.Contains("$compute=") && (parameters.RequestUri.Contains("ceiling(") || parameters.RequestUri.Contains("hour("))) { throw new NotSupportedException("$compute and function not suported"); } if (parameters.RequestUri.EndsWith("$expand=Items/$count") || parameters.RequestUri.EndsWith("$expand=Customer,Items/$count,AltCustomer")) { throw new NotSupportedException("$count in $expand not supported"); } fromOe = await ExecuteOeViaHttpClient(parameters, null); TestWriteException(e, ConsoleColor.Green); } IReadOnlyList <EfInclude> includes; IList fromDb; using (var dataContext = new OrderContext(OrderContextOptions.Create(true))) fromDb = TestHelper.ExecuteDb(DataAdapter, dataContext, parameters.Expression, out includes); TestHelper.Compare(fromDb, fromOe, includes); }
public virtual async Task Execute <T, TResult>(QueryParameters <T, TResult> parameters) { IList fromOe = await ExecuteOe <TResult>(parameters.RequestUri, parameters.NavigationNextLink, parameters.PageSize).ConfigureAwait(false); ODataUri odataUri = ParseUri(parameters.RequestUri); IEdmModel edmModel = EdmModel.GetEdmModel(odataUri.Path); Db.OeDataAdapter oeDataAdapter = edmModel.GetDataAdapter(edmModel.EntityContainer); Db.OeDataAdapter dbDataAdapter = ((ITestDbDataAdapter)oeDataAdapter).DbDataAdapter; IList fromDb; IReadOnlyList <IncludeVisitor.Include> includes; using (var dataContext = (DbContext)dbDataAdapter.CreateDataContext()) fromDb = TestHelper.ExecuteDb(dbDataAdapter, dataContext, parameters.Expression, out includes); //fix null navigation property Order where aggregate Order(Name) if (typeof(TResult) == typeof(Object)) { foreach (SortedDictionary <String, Object> item in fromOe) { foreach (KeyValuePair <String, Object> keyValue in item.Where(i => i.Value == null).ToList()) { PropertyInfo navigationProperty = typeof(T).GetProperty(keyValue.Key); if (navigationProperty != null && TestContractResolver.IsEntity(navigationProperty.PropertyType) && !includes.Any(i => i.Property == navigationProperty)) { item.Remove(keyValue.Key); } } } } Console.WriteLine(parameters.RequestUri); TestHelper.Compare(fromDb, fromOe, MetadataProvider, includes); }