Ejemplo n.º 1
0
        public void testStudents()
        {
            //test removing all students
            mcrRepository.removeAllStudents();
            Assert.AreEqual(0, mcrRepository.getStudents().Count);
            Assert.AreEqual(0, mcrRepository.getStudents("TestIp").Count);

            //test creating a student
            Student createdStd = mcrRepository.createStudent(testStudent);

            validateStudent(createdStd, "TestStudent", "TestStudentId", "TestIp");

            //test reading students
            Assert.IsTrue(mcrRepository.getStudents().Contains(createdStd));
            Assert.IsTrue(mcrRepository.getStudents("TestIp").Contains(createdStd));
            Assert.AreEqual(createdStd, mcrRepository.getStudent(createdStd.id));
            validateStudent(createdStd, "TestStudent", "TestStudentId", "TestIp");

            //test reading students under an ip
            Assert.IsTrue(mcrRepository.getStudents("TestIp").Contains(createdStd));

            //test creating 10000 students parallelly
            int       lastStudentCount = mcrRepository.getStudents().Count;
            const int nStudent         = 50;

            Parallel.For(0, nStudent, (i) => {
                Student std = new Student {
                    name = "Student-" + i, studentId = "TestStudentId-" + i, ip = "TestIp"
                };
                mcrRepository.createStudent(std);
                validateStudent(std, "Student-" + i, "TestStudentId-" + i, "TestIp");
            });
            Assert.AreEqual(lastStudentCount + nStudent, mcrRepository.getStudents().Count);
        }