示例#1
0
        /// <summary>
        /// Process the specified file and output the data in the specified sort order
        /// </summary>
        /// <param name="filename">Filename to parse</param>
        /// <param name="sortOrder"></param>
        /// <returns></returns>
        public static int ProcessFile(string filename, SortOrder sortOrder)
        {
            // Check to see if the file exists, if not throw an exception
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException("File not found", filename);
            }

            // Read all the lines of the file
            var lines = File.ReadAllLines(filename);

            var           factory = new PersonFactory();
            List <Record> records = new List <Record>();

            // For each line that isn't null or empty, parse the line and add the record to the list
            foreach (var line in lines.Where(x => !String.IsNullOrEmpty(x)))
            {
                records.Add(factory.ParseLine(line));
            }

            // Output the formatted output in the specified sort order
            System.Console.WriteLine(Output.Format(records, sortOrder));

            return(RETURN_SUCCESS);
        }
示例#2
0
文件: Tests.cs 项目: sirtwist/GR
        public void Person_BlankFirstName()
        {
            // Arrange
            string input    = "Roberts, , Male, Purple, 1973-04-11";
            Person expected = new Person()
            {
                LastName = "Roberts", FirstName = "George", Gender = Gender.Male, FavoriteColor = "Purple", DateOfBirth = new DateTime(1973, 4, 11)
            };

            // Act
            var factory = new PersonFactory();

            // Assert

            Assert.ThrowsException <FormatException>(() => factory.ParseLine(input));
        }
示例#3
0
文件: Tests.cs 项目: sirtwist/GR
        public void Input_SpaceDelimitedShouldParseSuccessfully()
        {
            // Arrange

            string input    = "Roberts George Male Purple 1973-04-11";
            Person expected = new Person()
            {
                LastName = "Roberts", FirstName = "George", Gender = Gender.Male, FavoriteColor = "Purple", DateOfBirth = new DateTime(1973, 4, 11)
            };

            // Act

            var factory = new PersonFactory();
            var actual  = factory.ParseLine(input);

            // Assert

            Assert.AreEqual <Person>(expected, (Person)actual);
        }