public void AddSortOperation_DescOnIOrderedQueryable_ShouldAddThenByDescending() { // arrange IOrderedQueryable <Foo> source = new Foo[0].AsQueryable().OrderBy(f => f.Bar); var closure = new SortQueryableClosure(typeof(Foo), "p"); closure.EnqueueProperty(typeof(Foo).GetProperty(nameof(Foo.Bar))); var operation = closure.CreateSortOperation(SortOperationKind.Desc); // act IOrderedQueryable <Foo> sorted = source.AddInitialSortOperation( operation ); // assert Assert.Equal(source.ThenByDescending(s => s.Bar), sorted); }
public void CompileInitialSortOperation_AscOnIQueryable_ShouldAddOrderBy() { // arrange IQueryable <Foo> source = new Foo[0].AsQueryable(); var closure = new SortQueryableClosure(typeof(Foo), "p"); closure.EnqueueProperty(typeof(Foo).GetProperty(nameof(Foo.Bar))); SortOperationInvocation operation = closure.CreateSortOperation(SortOperationKind.Asc); // act Expression sortExpression = source.Expression.CompileInitialSortOperation( operation ); IQueryable <Foo> sorted = source.Provider.CreateQuery <Foo>(sortExpression); // assert Assert.Equal(source.OrderBy(s => s.Bar), sorted); }