public void DeleteItemTest() { var subject = new Subject { Name = "Test Linear Algebra" }; _context.Subjects.Add(subject); var repo = new TeachSubjRepository(_context); var item = new TeachSubj { Teacher = _context.Teachers.FirstOrDefault(x => x.Id == 1), Subject = _context.Subjects.FirstOrDefault(x => x.Name == subject.Name) }; repo.AddItem(item); int Id = _context.TeachSubjs.FirstOrDefault(x => x.Teacher.Id == item.Teacher.Id && x.Subject.Id == item.Subject.Id).Id; var newitem = repo.GetItem(Id); Assert.AreEqual(item.Teacher.Id, newitem.Teacher.Id); Assert.AreEqual(item.Subject.Id, newitem.Subject.Id); repo.DeleteItem(Id); _context.Subjects.Remove(subject); Assert.AreEqual(item.Teacher.Id, repo.GetItem(Id).Teacher.Id); }
public void DeleteItemTest() { var repo = new TeachSubjRepository(_context); var item = new TeachSubj { Teacher = _context.Teachers.FirstOrDefault(x => x.Id == 1), Subject = _context.Subjects.FirstOrDefault(x => x.Id == 1) }; repo.AddItem(item); int Id = _context.TeachSubjs.FirstOrDefault(x => x.Teacher.Id == item.Teacher.Id && x.Subject.Id == item.Subject.Id).Id; var newitem = repo.GetItem(Id); Assert.AreEqual(item.Teacher.Id, newitem.Teacher.Id); Assert.AreEqual(item.Subject, newitem.Subject.Id); repo.DeleteItem(Id); Assert.AreEqual(item.Teacher.Id, repo.GetItem(Id).Teacher.Id); }