public void T4_trains_can_be_found_by_name()
        {
            ICity s = CityFactory.CreateCity("Paris");

            ICompany c1 = s.AddCompany("Transports de Lyon");
            ICompany c2 = s.AddCompany("Transports de Marseille");

            ITrain t1 = c1.AddTrain("RER1");

            c1.FindTrain("RER1").Should().BeSameAs(t1);
            c2.FindTrain("RER1").Should().BeNull();


            ITrain t2 = c2.AddTrain("RER1");

            c2.FindTrain("RER1").Should().BeSameAs(t2);
            c1.FindTrain("RER1").Should().NotBeSameAs(t2);


            ITrain t3 = c1.AddTrain("RER2");
            ITrain t4 = c1.AddTrain("RER3");
            ITrain t5 = c1.AddTrain("RER4");

            c1.FindTrain("RER2").Should().BeSameAs(t3);
            c1.FindTrain("RER3").Should().BeSameAs(t4);
            c1.FindTrain("RER4").Should().BeSameAs(t5);

            c2.FindTrain("RER2").Should().BeNull();
            c2.FindTrain("RER3").Should().BeNull();
            c2.FindTrain("RER4").Should().BeNull();
        }
        private static ICity CreateTestCity()
        {
            ICity    city = CityFactory.CreateCity("First City");
            ICompany c1   = city.AddCompany("C01");
            ITrain   t1   = c1.AddTrain("T01");
            ICompany c2   = city.AddCompany("C02");
            ITrain   t2   = c2.AddTrain("T02");

            return(city);
        }
        public void T4_trains_are_created_by_companies_and_have_a_unique_name()
        {
            ICity    s = CityFactory.CreateCity("Paris");
            ICompany c = s.AddCompany("SNCF");

            Action a = () => c.AddTrain(null);

            a.ShouldThrow <ArgumentException>();


            ITrain p1 = c.AddTrain("train1");

            p1.Company.Should().BeSameAs(c);
            p1.Name.Should().BeEquivalentTo("train1");
            p1.Assignment.Should().BeNull();
            Action a1 = () => c.AddTrain("train1");

            a1.ShouldThrow <ArgumentException>();


            ITrain p2 = c.AddTrain("train2");

            p2.Company.Should().BeSameAs(c);
            p2.Name.Should().BeEquivalentTo("train2");
            p2.Assignment.Should().BeNull();
            Action a2 = () => c.AddTrain("train2");

            a2.ShouldThrow <ArgumentException>();

            p1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Train.Name must NOT be writeable.");
            p1.GetType().GetProperty("Assignment").GetSetMethod().Should().BeNull("Train.Assignment must NOT be writeable.");
            p1.GetType().GetProperty("City").GetSetMethod().Should().BeNull("Train.City must NOT be writeable.");
            p1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Train must not expose any public constructors.");
        }
        private static ICity CreateTestCity()
        {
            ICity    city    = CityFactory.CreateCity("Paris");
            ICompany company = city.AddCompany("ITICORP");
            ITrain   train   = company.AddTrain("TGV");

            return(city);
        }
        public void T1_companies_can_be_found_by_name()
        {
            ICity    s  = CityFactory.CreateCity("Paris");
            ICompany c1 = s.AddCompany("SNCF");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeNull();

            ICompany c2 = s.AddCompany("RATP");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeSameAs(c2);
            s.FindCompany("Transports de Lyon").Should().BeNull();


            ICompany c3 = s.AddCompany("Transports de Lyon");
            ICompany c4 = s.AddCompany("Transports de Marseille");
            ICompany c5 = s.AddCompany("Transports de Lille");

            s.FindCompany("SNCF").Should().BeSameAs(c1);
            s.FindCompany("RATP").Should().BeSameAs(c2);
            s.FindCompany("Transports de Lyon").Should().BeSameAs(c3);
            s.FindCompany("Transports de Marseille").Should().BeSameAs(c4);
            s.FindCompany("Transports de Lille").Should().BeSameAs(c5);


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

            teachers.Should().BeEquivalentTo(randomNames.Select(n => s.FindCompany(n)));
        }
        public void T2_companies_are_created_by_cities_and_have_a_unique_name()
        {
            ICity s = CityFactory.CreateCity("Paris");

            Action a = () => s.AddCompany(null);

            a.ShouldThrow <ArgumentException>();
            Action ab = () => s.AddCompany(String.Empty);

            ab.ShouldThrow <ArgumentException>();


            ICompany c1 = s.AddCompany("SNCF");

            c1.City.Should().BeSameAs(s);
            c1.Name.Should().BeEquivalentTo("SNCF");
            Action a1 = () => s.AddCompany("SNCF");

            a1.ShouldThrow <ArgumentException>();

            ICompany c2 = s.AddCompany("RATP");

            c2.City.Should().BeSameAs(s);
            c2.Name.Should().BeEquivalentTo("RATP");
            Action a2 = () => s.AddCompany("RATP");

            a2.ShouldThrow <ArgumentException>();

            c2.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Company must not expose any public constructors.");
            c2.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Company.Name must NOT be writeable.");
            c2.GetType().GetProperty("City").GetSetMethod().Should().BeNull("Company.City must NOT be writeable.");
        }
