public void Test_Save_TravelPlan() { //Arrange StationORM stationFile = new StationORM("Data/stations.txt"); TimetableORM timetableFile = new TimetableORM("Data/timetable.txt"); TrainORM trainFile = new TrainORM("Data/trains.txt"); new StationORM("Data/stations.txt"); TrackORM newTrack = new TrackORM("Data/traintrack2.txt", stationFile.Stations); Train train = trainFile.Trains[1]; // Create the travel plan and save it to file. new TrainPlanner(train) .AddStations(stationFile.Stations) .AddTimetable(timetableFile.Timetable.Where(stop => stop.TrainId == train.Id).ToList()) .GeneratePlan() .SavePlan(); string expectedFileContent = "{\"Stations\":[{\"ID\":1,\"Name\":\"Stonecro\",\"Distance\":0,\"EndStation\":true},{\"ID\":2,\"Name\":\"Mount Juanceo\",\"Distance\":120,\"EndStation\":false},{\"ID\":3,\"Name\":\"Grand Retro\",\"Distance\":130,\"EndStation\":true}],\"Timetable\":[{\"TrainId\":2,\"StationId\":1,\"DepartureTime\":{\"TickInterval\":100,\"Hours\":10,\"Minutes\":20,\"TimeThread\":null},\"ArrivalTime\":null,\"HasDeparted\":false},{\"TrainId\":2,\"StationId\":2,\"DepartureTime\":{\"TickInterval\":100,\"Hours\":12,\"Minutes\":0,\"TimeThread\":null},\"ArrivalTime\":null,\"HasDeparted\":false},{\"TrainId\":2,\"StationId\":3,\"DepartureTime\":null,\"ArrivalTime\":null,\"HasDeparted\":false}],\"Train\":{\"Id\":2,\"Name\":\"Golden Arrow\",\"Speed\":120,\"Color\":6}}"; string actualOutputFile = File.ReadAllText(@"C:\Temp\travelplan-train2.json"); //Assert Assert.Equal(expectedFileContent, actualOutputFile); }
public void When_ScheduleORMLoadsFile_Validate_OneSTopForEachTrain() { //Arrange TimetableORM timetableFile = new TimetableORM("Data/timetable.txt"); //Assert Assert.IsType <TimetableORM>(timetableFile); Assert.Equal(2, timetableFile.Timetable[0].TrainId); Assert.Equal(1, timetableFile.Timetable[0].StationId); Assert.Equal("10:20", timetableFile.Timetable[0].DepartureTime.ToString()); Assert.Equal(3, timetableFile.Timetable[3].TrainId); Assert.Equal(1, timetableFile.Timetable[3].StationId); Assert.Equal("10:23", timetableFile.Timetable[3].DepartureTime.ToString()); }
static void Main(string[] args) { Console.CursorVisible = false; TimetableORM timetableFile = new TimetableORM("Data/timetable.txt"); TrainORM trainFile = new TrainORM("Data/trains.txt"); StationORM stationFile = new StationORM("Data/stations.txt"); new TrackORM("Data/traintrack2.txt", stationFile.Stations); List <ITravelPlan> travelPlans = new List <ITravelPlan>(); foreach (Train train in trainFile.Trains) { // Create the travel plan for the train "newTrain". ITravelPlan travelPlan = new TrainPlanner(train) .AddStations(stationFile.Stations) .AddTimetable(timetableFile.Timetable) .GeneratePlan(); // Save the travel plan to file travelPlan.SavePlan(); // Save the travel to a list travelPlans.Add(travelPlan); } // Create a fakeTime object which we can send into the travel plan "simulator". FakeTime fakeTime = new FakeTime(10, 00); System.Console.WriteLine("The Train Simulator"); foreach (var travelPlan in travelPlans) { travelPlan.Simulate(fakeTime); } // Start the time after all travelplan simulations have been instantiated. fakeTime.StartTime(); TravelPlan travelPlan1 = new TravelPlan(); travelPlan1.LoadPlan(@"C:\Temp\travelplan-train2.json"); }