public async Task ApplyOrdering_ReturnTodosWhenUnknowColumn() { using var testDb = new TestDatabase <TodoContext>(); var todos = TodoFactory.GetTodos(); var options = await testDb.InitializeAsync(async context => { context.Todos.AddRange(todos); await context.SaveChangesAsync(); }); var queryObject = new QueryObject { SortBy = "unknown", IsSortAscending = true }; await using (var context = new TodoContext(options)) { var result = await context.Todos.AsQueryable() .ApplyOrdering(queryObject, ColumnsMap) .ToListAsync(); Assert.Equal(5, result.Count); } }
public async Task ApplyOrdering_OrdersByTitlesDesc() { using (var testDb = new TestDatabase <TodoContext>()) { var todos = TodoFactory.GetTodos(); var options = await testDb.InitializeAsync(async context => { context.Todos.AddRange(todos); await context.SaveChangesAsync(); }); await using (var context = new TodoContext(options)) { var result = await context.Todos.AsQueryable() .ApplyOrdering("title", true, ColumnsMap) .ToListAsync(); Assert.Equal(5, result.Count); Assert.Equal("Todo 5", result.ElementAt(0).Title); Assert.Equal("Todo 4", result.ElementAt(1).Title); Assert.Equal("Todo 1", result.ElementAt(2).Title); Assert.Equal("My Todo 3", result.ElementAt(3).Title); Assert.Equal("My Todo 2", result.ElementAt(4).Title); } } }
public async Task FindAsync_PaginateWithWrongData_ReturnsDefault() { using var testDb = new TestDatabase <TodoContext>(); var todos = TodoFactory.GetTodos(); var options = await testDb.InitializeAsync(async context => { context.Todos.AddRange(todos); await context.SaveChangesAsync(); }); var queryObject = new QueryObject { SortBy = "id", IsSortAscending = true, Page = 0, PageSize = 0 }; await using (var context = new TodoContext(options)) { var result = await context.Todos.AsQueryable() .ApplyOrdering(queryObject, ColumnsMap) .ApplyPaging(queryObject) .ToListAsync(); Assert.Equal(5, result.Count); Assert.Equal(1, result.First().Id); Assert.Equal(5, result.Last().Id); } }
public async Task FindAsync_Paginate_ReturnsPage2() { using var testDb = new TestDatabase <TodoContext>(); var todos = TodoFactory.GetTodos(); var options = await testDb.InitializeAsync(async context => { context.Todos.AddRange(todos); await context.SaveChangesAsync(); }); await using (var context = new TodoContext(options)) { var result = await context.Todos.AsQueryable() .ApplyOrdering("id", false, ColumnsMap) .ApplyPaging(2, 3) .ToListAsync(); Assert.Equal(2, result.Count); Assert.Equal(4, result.First().Id); Assert.Equal(5, result.Last().Id); } }
public HomeController(TodoFactory tFactory) { _todoFactory = tFactory; }