Esempio n. 1
0
        public bool AddNewLesson(int _teacher_id, Lesson _lesson)
        {
            var query = from b in Context.Teachers where b.TeacherId == _teacher_id select b;
            Teacher found_teacher = null;

            bool result = true;

            try
            {
                found_teacher = query.Single<Teacher>();
                Context.Lessons.Add(_lesson);
                Context.SaveChanges();
            }
            catch (InvalidOperationException)
            {
                result = false;
            }
            catch (ArgumentNullException)
            {
                result = false;
            }
            return result;
        }
Esempio n. 2
0
        public void LessonRepoEnsureICanCreateNewLesson()
        {
            //Arrange - Setup
            LLists = new List<Lesson>();
            TList = new List<Teacher>();
            mock_context = new Mock<CContext>();
            mock_teacher = new Mock<DbSet<Teacher>>();
            mock_student = new Mock<DbSet<Student>>();
            mock_payment = new Mock<DbSet<Payment>>();
            mock_lesson = new Mock<DbSet<Lesson>>();

            var data = LLists.AsQueryable();
            Repository Repo = new Repository(mock_context.Object);
            Lesson lesson = new Lesson { LessonId = 1 };
            Teacher teacher = new Teacher { Name = "Shalene" };
            LLists.Add(new Lesson { Title = "WCS", LessonId = 1 });

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

            mock_lesson.Setup(m => m.Add(It.IsAny<Lesson>())).Callback((Lesson b) => LLists.Add(b));

            mock_context.Setup(m => m.Lessons).Returns(mock_lesson.Object);

            var tdata = TList.AsQueryable();
            mock_teacher.As<IQueryable<Teacher>>().Setup(m => m.Provider).Returns(tdata.Provider);
            mock_teacher.As<IQueryable<Teacher>>().Setup(m => m.GetEnumerator()).Returns(tdata.GetEnumerator());
            mock_teacher.As<IQueryable<Teacher>>().Setup(m => m.ElementType).Returns(tdata.ElementType);
            mock_teacher.As<IQueryable<Teacher>>().Setup(m => m.Expression).Returns(tdata.Expression);

            mock_teacher.Setup(m => m.Add(It.IsAny<Teacher>())).Callback((Teacher b) => TList.Add(b));

            mock_context.Setup(m => m.Teachers).Returns(mock_teacher.Object);

            //Act - Call method that is being tested
            bool Success = Repo.AddNewLesson(1, lesson);

            //Assert - check result

            Assert.AreEqual(1, Repo.Context.Lessons.Count());
            Assert.IsFalse(Success);
        }
Esempio n. 3
0
 //public virtual List<Lesson> Courses { get; set; } //Why not this?
 public Student()
 {
     Lesson = new Lesson();
 }
Esempio n. 4
0
 public Payment()
 {
     Lesson = new Lesson();
 }