Ejemplo n.º 1
0
        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 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);
        }
        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);
        }
 public void GetItemExceptionTest()
 {
     var repo  = new TeachSubjRepository(_context);
     var item1 = repo.GetItem(-1).Subject.Id;
 }