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 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.");
        }
Ejemplo n.º 3
0
        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)));
        }