Beispiel #1
0
        public void TestComplexModel()
        {
            // load environment variables from .env
            DotNetEnv.Env.Load();

            /* Insert a complex model with foreign model relationships
             * <- means depends foreign model
             * Lecturer <- Student <- ProjectMembers -> Project
             */
            int lecturerId = -1;

            using (EPortfolioDB database = new EPortfolioDB())
            {
                // Lecturer model
                Lecturer lecturer = LecturerTest.GetSampleLecturer();
                database.Lecturers.Add(lecturer);

                // Student model
                Student student = StudentTest.GetSampleStudent();
                student.Mentor = lecturer;
                database.Students.Add(student);

                // Project model
                Project project = ProjectTest.GetSampleProject();
                database.Projects.Add(project);

                // ProjectMember model
                ProjectMember projectMember = new ProjectMember
                {
                    Member  = student,
                    Project = project,
                    Role    = "Member"
                };
                database.ProjectMembers.Add(projectMember);

                database.SaveChanges();
                lecturerId = lecturer.LecturerId;
            }

            // query complex model
            using (EPortfolioDB database = new EPortfolioDB())
            {
                Lecturer lecturer = database.Lecturers
                                    .Where(l => l.LecturerId == lecturerId)
                                    .Include(l => l.Students)
                                    .ThenInclude(s => s.ProjectMembers)
                                    .ThenInclude(pm => pm.Project)
                                    .Single();

                Assert.True(LecturerTest.CheckSampleLecturer(lecturer),
                            "lecturer obtained from DB inconsistent with one inserted " +
                            "into the db");

                Student student = lecturer.Students.First();
                Assert.True(StudentTest.CheckSampleStudent(student),
                            "student obtained from DB inconsistent with one inserted " +
                            "into the db");


                ProjectMember projectMember = lecturer.Students.First()
                                              .ProjectMembers.First();
                Assert.Equal("Member", projectMember.Role);

                Project project = projectMember.Project;
                Assert.True(ProjectTest.CheckSampleProject(project),
                            "project obtained from DB inconsistent with one inserted " +
                            "into the db");

                // cleanup
                database.ProjectMembers.Remove(projectMember);
                database.Projects.Remove(project);
                database.Students.Remove(student);
                database.Lecturers.Remove(lecturer);
                database.SaveChanges();
            }
        }
Beispiel #2
0
        public void TestLectuerConstruction()
        {
            Lecturer lecturer = LecturerTest.GetSampleLecturer();

            Assert.True(LecturerTest.CheckSampleLecturer(lecturer));
        }