Esempio n. 1
0
        public void Parse2()
        {
            var input = new List <string> {
                "first1,last1,gender1,color1,11/11/2016", "first2,last2, gender2, color2, 11/11/2016"
            };
            var output = new List <Record> {
                new Record("first1", "last1", "gender1", "color1", Convert.ToDateTime("11/11/2016")), new Record("first2", "last2", "gender2", "color2", Convert.ToDateTime("11/11/2016"))
            };
            var res = RecordParser.ParseLines(input);

            Assert.Equal(res, output);
        }
        public void ParseFailInputLength()
        {
            var input = new List <string> {
                "first1,last1,gender1,color1,11/11/2016", "first2,last2, gender2, color2, 11/11/2016"
            };
            var output = new List <Code.Record> {
                new Code.Record("first", "last", "gender", "color", Convert.ToDateTime("11/11/2016")), new Code.Record("first", "last", "gender", "color", Convert.ToDateTime("11/11/2016"))
            };
            var res = RecordParser.ParseLines(new List <string>());

            Assert.Equal(res, res);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //argument checks
            if (args.Length != 3)
            {
                Console.WriteLine("3 filepaths required");
                return;
            }
            //validate arguments lead to files
            foreach (var arg in args)
            {
                if (!File.Exists(arg))
                {
                    Console.WriteLine($"No file exists at {arg}");
                    return;
                }
            }

            //Add records for each file to RecordList
            var recordList = new List <Record>();

            foreach (var arg in args)
            {
                List <string> fileInput = new List <string>();
                using (var reader = new StreamReader(arg))
                {
                    //Parse file
                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        fileInput.Add(line);
                    }
                }
                recordList.AddRange(RecordParser.ParseLines(fileInput));
            }

            //Output 1 – sorted by gender(females before males) then by last name ascending.
            Console.WriteLine("Output 1 – sorted by gender(females before males) then by last name ascending");
            recordList = recordList.OrderBy(x => x.Gender).ThenBy(x => x.LastName).ToList();
            OutputRecordsToConsole(recordList);

            //Output 2 – sorted by birth date, ascending.
            Console.WriteLine("Output 2 – sorted by birth date, ascending.");
            recordList = recordList.OrderBy(x => x.DateOfBirth).ToList();
            OutputRecordsToConsole(recordList);

            //Output 3 – sorted by last name, descending.
            Console.WriteLine("Output 3 – sorted by last name, descending.");
            recordList = recordList.OrderByDescending(x => x.LastName).ToList();
            OutputRecordsToConsole(recordList);
        }
Esempio n. 4
0
        public void ParseEmpty()
        {
            var res = RecordParser.ParseLines(new List <string>());

            Assert.Equal(res, new List <Record>());
        }