public XmlReaderExportLoader(Stream data)
        {
            var elements = Read(data)
                           .Select(e =>
            {
                var isRecord = e.Item1 == "Record";
                var record   = isRecord ? RecordParser.ParseRecord(e.Item2) : null;
                var workout  = isRecord ? null : WorkoutParser.Dictionary.ParseWorkout(e.Item2);
                return(new { isRecord, record, workout });
            })
                           .Aggregate(Tuple.Create(new List <Record>(), new List <Workout>()), (acc, item) =>
            {
                if (item.isRecord)
                {
                    acc.Item1.Add(item.record);
                }
                else
                {
                    acc.Item2.Add(item.workout);
                }
                return(acc);
            });

            Records  = elements.Item1;
            Workouts = elements.Item2;
        }
Esempio n. 2
0
        public void TestGetBinaryRepresentation(string hexDataRecord, int baseAddress, byte[] expectedBinaryRepresentation)
        {
            var uut = RecordParser.ParseRecord(hexDataRecord);

            var representation = uut.GetBinaryRepresentation(baseAddress);

            Assert.AreEqual(expectedBinaryRepresentation, representation);
        }
Esempio n. 3
0
        public void ParseRecord_BadDelimiter()
        {
            var data         = "Doe.John.Male.Blue.2001-01-11";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            Assert.IsNull(record);
        }
Esempio n. 4
0
        public void ParseRecord_MissingColor()
        {
            var data         = "Doe|John|Male||2001-01-01";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            Assert.IsNotNull(record);
        }
Esempio n. 5
0
        public void ParseRecord_MissingBirthDate()
        {
            var data         = "Doe|John|Male|Blue|";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            Assert.IsNotNull(record);
        }
Esempio n. 6
0
        public void ParseRecord_MixedCaseGender()
        {
            var data         = "Doe|John|mAlE|Blue|2001-01-01";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            Assert.IsNotNull(record);
        }
        public void Should_parse_correctly_when_correct_input_is_given()
        {
            var record       = "1ARNOLD/NIGELMR-B2 .L/LVGVUP";
            var recordParser = new RecordParser();

            recordParser.ParseRecord(record, out string passengerName, out string recordLocator);
            Assert.AreEqual("ARNOLD/NIGELMR", passengerName);
            Assert.AreEqual("LVGVUP", recordLocator);
        }
Esempio n. 8
0
        public void SolvePart1()
        {
            string[] records = InputParser.ReadChunksToStringArr(Day, "1");
            int      valid   = 0;

            foreach (string record in records)
            {
                Dictionary <string, string> recordMap = RecordParser.ParseRecord(record);
                if (RecordParser.ContainsRequiredFields(recordMap))
                {
                    valid++;
                }
            }
            Console.WriteLine($"Number of valid passports: {valid}");
        }
        public void ParseRecordTest(string record,
                                    int byteCount,
                                    int address,
                                    IntelHexRecordType recordType,
                                    byte[] data,
                                    byte checksum)
        {
            var intelHexRecord = RecordParser.ParseRecord(record);

            Assert.AreEqual(byteCount, intelHexRecord.ByteCount);
            Assert.AreEqual(address, intelHexRecord.Address);
            Assert.AreEqual(recordType, intelHexRecord.Type);
            Assert.AreEqual(data, intelHexRecord.Data);
            Assert.AreEqual(checksum, intelHexRecord.Checksum);
        }
Esempio n. 10
0
        public void ParseRecord_MalePipe()
        {
            var data         = "Doe|John|Male|Blue|2001-01-11";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            // Check that a Record instance was created and returned
            //
            Assert.IsNotNull(record);
            Assert.IsInstanceOfType(record, typeof(Record));

            // Check that values were correctly set
            //
            Assert.AreEqual(record.LastName, "Doe");
            Assert.AreEqual(record.FirstName, "John");
            Assert.AreEqual(record.Gender, Gender.Male);
            Assert.AreEqual(record.FavoriteColor, "Blue");
            Assert.AreEqual(record.BirthDate, new DateTime(2001, 1, 11));
        }
Esempio n. 11
0
        public void ParseRecord_FemaleSpace()
        {
            var data         = "Smith Jane Female Blue 2002-02-12";
            var recordParser = new RecordParser();
            var record       = recordParser.ParseRecord(data);

            // Check that a Record instance was created and returned
            //
            Assert.IsNotNull(record);
            Assert.IsInstanceOfType(record, typeof(Record));

            // Check that values were correctly set
            //
            Assert.AreEqual(record.LastName, "Smith");
            Assert.AreEqual(record.FirstName, "Jane");
            Assert.AreEqual(record.Gender, Gender.Female);
            Assert.AreEqual(record.FavoriteColor, "Blue");
            Assert.AreEqual(record.BirthDate, new DateTime(2002, 2, 12));
        }
Esempio n. 12
0
 public void ParseRecord_MissingData_Pipe()
 {
     var data         = "Doe|John|Male|Blue";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 13
0
 public void ParseRecord_BadBirthDate()
 {
     var data         = "Doe|John|Male|Blue|2001-a1-01";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 14
0
 public void ParseRecord_NoData()
 {
     var data         = "";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 15
0
 public void ParseRecord_OnlyWhiteSpace()
 {
     var data         = "   ";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 16
0
 public void ParseRecord_BadGender()
 {
     var data         = "Doe|John|Mail|Blue|2001-01-01";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 17
0
 public void ParseRecord_MissingLastName()
 {
     var data         = "|John|Male|Blue|2001-01-01";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 18
0
 public void ParseRecord_TooManyFields_Pipe()
 {
     var data         = "Doe|John|Male|Blue|2001-01-01|Programmer";
     var recordParser = new RecordParser();
     var record       = recordParser.ParseRecord(data);
 }
Esempio n. 19
0
        public void CalculateChecksumShouldCalculateTheCorrectChecksum(string record, byte checksum)
        {
            var sut = RecordParser.ParseRecord(record);

            Assert.AreEqual(checksum, sut.CalculateChecksum());
        }