public async void CRUDFavoritesTest() { DbContextOptions <LTBDBContext> options = new DbContextOptionsBuilder <LTBDBContext>() .UseInMemoryDatabase("Favorites") .Options; using (LTBDBContext context = new LTBDBContext(options)) { //CREATE Favorite fav = new Favorite(); Profile profile = new Profile(); profile.Username = "******"; profile.LocationZip = 98107; fav.Profile = profile; fav.Notes = "G'BOY GREGG"; context.Favorites.Add(fav); context.SaveChanges(); //READ var newFav = await context.Favorites.FirstOrDefaultAsync(r => r.Profile == fav.Profile); Assert.Equal("Greg", fav.Profile.Username); //UPDATE newFav.Notes = "BAD BOY GREG! You're Bad!"; context.Update(newFav); context.SaveChanges(); var newFavorite = await context.Favorites.FirstOrDefaultAsync(r => r.Notes == newFav.Notes); Assert.Equal("BAD BOY GREG! You're Bad!", newFavorite.Notes); //DELETE context.Favorites.Remove(newFavorite); context.SaveChanges(); var deletedFavorite = await context.Favorites.FirstOrDefaultAsync(r => r.Profile.Username == newFavorite.Profile.Username); Assert.True(deletedFavorite == null); } }
public async void CRUDProfileTest() { DbContextOptions <LTBDBContext> options = new DbContextOptionsBuilder <LTBDBContext>() .UseInMemoryDatabase("Profile") .Options; using (LTBDBContext context = new LTBDBContext(options)) { //CREATE Profile profile = new Profile(); profile.Username = "******"; profile.LocationZip = 98107; context.Profiles.Add(profile); context.SaveChanges(); //READ var newProfile = await context.Profiles.FirstOrDefaultAsync(r => r.Username == profile.Username); Assert.Equal("Greg", newProfile.Username); //UPDATE newProfile.Username = "******"; context.Update(newProfile); context.SaveChanges(); var newProf = await context.Profiles.FirstOrDefaultAsync(r => r.Username == newProfile.Username); Assert.Equal("Carl", newProf.Username); //DELETE context.Profiles.Remove(newProf); context.SaveChanges(); var deletedProfile = await context.Profiles.FirstOrDefaultAsync(r => r.Username == newProf.Username); Assert.True(deletedProfile == null); } }