public async void FavoriteControllerUpdateTest() { DbContextOptions <LTBDBContext> options = new DbContextOptionsBuilder <LTBDBContext>() .UseInMemoryDatabase("FavoritesUpdate") .Options; using (LTBDBContext context = new LTBDBContext(options)) { FavoriteService TestService = new FavoriteService(context); Favorite favorites = new Favorite(); favorites.UserID = 1; favorites.PetID = 2; favorites.Notes = "Did this test pass?"; await TestService.CreateFavorite(favorites); favorites.Notes = "Let's change the test"; await TestService.UpdateFavorite(favorites); var TestFavorite = await TestService.GetFavorite(favorites.UserID, favorites.PetID); Assert.Equal("Let's change the test", TestFavorite.Notes); } }
public ActionResult Create(FavoriteCreate model) { if (ModelState.IsValid) { return(View(model)); } var userId = Guid.Parse(User.Identity.GetUserId()); var services = new FavoriteService(userId); services.CreateFavorite(model); return(RedirectToAction("Index")); }
public async void FavoriteControllerDeleteTest() { DbContextOptions <LTBDBContext> options = new DbContextOptionsBuilder <LTBDBContext>() .UseInMemoryDatabase("FavoritesDelete") .Options; using (LTBDBContext context = new LTBDBContext(options)) { FavoriteService TestService = new FavoriteService(context); Favorite favorites = new Favorite(); favorites.UserID = 1; favorites.PetID = 2; favorites.Notes = "Did this test pass?"; await TestService.CreateFavorite(favorites); await TestService.DeleteFavorite(1, 2); var TestFavorite = await context.Favorites.FirstOrDefaultAsync(x => x.UserID == 1 && x.PetID == 2); Assert.Null(TestFavorite); } }