public void returns_expected_result() { var recordParser = BuildParser(); var recordToParse = "CRHULL XX1J22 111808920 DMUS 075 S S "; var expectedResult = new ChangesEnRouteRecord { RecordIdentity = ScheduleRecordType.CR, Tiploc = "HULL", TiplocSuffix = string.Empty, Category = "XX", TrainIdentity = "1J22", HeadCode = string.Empty, CourseIndicator = "1", ServiceCode = "11808920", PortionId = string.Empty, PowerType = PowerType.DMU, TimingLoad = "S", Speed = 075, OperatingCharacteristics = string.Empty, SeatingClass = SeatingClass.S, Sleepers = SleeperDetails.NotAvailable, Reservations = ReservationDetails.S, ConnectionIndicator = string.Empty, CateringCode = 0, ServiceBranding = ServiceBranding.None, UicCode = string.Empty, Rsid = string.Empty }; var result = recordParser.ParseRecord(recordToParse); Assert.AreEqual(expectedResult, result); }
public IScheduleRecord ParseRecord(string recordString) { if (string.IsNullOrWhiteSpace(recordString)) { throw new ArgumentNullException(nameof(recordString)); } var record = new ChangesEnRouteRecord { RecordIdentity = ScheduleRecordType.CR, Tiploc = recordString.Substring(2, 7).Trim(), TiplocSuffix = recordString.Substring(9, 1).Trim(), Category = recordString.Substring(10, 2).Trim(), TrainIdentity = recordString.Substring(12, 4).Trim(), HeadCode = recordString.Substring(16, 4).Trim(), CourseIndicator = recordString.Substring(20, 1).Trim(), ServiceCode = recordString.Substring(21, 8).Trim(), PortionId = recordString.Substring(29, 1).Trim(), PowerType = (PowerType)_enumPropertyParsers["PowerType"].ParseProperty(recordString.Substring(30, 3).Trim()), TimingLoad = recordString.Substring(33, 4).Trim(), OperatingCharacteristics = recordString.Substring(40, 6).Trim(), SeatingClass = (SeatingClass)_enumPropertyParsers["SeatingClass"].ParseProperty(recordString.Substring(46, 1)), Sleepers = (SleeperDetails)_enumPropertyParsers["SleeperDetails"].ParseProperty(recordString.Substring(47, 1)), Reservations = (ReservationDetails)_enumPropertyParsers["ReservationDetails"].ParseProperty(recordString.Substring(48, 1)), ConnectionIndicator = recordString.Substring(49, 1).Trim(), CateringCode = (CateringCode)_enumPropertyParsers["CateringCode"].ParseProperty(recordString.Substring(50, 4).Trim()), ServiceBranding = (ServiceBranding)_enumPropertyParsers["ServiceBranding"].ParseProperty(recordString.Substring(54, 4).Trim()), UicCode = recordString.Substring(58, 5).Trim(), Rsid = recordString.Substring(63, 8).Trim() }; int speed; var speedParsed = int.TryParse(recordString.Substring(37, 3).Trim(), NumberStyles.Any, new CultureInfo("en-gb"), out speed); if (speedParsed) { record.Speed = speed; } return(record); }