public void T3_lines_are_created_by_cities_and_have_a_unique_name() { ICity s = CityFactory.CreateCity("Paris"); Action a = () => s.AddLine(null); a.ShouldThrow <ArgumentException>(); Action ab = () => s.AddLine(String.Empty); ab.ShouldThrow <ArgumentException>(); ILine c1 = s.AddLine("RER A"); c1.City.Should().BeSameAs(s); c1.Name.Should().BeEquivalentTo("RER A"); Action a1 = () => s.AddLine("RER A"); a1.ShouldThrow <ArgumentException>(); ILine c2 = s.AddLine("RER B"); c2.City.Should().BeSameAs(s); c2.Name.Should().BeEquivalentTo("RER B"); Action a2 = () => s.AddLine("RER B"); a2.ShouldThrow <ArgumentException>(); c1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Line.Name must NOT be writeable."); c1.GetType().GetProperty("City").GetSetMethod().Should().BeNull("Line.City must NOT be writeable."); c1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Line must not expose any public constructors."); }
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 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."); }
public void T2_lines_can_be_found_by_name() { ICity c = CityFactory.CreateCity("Paris"); ILine l1 = c.AddLine("1"); c.FindLine("1").Should().BeSameAs(l1); c.FindLine("2").Should().BeNull(); ILine l2 = c.AddLine("2"); c.FindLine("1").Should().BeSameAs(l1); c.FindLine("2").Should().BeSameAs(l2); c.FindLine("3").Should().BeNull(); ILine l3 = c.AddLine("3"); ILine l4 = c.AddLine("4"); ILine l5 = c.AddLine("5"); c.FindLine("1").Should().BeSameAs(l1); c.FindLine("2").Should().BeSameAs(l2); c.FindLine("3").Should().BeSameAs(l3); c.FindLine("4").Should().BeSameAs(l4); c.FindLine("5").Should().BeSameAs(l5); var randomNames = Enumerable.Range(0, 20) .Select(i => String.Format("n°{0} - {1}", i, Guid.NewGuid().ToString())) .ToArray(); var lines = randomNames.Select(n => c.AddLine(n)).ToArray(); lines.Should().BeEquivalentTo(randomNames.Select(n => c.FindLine(n))); }
public void T3_stations_can_be_found_by_name() { ICity s = CityFactory.CreateCity("Paris"); IStation c1 = s.AddStation("Opera", 0, 0); s.FindStation("Opera").Should().BeSameAs(c1); s.FindStation("Chatelet").Should().BeNull(); IStation c2 = s.AddStation("Chatelet", 1, 1); s.FindStation("Opera").Should().BeSameAs(c1); s.FindStation("Chatelet").Should().BeSameAs(c2); s.FindStation("Ivry").Should().BeNull(); IStation c3 = s.AddStation("Ivry", 2, 2); IStation c4 = s.AddStation("Villejuif", 3, 3); IStation c5 = s.AddStation("Bourse", 4, 4); s.FindStation("Opera").Should().BeSameAs(c1); s.FindStation("Chatelet").Should().BeSameAs(c2); s.FindStation("Ivry").Should().BeSameAs(c3); s.FindStation("Villejuif").Should().BeSameAs(c4); s.FindStation("Bourse").Should().BeSameAs(c5); }
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("Paris"); ICompany company = city.AddCompany("ITICORP"); ITrain train = company.AddTrain("TGV"); return(city); }
public void T6_line_with_no_stations_doesnt_throw() { ICity s = CityFactory.CreateCity("Paris"); ILine p1 = s.AddLine("K"); Action a = () => p1.Stations.Count(); a.ShouldNotThrow(); }
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 T1_stations_can_be_assigned_to_a_line() { ICity c = CityFactory.CreateCity("Paris"); ILine l1 = c.AddLine("RER A"); IStation s1 = c.AddStation("Opera", 0, 0); IStation s2 = c.AddStation("Chatelet", 1, 1); l1.Stations.Count().Should().Be(0); s1.Lines.Count().Should().Be(0); s2.Lines.Count().Should().Be(0); Action a1 = () => l1.AddBefore(null, null); a1.ShouldThrow <ArgumentException>(); Action a2 = () => l1.AddBefore(s1, null); a2.ShouldNotThrow(); l1.Next(s1).Should().BeNull(); l1.Previous(s1).Should().BeNull(); s1.Lines.Count().Should().Be(1); s1.Lines.Count().Should().Be(1); s2.Lines.Count().Should().Be(0); s1.Lines.Single().Should().BeSameAs(l1); Action a3 = () => l1.Next(s2); a3.ShouldThrow <ArgumentException>(); Action a4 = () => l1.Previous(s2); a4.ShouldThrow <ArgumentException>(); l1.Stations.Single().Should().BeSameAs(s1); Action a5 = () => l1.AddBefore(s2, s1); a5.ShouldNotThrow(); l1.Stations.Count().Should().Be(2); s1.Lines.Count().Should().Be(1); s2.Lines.Count().Should().Be(1); l1.Next(s2).Should().BeSameAs(s1); l1.Previous(s1).Should().BeSameAs(s2); l1.Next(s1).Should().BeNull(); l1.Previous(s2).Should().BeNull(); s1.Lines.Single().Should().BeSameAs(l1); s2.Lines.Single().Should().BeSameAs(l1); }
public void T3_stations_cant_be_2_times_on_a_line() { ICity c = CityFactory.CreateCity("Paris"); ILine l = c.AddLine("RER B"); IStation s = c.AddStation("Opera", 0, 0); l.AddBefore(s); Action a1 = () => l.AddBefore(s); a1.ShouldThrow <ArgumentException>(); }
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); }
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); }
public void T5_stations_are_created_by_cities_and_have_a_unique_name() { ICity s = CityFactory.CreateCity("Paris"); IStation p1 = s.AddStation("Opera", 0, 0); p1.City.Should().BeSameAs(s); p1.Name.Should().BeEquivalentTo("Opera"); p1.X.Should().Be(0); p1.Y.Should().Be(0); Action a = () => s.AddStation("Opera", 0, 0); a.ShouldThrow <ArgumentException>(); Action a1 = () => s.AddStation("Opera", 10, 0); a1.ShouldThrow <ArgumentException>(); Action a2 = () => s.AddStation("Opera", 0, 10); a2.ShouldThrow <ArgumentException>(); IStation p2 = s.AddStation("Chatelet", 1, 1); p2.City.Should().BeSameAs(s); p2.Name.Should().BeEquivalentTo("Chatelet"); p2.X.Should().Be(1); p2.Y.Should().Be(1); Action a4 = () => s.AddStation("Chatelet", 0, 0); a4.ShouldThrow <ArgumentException>(); Action a5 = () => s.AddStation("Chatelet", 10, 0); a5.ShouldThrow <ArgumentException>(); Action a6 = () => s.AddStation("Chatelet", 0, 10); a6.ShouldThrow <ArgumentException>(); Action a7 = () => s.AddStation("Same Place Station", 0, 0); a7.ShouldThrow <ArgumentException>(); p1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("Lane.Name must NOT be writeable."); p1.GetType().GetProperty("X").GetSetMethod().Should().BeNull("Lane.X must NOT be writeable."); p1.GetType().GetProperty("Y").GetSetMethod().Should().BeNull("Lane.Y must NOT be writeable."); p1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Train must not expose any public constructors."); }
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); }
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>(); }
public void T4_stations_can_be_removed() { ICity c = CityFactory.CreateCity("Paris"); ILine l = c.AddLine("RER B"); IStation s = c.AddStation("Opera", 0, 0); Action a1 = () => l.Remove(s); a1.ShouldThrow <ArgumentException>(); l.AddBefore(s); Action a2 = () => l.Remove(s); a2.ShouldNotThrow(); l.Stations.Count().Should().Be(0); s.Lines.Count().Should().Be(0); }
public void T5_stations_can_be_removed_then_re_added() { ICity c = CityFactory.CreateCity("Paris"); ILine l = c.AddLine("RER B"); IStation s = c.AddStation("Opera", 0, 0); l.AddBefore(s); s.Lines.Count().Should().Be(1); l.Remove(s); s.Lines.Count().Should().Be(0); Action a1 = () => l.AddBefore(s); a1.ShouldNotThrow(); l.Stations.Count().Should().Be(1); s.Lines.Count().Should().Be(1); }
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); }
public void T1_creating_named_cities() { Action a = () => CityFactory.CreateCity(null); a.ShouldThrow <ArgumentException>(); Action ab = () => CityFactory.CreateCity(String.Empty); ab.ShouldThrow <ArgumentException>(); { ICity s = CityFactory.CreateCity("Paris"); s.Name.Should().BeEquivalentTo("Paris"); } { var randomName = Guid.NewGuid().ToString(); ICity s = CityFactory.CreateCity(randomName); s.Name.Should().BeEquivalentTo(randomName); } ICity s1 = CityFactory.CreateCity("getType"); s1.GetType().GetProperty("Name").GetSetMethod().Should().BeNull("City.Name must NOT be writeable."); s1.GetType().GetConstructors(BindingFlags.Instance | BindingFlags.Public).Should().BeEmpty("Company must not expose any public constructors."); }
public void T6_lines_should_start_and_end_with_null() { ICity c = CityFactory.CreateCity("Paris"); ILine l = c.AddLine("RER B"); IStation s = c.AddStation("0", 0, 0); IStation s1 = c.AddStation("1", 1, 0); IStation s2 = c.AddStation("2", 2, 0); IStation s3 = c.AddStation("3", 3, 0); IStation s4 = c.AddStation("4", 4, 0); l.AddBefore(s); l.AddBefore(s1); l.AddBefore(s2); l.AddBefore(s3); l.AddBefore(s4); l.Stations.Count().Should().Be(5); l.Previous(s4).Should().BeNull(); l.Next(s4).Should().BeSameAs(s3); l.Next(s3).Should().BeSameAs(s2); l.Next(s2).Should().BeSameAs(s1); l.Next(s1).Should().BeSameAs(s); l.Next(s).Should().BeNull(); }
public void T2_station_can_be_on_2_lines() { ICity c = CityFactory.CreateCity("Paris"); ILine l1 = c.AddLine("RER A"); ILine l2 = c.AddLine("RER B"); IStation s = c.AddStation("Opera", 0, 0); Action a1 = () => l1.AddBefore(s, null); a1.ShouldNotThrow(); Action a2 = () => l2.AddBefore(s, null); a2.ShouldNotThrow(); l1.Stations.Single().Should().BeSameAs(l2.Stations.Single()); l1.Stations.Single().Should().BeSameAs(s); l2.Stations.Single().Should().BeSameAs(s); s.Lines.Count().Should().Be(2); s.Lines.Contains(l1).Should().BeTrue(); s.Lines.Contains(l2).Should().BeTrue(); }