public async Task DeleteUserFromDBAsync() { DbContextOptions <VacationMVCDbContext> options = new DbContextOptionsBuilder <VacationMVCDbContext>() .UseInMemoryDatabase("DeleteUserFromDBAsync") .Options; using (VacationMVCDbContext context = new VacationMVCDbContext(options)) { UserService service = new UserService(context); User user = new User(); user.ID = 5; user.Name = "Fwoopty"; user.FaveTripItem = User.TripItem.FlipFlops; context.Add(user); await context.SaveChangesAsync(); await service.DeleteUser(user.ID); await context.SaveChangesAsync(); User result = await context.Users.FirstOrDefaultAsync(x => x.ID == user.ID); Assert.Null(result); } }
public async Task UpdateUserInDBAsync() { DbContextOptions <VacationMVCDbContext> options = new DbContextOptionsBuilder <VacationMVCDbContext>() .UseInMemoryDatabase("UpdateUserInDBAsync") .Options; using (VacationMVCDbContext context = new VacationMVCDbContext(options)) { UserService service = new UserService(context); User user = new User(); user.ID = 4; user.Name = "Boopty"; user.FaveTripItem = User.TripItem.Games; context.Add(user); await context.SaveChangesAsync(); user.Name = "Woopty"; await service.UpdateUser(user); await context.SaveChangesAsync(); User result = await context.Users.FirstOrDefaultAsync(x => x.ID == user.ID); Assert.Equal("Woopty", result.Name); } }
public async void UserCreateControllerTest() { DbContextOptions <VacationMVCDbContext> options = new DbContextOptionsBuilder <VacationMVCDbContext>() .UseInMemoryDatabase("UserDeleteRouteCheck") .Options; using (VacationMVCDbContext context = new VacationMVCDbContext(options)) { UserService service = new UserService(context); User user = new User(); user.ID = 10; user.Name = "Droopty"; user.FaveTripItem = User.TripItem.Toothpaste; UserController controller = new UserController(service); await controller.Create(user); var result = await context.Users.FirstOrDefaultAsync(x => x.ID == user.ID); Assert.Equal("Droopty", result.Name); } }
public async Task GetUserFromDBAsync() { DbContextOptions <VacationMVCDbContext> options = new DbContextOptionsBuilder <VacationMVCDbContext>() .UseInMemoryDatabase("GetUserFromDBAsync") .Options; using (VacationMVCDbContext context = new VacationMVCDbContext(options)) { UserService service = new UserService(context); User user = new User(); user.ID = 6; user.Name = "Goopty"; user.FaveTripItem = User.TripItem.Headphones; context.Add(user); await context.SaveChangesAsync(); var result = service.GetUser(user.ID); Assert.Equal("Goopty", result.Result.Name); } }
public async void UserDeleteControllerRouteCheck() { DbContextOptions <VacationMVCDbContext> options = new DbContextOptionsBuilder <VacationMVCDbContext>() .UseInMemoryDatabase("UserDeleteRouteCheck") .Options; using (VacationMVCDbContext context = new VacationMVCDbContext(options)) { UserService service = new UserService(context); User user = new User(); user.ID = 9; user.Name = "Roopty"; user.FaveTripItem = User.TripItem.Volleyball; context.Add(user); await context.SaveChangesAsync(); UserController controller = new UserController(service); var result = await controller.Delete(user.ID) as ViewResult; User resultUser = (User)result.ViewData.Model; Assert.Equal("Roopty", resultUser.Name); } }
public TripService(VacationMVCDbContext context) { _context = context; }
public UserService(VacationMVCDbContext context) { _context = context; }