Beispiel #7
0
        public void T5_line_can_have_mutiple_trains()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");
            ITrain   t2 = c1.AddTrain("RER2");

            t1.AssignTo(l1);
            t2.AssignTo(l1);
            l1.Trains.Count().Should().Be(2);
            l1.Trains.Contains(t1).Should().BeTrue();
            l1.Trains.Contains(t2).Should().BeTrue();

            t1.AssignTo(null);
            l1.Trains.Single().Should().BeSameAs(t2);
        }
Beispiel #8
0
        public void T2_when_a_train_is_assigned_to_a_line_he_losts_its_previous_line()
        {
            ICity    s  = CityFactory.CreateCity("Paris");
            ICompany c  = s.AddCompany("SNCF");
            ILine    l1 = s.AddLine("RER A");
            ILine    l2 = s.AddLine("RER B");
            ITrain   t1 = c.AddTrain("RER1");

            t1.AssignTo(l1);

            t1.Assignment.Should().BeSameAs(l1);

            t1.AssignTo(l2);
            t1.Assignment.Should().BeSameAs(l2);
            l1.Trains.Count().Should().Be(0);
            l2.Trains.Single().Should().BeSameAs(t1);
        }
Beispiel #9
0
        public void T4_assigning_a_train_to_a_null_line_removes_its_assignment()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");

            Action a1 = () => t1.AssignTo(null);

            a1.ShouldNotThrow();

            t1.AssignTo(l1);
            t1.Assignment.Should().BeSameAs(l1);

            t1.AssignTo(null);
            t1.Assignment.Should().BeNull();
            l1.Trains.Count().Should().Be(0);
        }
Beispiel #10
0
        public void T3_trains_and_lines_must_belong_to_the_same_city()
        {
            ICity    s1 = CityFactory.CreateCity("Paris");
            ICompany c1 = s1.AddCompany("SNCF");
            ILine    l1 = s1.AddLine("RER A");
            ITrain   t1 = c1.AddTrain("RER1");

            ICity    s2 = CityFactory.CreateCity("Lyon");
            ICompany c2 = s2.AddCompany("SNCF");
            ILine    l2 = s2.AddLine("RER A");
            ITrain   t2 = c2.AddTrain("RER1");

            Action a1 = () => t1.AssignTo(l1);
            Action a2 = () => t1.AssignTo(l2);

            a1.ShouldNotThrow();
            a2.ShouldThrow <ArgumentException>();
        }
Beispiel #11
0
        public void T1_trains_can_be_assigned_to_a_line()
        {
            ICity    s = CityFactory.CreateCity("Paris");
            ICompany c = s.AddCompany("SNCF");

            ITrain t1 = c.AddTrain("RER1");
            ITrain t2 = c.AddTrain("RER2");

            t1.Assignment.Should().BeNull();
            t2.Assignment.Should().BeNull();

            ILine l = s.AddLine("RER A");

            t1.AssignTo(l);
            t1.Assignment.Should().BeSameAs(l);
            t2.Assignment.Should().BeNull();
            l.Trains.Count().Should().Be(1);
            l.Trains.Single().Should().BeSameAs(t1);
        }