public void ChangeItemTest() { 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); newitem.Subject.Name = "Demo"; repo.ChangeItem(newitem); var gotitem = repo.GetItem(Id); Assert.AreEqual(newitem.Teacher.Id, gotitem.Teacher.Id); Assert.AreEqual(newitem.Subject.Name, gotitem.Subject.Name); _context.TeachSubjs.Remove(newitem); _context.Subjects.Remove(subject); }
public void ChangeItemTest() { 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); newitem.Subject.Id = 4; repo.ChangeItem(newitem); var gotitem = repo.GetItem(Id); Assert.AreEqual(newitem.Teacher.Id, gotitem.Teacher.Id); Assert.AreEqual(newitem.Subject.Id, gotitem.Subject.Id); _context.TeachSubjs.Remove(newitem); }