public void t5_pupils_firstname_and_lastname_must_be_not_null_and_longer_than_2_characters(string firstName, string lastName)
        {
            School    s = new School("Evariste Galois");
            Classroom c = s.AddClassRoom("C");

            Assert.Throws <ArgumentException>(() => c.AddPupil(firstName, lastName));
        }
        public void t1_teachers_can_be_assigned_to_a_classroom()
        {
            School    s  = new School("Evariste Galois");
            Classroom c1 = s.AddClassRoom("CE1");
            Classroom c2 = s.AddClassRoom("CE2");

            Assert.That(c1.Teacher, Is.Null, "No teacher assigned yet to CE1.");
            Assert.That(c2.Teacher, Is.Null, "No teacher assigned yet to CE2.");

            Teacher t = s.AddTeacher("Albert");

            t.AssignTo(c1);
            Assert.That(t.Assignment, Is.SameAs(c1), "Albert is now teaching to CE1.");
            Assert.That(c1.Teacher, Is.SameAs(t), "CE1 is now teached by Albert.");
            Assert.That(c2.Teacher, Is.Null, "CE2 still has no teacher.");
        }
        public void t2_when_a_teacher_is_assigned_to_a_classroom_he_losts_its_previous_classroom()
        {
            School    s  = new School("Evariste Galois");
            Classroom c1 = s.AddClassRoom("CE1");
            Classroom c2 = s.AddClassRoom("CE2");
            Teacher   t  = s.AddTeacher("Albert");

            t.AssignTo(c1);
            Assert.That(t.Assignment, Is.SameAs(c1), "Albert is now teaching to CE1.");
            Assert.That(c1.Teacher, Is.SameAs(t), "CE1 is now teached by Albert.");
            Assert.That(c2.Teacher, Is.Null, "CE2 still has no teacher.");

            t.AssignTo(c2);
            Assert.That(t.Assignment, Is.SameAs(c2), "Albert is now teaching to CE2.");
            Assert.That(c2.Teacher, Is.SameAs(t), "CE2 is now teached by Albert.");
            Assert.That(c1.Teacher, Is.Null, "CE1 has no teacher anymore.");
        }
        public void t4_classrooms_can_be_renamed()
        {
            School    s  = new School("Evariste Galois");
            Classroom c1 = s.AddClassRoom("CE1-1");
            Classroom c2 = s.AddClassRoom("CE1-2");

            Assert.That(s.FindClassRoom("CE1-1"), Is.SameAs(c1));
            Assert.That(s.FindClassRoom("CE1-2"), Is.SameAs(c2));

            c1.Name = "XRQ-3712";
            Assert.That(s.FindClassRoom("CE1-1"), Is.Null);
            Assert.That(c1.Name, Is.EqualTo("XRQ-3712"));
            Assert.That(s.FindClassRoom("XRQ-3712"), Is.SameAs(c1));

            Assert.Throws <ArgumentException>(() => c1.Name = "CE1-2");

            Assert.DoesNotThrow(() => c2.Name = "CE1-2");
            Assert.DoesNotThrow(() => c1.Name = "XRQ-3712");
        }
        public void t3_classrooms_can_be_found_by_name()
        {
            School    s  = new School("Evariste Galois");
            Classroom c1 = s.AddClassRoom("CE1-1");

            Assert.That(s.FindClassRoom("CE1-1"), Is.SameAs(c1));
            Assert.That(s.FindClassRoom("CE1-2"), Is.Null);

            Classroom c2 = s.AddClassRoom("CE1-2");

            Assert.That(s.FindClassRoom("CE1-1"), Is.SameAs(c1));
            Assert.That(s.FindClassRoom("CE1-2"), Is.SameAs(c2));
            Assert.That(s.FindClassRoom("CE1-3"), Is.Null);

            Classroom c3 = s.AddClassRoom("CE1-3");
            Classroom c4 = s.AddClassRoom("CE2-1");
            Classroom c5 = s.AddClassRoom("CE2-2");

            Assert.That(s.FindClassRoom("CE1-1"), Is.SameAs(c1));
            Assert.That(s.FindClassRoom("CE1-2"), Is.SameAs(c2));
            Assert.That(s.FindClassRoom("CE1-3"), Is.SameAs(c3));
            Assert.That(s.FindClassRoom("CE2-1"), Is.SameAs(c4));
            Assert.That(s.FindClassRoom("CE2-2"), Is.SameAs(c5));

            var randomNames = Enumerable.Range(0, 20).Select(i => String.Format("n°{0} - {1}", i, Guid.NewGuid().ToString())).ToArray();
            var classRooms  = randomNames.Select(n => s.AddClassRoom(n)).ToArray();

            CollectionAssert.AreEqual(classRooms, randomNames.Select(n => s.FindClassRoom(n)));
        }
        public void t4_assigning_a_teacher_to_a_null_classroom_removes_its_assignment()
        {
            School    s = new School("Evariste Galois");
            Classroom c = s.AddClassRoom("CE1");
            Teacher   t = s.AddTeacher("Evariste");

            Assert.DoesNotThrow(() => t.AssignTo(null));

            t.AssignTo(c);
            Assert.That(t.Assignment, Is.SameAs(c), "Evariste now teachs to CE1.");
            Assert.That(c.Teacher, Is.SameAs(t), "CE1 has teacher Evariste.");

            t.AssignTo(null);
            Assert.That(t.Assignment, Is.Null, "Evariste does not teach anymore.");
            Assert.That(c.Teacher, Is.Null, "CE1 has no teacher anymore.");
        }
        public void t3_teachers_and_classrooms_must_belong_to_the_same_school()
        {
            School    s1   = new School("Evariste Galois");
            Classroom c1S1 = s1.AddClassRoom("CE1 (Evariste Galois)");
            Teacher   tS1  = s1.AddTeacher("Evariste");

            School    s2   = new School("Jules Vallès");
            Classroom c1S2 = s2.AddClassRoom("CE1 (Jules Vallès)");

            Assert.DoesNotThrow(() => tS1.AssignTo(c1S1));
            Assert.Throws <ArgumentException>(() => tS1.AssignTo(c1S2));

            School    s3   = new School("Evariste Galois");
            Classroom c1S3 = s3.AddClassRoom("CE1 (Evariste Galois n°2)");

            Assert.Throws <ArgumentException>(() => tS1.AssignTo(c1S3));
        }
        public void t4_pupils_are_created_by_classrooms_and_have_a_unique_firstname_and_lastname()
        {
            School    s = new School("Evariste Galois");
            Classroom c = s.AddClassRoom("C");

            Pupil p1 = c.AddPupil("Jean-Paul", "Sartre");

            Assert.That(p1.Classroom, Is.SameAs(c));
            Assert.That(p1.FirstName, Is.EqualTo("Jean-Paul"));
            Assert.That(p1.LastName, Is.EqualTo("Sartre"));
            Assert.Throws <ArgumentException>(() => c.AddPupil("Jean-Paul", "Sartre"));

            Pupil p2 = c.AddPupil("Jean-Paul", "Deux");

            Assert.That(p2.Classroom, Is.SameAs(c));
            Assert.That(p2.FirstName, Is.EqualTo("Jean-Paul"));
            Assert.That(p2.LastName, Is.EqualTo("Deux"));
            Assert.Throws <ArgumentException>(() => c.AddPupil("Jean-Paul", "Deux"));

            Assert.That(typeof(Pupil).GetProperty("FirstName").GetSetMethod(), Is.Null, "Pupil.FirstName must NOT be writeable.");
            Assert.That(typeof(Pupil).GetProperty("LastName").GetSetMethod(), Is.Null, "Pupil.FirstName must NOT be writeable.");
            Assert.That(typeof(Pupil).GetConstructors(BindingFlags.Instance | BindingFlags.Public), Is.Empty, "Pupil must not expose any public constructors.");
        }
        public void t2_pupils_can_be_found_by_name()
        {
            School    s = new School("Evariste Galois");
            Classroom c = s.AddClassRoom("CE1");

            Pupil albert = c.AddPupil("Albert", "Einstein");

            Assert.That(c.FindPupil("Albert", "Einstein"), Is.SameAs(albert));
            Assert.That(c.FindPupil("Max", "Planck"), Is.Null);

            Pupil max = c.AddPupil("Max", "Planck");

            Assert.That(c.FindPupil("Albert", "Einstein"), Is.SameAs(albert));
            Assert.That(c.FindPupil("Max", "Planck"), Is.SameAs(max));
            Assert.That(c.FindPupil("Enrico", "Fermi"), Is.Null);

            Pupil enrico = c.AddPupil("Enrico", "Fermi");
            Pupil paul   = c.AddPupil("Paul", "Langevin");
            Pupil nikola = c.AddPupil("Nikola", "Tesla");

            Assert.That(c.FindPupil("Albert", "Einstein"), Is.SameAs(albert));
            Assert.That(c.FindPupil("Max", "Planck"), Is.SameAs(max));
            Assert.That(c.FindPupil("Enrico", "Fermi"), Is.SameAs(enrico));
            Assert.That(c.FindPupil("Paul", "Langevin"), Is.SameAs(paul));
            Assert.That(c.FindPupil("Nikola", "Tesla"), Is.SameAs(nikola));

            var randomNames = Enumerable.Range(0, 20)
                              .Select(i => new  {
                LastName  = String.Format("n°{0} - {1}", i, Guid.NewGuid().ToString()),
                FirstName = Guid.NewGuid().ToString()
            })
                              .ToArray();
            var pupils = randomNames.Select(n => c.AddPupil(n.FirstName, n.LastName)).ToArray();

            CollectionAssert.AreEqual(pupils, randomNames.Select(n => c.FindPupil(n.FirstName, n.LastName)));
        }
        public void t2_classrooms_are_created_by_school_and_have_a_unique_name()
        {
            School s = new School("Evariste Galois");

            Assert.Throws <ArgumentException>(() => s.AddClassRoom(null));
            Assert.Throws <ArgumentException>(() => s.AddClassRoom(String.Empty));

            Classroom c1 = s.AddClassRoom("CE1");

            Assert.That(c1.School, Is.SameAs(s));
            Assert.That(c1.Name, Is.EqualTo("CE1"));
            Assert.Throws <ArgumentException>(() => s.AddClassRoom("CE1"));

            Classroom c2 = s.AddClassRoom("CE2");

            Assert.That(c2.School, Is.SameAs(s));
            Assert.That(c2.Name, Is.EqualTo("CE2"));
            Assert.Throws <ArgumentException>(() => s.AddClassRoom("CE1"));

            Assert.That(typeof(Classroom).GetConstructors(BindingFlags.Instance | BindingFlags.Public), Is.Empty, "Classroom must not expose any public constructors.");
        }