public void returns_expected_result_with_new_record()
        {
            var recordParser   = BuildParser();
            var recordToParse  = "AANL82468L839221512191601020000010   CLCHSTR  T                                C";
            var expectedResult = new AssociationRecord
            {
                RecordIdentity      = ScheduleRecordType.AAN,
                MainTrainUid        = "L82468",
                AssocTrainUid       = "L83922",
                DateFrom            = new DateTime(2015, 12, 19),
                DateTo              = new DateTime(2016, 1, 2),
                AssocDays           = Days.Saturday,
                Category            = AssociationCategory.None,
                DateIndicator       = DateIndicator.None,
                Location            = "CLCHSTR",
                BaseLocationSuffix  = string.Empty,
                AssocLocationSuffix = string.Empty,
                DiagramType         = "T",
                AssocType           = AssociationType.None,
                StpIndicator        = StpIndicator.C
            };

            var result = recordParser.ParseRecord(recordToParse);

            Assert.AreEqual(expectedResult, result);
        }
        public void returns_expected_result_with_revise_record()
        {
            var recordParser   = BuildParser();
            var recordToParse  = "AARW01400W005701512131602070000001   ORPNGTN  T                                C";
            var expectedResult = new AssociationRecord
            {
                RecordIdentity      = ScheduleRecordType.AAR,
                MainTrainUid        = "W01400",
                AssocTrainUid       = "W00570",
                DateFrom            = new DateTime(2015, 12, 13),
                DateTo              = new DateTime(2016, 2, 7),
                AssocDays           = Days.Sunday,
                Category            = AssociationCategory.None,
                DateIndicator       = DateIndicator.None,
                Location            = "ORPNGTN",
                BaseLocationSuffix  = string.Empty,
                AssocLocationSuffix = string.Empty,
                DiagramType         = "T",
                AssocType           = AssociationType.None,
                StpIndicator        = StpIndicator.C
            };

            var result = recordParser.ParseRecord(recordToParse);

            Assert.AreEqual(expectedResult, result);
        }
        public void returns_expected_result_with_new_record()
        {
            var recordParser = BuildParser();
            var recordToParse = "AANL82468L839221512191601020000010   CLCHSTR  T                                C";
            var expectedResult = new AssociationRecord
            {
                RecordIdentity = ScheduleRecordType.AAN,
                MainTrainUid = "L82468",
                AssocTrainUid = "L83922",
                DateFrom = new DateTime(2015, 12, 19),
                DateTo = new DateTime(2016, 1, 2),
                AssocDays = Days.Saturday,
                Category = AssociationCategory.None,
                DateIndicator = DateIndicator.None,
                Location = "CLCHSTR",
                BaseLocationSuffix = string.Empty,
                AssocLocationSuffix = string.Empty,
                DiagramType = "T",
                AssocType = AssociationType.None,
                StpIndicator = StpIndicator.C
            };

            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 AssociationRecord
            {
                RecordIdentity = (ScheduleRecordType)_enumPropertyParsers["ScheduleRecordType"].ParseProperty(recordString.Substring(0, 3)),
                MainTrainUid   = recordString.Substring(3, 6),
                AssocTrainUid  = recordString.Substring(9, 6),
                DateTo         = _dateTimeParser.ParseDateTime(new DateTimeParserRequest
                {
                    DateTimeFormat = "yyMMdd",
                    DateTimeString = recordString.Substring(21, 6)
                }),
                AssocDays           = (Days)_enumPropertyParsers["RunningDays"].ParseProperty(recordString.Substring(27, 7)),
                Category            = (AssociationCategory)_enumPropertyParsers["AssociationCategory"].ParseProperty(recordString.Substring(34, 2)),
                DateIndicator       = (DateIndicator)_enumPropertyParsers["DateIndicator"].ParseProperty(recordString.Substring(36, 1)),
                Location            = recordString.Substring(37, 7).Trim(),
                BaseLocationSuffix  = recordString.Substring(44, 1).Trim(),
                AssocLocationSuffix = recordString.Substring(45, 1).Trim(),
                DiagramType         = recordString.Substring(46, 1).Trim(),
                StpIndicator        = (StpIndicator)_enumPropertyParsers["StpIndicator"].ParseProperty(recordString.Substring(79, 1))
            };

            var dateFromResult = _dateTimeParser.ParseDateTime(new DateTimeParserRequest
            {
                DateTimeFormat = "yyMMdd",
                DateTimeString = recordString.Substring(15, 6)
            });

            if (dateFromResult.HasValue)
            {
                record.DateFrom = dateFromResult.Value;
            }
            else
            {
                throw new ArgumentException("Failed to parse Date From for Association record.");
            }

            return(record);
        }
        public void returns_expected_result_with_revise_record()
        {
            var recordParser = BuildParser();
            var recordToParse = "AARW01400W005701512131602070000001   ORPNGTN  T                                C";
            var expectedResult = new AssociationRecord
            {
                RecordIdentity = ScheduleRecordType.AAR,
                MainTrainUid = "W01400",
                AssocTrainUid = "W00570",
                DateFrom = new DateTime(2015, 12, 13),
                DateTo = new DateTime(2016, 2, 7),
                AssocDays = Days.Sunday,
                Category = AssociationCategory.None,
                DateIndicator = DateIndicator.None,
                Location = "ORPNGTN",
                BaseLocationSuffix = string.Empty,
                AssocLocationSuffix = string.Empty,
                DiagramType = "T",
                AssocType = AssociationType.None,
                StpIndicator = StpIndicator.C
            };

            var result = recordParser.ParseRecord(recordToParse);

            Assert.AreEqual(expectedResult, result);
        }