コード例 #1
0
        public void ChangeItemTest()
        {
            //_context.Subjects.RemoveRange(_context.Subjects);
            var repo = new TeachersRepository(_context);
            var item = new Teacher
            {
                FirstName  = "Kate",
                MiddleName = "Mary",
                LastName   = "March",
                Department = _context.Departments.FirstOrDefault()
            };

            repo.AddItem(item);
            int Id = _context.Teachers.FirstOrDefault(x => x.FirstName == item.FirstName &&
                                                      x.MiddleName == item.MiddleName &&
                                                      x.LastName == item.LastName &&
                                                      x.Department.Id == item.Department.Id).Id;
            var newitem = repo.GetItem(Id);

            newitem.LastName = "Price";
            repo.ChangeItem(newitem);
            var changeditem = repo.GetItem(Id);;

            Assert.AreEqual(newitem.FirstName, changeditem.FirstName);
            Assert.AreEqual(newitem.MiddleName, changeditem.MiddleName);
            Assert.AreEqual(newitem.LastName, changeditem.LastName);
            Assert.AreEqual(newitem.Department.Id, changeditem.Department.Id);
            _context.Teachers.Remove(newitem);
        }
コード例 #2
0
        public void DeleteItemTest()
        {
            var repo = new TeachersRepository(_context);
            var item = new Teacher
            {
                FirstName  = "Kate",
                MiddleName = "Mary",
                LastName   = "March",
                Department = _context.Departments.FirstOrDefault()
            };

            repo.AddItem(item);
            int Id = _context.Teachers.FirstOrDefault(x => x.FirstName == item.FirstName &&
                                                      x.MiddleName == item.MiddleName &&
                                                      x.LastName == item.LastName).Id;

            Assert.AreEqual(item.FirstName, repo.GetItem(Id).FirstName);
            Assert.AreEqual(item.MiddleName, repo.GetItem(Id).MiddleName);
            Assert.AreEqual(item.LastName, repo.GetItem(Id).LastName);
            repo.DeleteItem(Id);
            Assert.AreEqual(item.LastName, repo.GetItem(Id).LastName);
        }
コード例 #3
0
 public void GetItemExceptionTest()
 {
     var repo  = new TeachersRepository(_context);
     var item1 = repo.GetItem(-1).LastName;
 }