Exemplo n.º 1
0
        public bool AddNewStudent(int _lesson_id, Student _student)
        {
            var query = from b in Context.Lessons where b.LessonId == _lesson_id select b;
            Lesson found_lesson = null;

            bool result = true;

            try
            {
                found_lesson = query.Single<Lesson>();
                found_lesson.Class.Add(_student);
                Context.SaveChanges();
            }
            catch (InvalidOperationException)
            {
                result = false;
            }
            catch (ArgumentNullException)
            {
                result = false;
            }
            return result;
        }
Exemplo n.º 2
0
        public void AddStudentToLesson()
        {
            //Arrange
            TList = new List<Teacher>();
            LLists = new List<Lesson>();
            SList = new List<Student>();

            TList.Add(new Teacher { Name = "Shalene", TeacherId = 1 }); //create real properties to test
            LLists.Add(new Lesson { LessonId = 1, Title = "Private" });
            SList.Add(new Student { Name = "Nikki", StudentID = 1 });

            mock_context = new Mock<CContext>();
            mock_teacher = new Mock<DbSet<Teacher>>();
            mock_student = new Mock<DbSet<Student>>();
            mock_lesson = new Mock<DbSet<Lesson>>();

            var data = SList.AsQueryable();

            mock_student.As<IQueryable<Student>>().Setup(m => m.Provider).Returns(data.Provider);
            mock_student.As<IQueryable<Student>>().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            mock_student.As<IQueryable<Student>>().Setup(m => m.ElementType).Returns(data.ElementType);
            mock_student.As<IQueryable<Student>>().Setup(m => m.Expression).Returns(data.Expression);

            mock_student.Setup(m => m.Add(It.IsAny<Student>())).Callback((Student b) => SList.Add(b));
            mock_context.Setup(m => m.Students).Returns(mock_student.Object);

            Repository Repo = new Repository(mock_context.Object);
            Student Class = new Student { Name = "Nikki" };

            //Act
            bool success = Repo.AddNewStudent(1, Class);

            //Assert
            Assert.AreEqual(1, Repo.Context.Students.Count());
            Assert.IsFalse(success);
        }
Exemplo n.º 3
0
 public string EditStudentName(Student _student)
 {
     return null;
 }
Exemplo n.º 4
0
 public int RetrieveNumOfStudents(Student _student)
 {
     return 0;
 }
Exemplo n.º 5
0
 public string DeleteStudent(Student _student)
 {
     return null;
 }