public async void DeleteHomePage() { DbContextOptions <JamesAmosDbContext> options = new DbContextOptionsBuilder <JamesAmosDbContext> ().UseInMemoryDatabase("DeleteHomePage").Options; using (JamesAmosDbContext context = new JamesAmosDbContext(options)) { // arrange HomePage homePage = new HomePage(); homePage.ID = 1; homePage.CardOneTitle = "hi"; // Act context.HomePage.Add(homePage); context.SaveChanges(); var toDelete = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID); context.HomePage.Remove(toDelete); context.SaveChanges(); var deleted = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID); // Assert Assert.Null(deleted); } }
public async void EditHomePage() { DbContextOptions <JamesAmosDbContext> options = new DbContextOptionsBuilder <JamesAmosDbContext> ().UseInMemoryDatabase("EditHomePage").Options; using (JamesAmosDbContext context = new JamesAmosDbContext(options)) { // arrange HomePage homePage = new HomePage(); homePage.ID = 1; homePage.CardOneTitle = "hi"; // Act context.HomePage.Add(homePage); context.SaveChanges(); var created = await context.HomePage.FirstOrDefaultAsync(h => h.ID == homePage.ID); created.CardOneTitle = "bye"; context.SaveChanges(); // Assert Assert.Equal("bye", created.CardOneTitle); } }
public async void DeleteVlogWorks() { DbContextOptions <JamesAmosDbContext> options = new DbContextOptionsBuilder <JamesAmosDbContext> ().UseInMemoryDatabase("DeleteVlog").Options; using (JamesAmosDbContext context = new JamesAmosDbContext(options)) { // arrange Vlog vlog = new Vlog(); vlog.ID = 1; vlog.Subject = "stuff"; vlog.VideoUrl = "URL"; // Act context.Vlogs.Add(vlog); context.SaveChanges(); var toDelete = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID); context.Remove(toDelete); context.SaveChanges(); var deleted = await context.Vlogs.FirstOrDefaultAsync(v => v.ID == vlog.ID); // Assert Assert.Null(deleted); } }
public IActionResult Create(string Subject, string VideoUrl) { Vlog vlog = new Vlog(); vlog.DateCreated = DateTime.Now; vlog.Subject = Subject; vlog.VideoUrl = VideoUrl; _context.Vlogs.Add(vlog); _context.SaveChanges(); return(RedirectToAction("Index")); }