public void Copy_Route() { // Arange int routeId = 1; string routeCode = "RouteCode1"; string routeName = "RouteName1"; string newRouteName = "00:10 Pier 1 to Pier 5"; DateTime startDate = new DateTime(2013, 06, 01); DateTime endDate = new DateTime(2013, 07, 01); int timeTableId = 1; string timeTableCode = "TimeTableCode1"; string timeTableName = "TimeTableName1"; TimeTable TimeTable = new TimeTable { Id = timeTableId, Code = timeTableCode, Name = timeTableName }; List<Schedule> schedules = new List<Schedule>(); Route oldRoute = new Route() { Id = routeId , Code = routeCode, Name = routeName, TimeTableId = timeTableId, TimeTable = TimeTable }; string[] pierNames = { "Pier 1", "Pier 2", "Pier 3", "Pier 4", "Pier 5" }; int[] pierIds = { 1, 2, 3, 4, 5 }; for (int i = 0; i < 5; i++) { schedules.Add(new Schedule { Id = i, Name = "Schedule " + i.ToString(), Pier = new Pier { Id = pierIds[i], Name = pierNames[i] }, Route = oldRoute, Time = new TimeSpan(i, 0, 0) }); } oldRoute.Schedules = schedules; TimeSpan increment = new TimeSpan(0, 10, 0); // Act Route newRoute = oldRoute.Copy(increment); var timeTableIsCorrect = oldRoute.Schedules.Zip(newRoute.Schedules, (s1, s2) => s1.Time == (s2.Time - increment)); // Assert Assert.AreNotSame(newRoute, oldRoute); // Not the same object Assert.IsTrue(timeTableIsCorrect.All(timeTable => timeTable)); // Increment has been applied // Check properties Assert.AreEqual(newRoute.Id, routeId); Assert.AreEqual(newRoute.Code, routeCode); Assert.AreEqual(newRoute.Name, newRouteName); Assert.AreEqual(newRoute.TimeTableId, timeTableId); }
public void Copy_Route_Over_24h() { // Arange TimeSpan currentTimeSpan = new TimeSpan(23, 50, 00); TimeSpan newTimeSpan = new TimeSpan(00, 10, 00); TimeSpan increment = new TimeSpan(0, 20, 0); Route route = new Route { Name = "Route 1", Schedules = new List<Schedule> { new Schedule { Time = currentTimeSpan, Pier = new Pier { Name = "Pier" } } } }; // Act Route newRoute = route.Copy(increment); // Assert Assert.AreEqual(newTimeSpan, newRoute.Schedules[0].Time.Value); }