public void Filtered_GivenFilterIsNull_ExpectUnfiltered() { var options = new DbContextOptionsBuilder <ODataContext>() .UseInMemoryDatabase($"ODataContext{Guid.NewGuid()}") .Options; using var context = new ODataContext(options); context.Add(new Role { Id = Guid.NewGuid(), Name = "Role-1", ResourceCount = 0, UserCount = 3, }); context.Add(new Role { Id = Guid.NewGuid(), Name = "Role-2", ResourceCount = 2, UserCount = 0, }); context.Add(new Role { Id = Guid.NewGuid(), Name = "Role-3", ResourceCount = 4, UserCount = 4, }); context.Add(new Role { Id = Guid.NewGuid(), Name = "Role-4", ResourceCount = 0, UserCount = 0, }); context.SaveChanges(); var roleController = new RoleController(context); var result = Assert.IsType <OkObjectResult>(roleController.Filtered(null)); var data = Assert.IsType <InternalDbSet <Role> >(result.Value); Assert.Equal(4, data.AsQueryable().Count()); }
public void Filtered_GivenFilterIsNull_ExpectUnfiltered() { var options = new DbContextOptionsBuilder <ODataContext>() .UseInMemoryDatabase($"ODataContext{Guid.NewGuid()}") .Options; using var context = new ODataContext(options); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = false, IsLocked = true, IsVerified = true, }); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = true, IsLocked = false, IsVerified = true, }); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = true, IsLocked = true, IsVerified = false, }); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = false, IsLocked = true, IsVerified = false, }); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = true, IsLocked = true, IsVerified = true, }); context.Add(new User { Id = Guid.NewGuid(), IsAdmin = false, IsLocked = false, IsVerified = false, }); context.SaveChanges(); var userController = new UserController(context); var result = Assert.IsType <OkObjectResult>(userController.Filtered(null)); var data = Assert.IsType <InternalDbSet <User> >(result.Value); Assert.Equal(6, data.AsQueryable().Count()); }