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 T6_line_with_no_stations_doesnt_throw() { ICity s = CityFactory.CreateCity("Paris"); ILine p1 = s.AddLine("K"); Action a = () => p1.Stations.Count(); a.ShouldNotThrow(); }
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 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_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 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(); }
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 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 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 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 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 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(); }