public RecordsController() { if (_recordManager == null) { _recordManager = new RecordManager(); } }
static void Main(string[] args) { RecordManager recordParser = new RecordManager(); var appFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PersonalRecordsFiles"); if (!Directory.Exists(appFolder)) throw new DirectoryNotFoundException("Could not find the directory with personal records"); var files = Directory.GetFiles(appFolder); if (0 == files.Count()) throw new FileNotFoundException("Could not find any files to process in directory " + appFolder); foreach(var file in files) { string[] lines = System.IO.File.ReadAllLines(file); foreach(var line in lines) { if(0 < line.Length) recordParser.AddPersonalRecord(line); } } Console.WriteLine("To retrieve sorted records, enter one of the following commands and press enter."); Console.WriteLine("Sorted by gender and then last name: gender\nSorted by birthday: birthday\nSorted by last name desc: lastname"); while(true) { var command = Console.ReadLine(); List<PersonalRecord> personalRecords = new List<PersonalRecord>(); switch(command) { case "gender": personalRecords = recordParser.GetRecordsSortedByGender(); break; case "birthday": personalRecords = recordParser.GetRecordsSortedByBirthday(); break; case "lastname": personalRecords = recordParser.GetRecordsSortedByLastName(); break; default: Console.WriteLine("Please enter a valid command(gender, birthday, or lastname)"); break; } if(0 < personalRecords.Count()) { //print the header Console.WriteLine("{0,15}{1,15}{2,15}{3,15}{4,15}","First Name", "Last Name", "Gender", "Favorite Color", "Date of Birth"); foreach (var personalRecord in personalRecords) Console.WriteLine(personalRecord.ToString()); } } }
public void GetRecordsSortedByLastName() { // List is ordered by last name var expectedList = new List<PersonalRecord>() { _richard, _chum, _gytha, _galatea, _magrat, _bill }; var recordManager = new RecordManager(); recordManager.AddPersonalRecord(_gythaString); recordManager.AddPersonalRecord(_richardString); recordManager.AddPersonalRecord(_chumString); recordManager.AddPersonalRecord(_billString); recordManager.AddPersonalRecord(_galateaString); recordManager.AddPersonalRecord(_magratString); var receivedList = recordManager.GetRecordsSortedByLastName(); Assert.AreEqual(receivedList.Count(), 6); CollectionAssert.AreEqual(expectedList, receivedList); }
public void GetRecordsSortedByBirthday() { // List is ordered by birthday var expectedList = new List<PersonalRecord>() { _galatea, _gytha, _chum, _magrat, _richard }; var recordManager = new RecordManager(); recordManager.AddPersonalRecord(_gythaString); recordManager.AddPersonalRecord(_richardString); recordManager.AddPersonalRecord(_chumString); recordManager.AddPersonalRecord(_galateaString); recordManager.AddPersonalRecord(_magratString); var receivedList = recordManager.GetRecordsSortedByBirthday(); Assert.AreEqual(receivedList.Count(), 5); CollectionAssert.AreEqual(expectedList, receivedList); }
public void AddPersonalrecordIncorrectDelimiter() { var recordManager = new RecordManager(); string incorrectDelimiterString = @"Richard ] Simmons ] male | maroon | 08/01/1979"; recordManager.AddPersonalRecord(incorrectDelimiterString); }
public void AddPersonalRecordDifferentDelimiters() { //Testing comma delimiter var recordManager = new RecordManager(); var expectedList = new List<PersonalRecord>(); expectedList.Add(_gytha); recordManager.AddPersonalRecord(_gythaString); Assert.AreEqual(recordManager.GetRecordsSortedByBirthday().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByGender().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByLastName().Count, 1); var receivedList = recordManager.GetRecordsSortedByBirthday(); var receivedRecord = receivedList.FirstOrDefault(); Assert.AreEqual(_gytha, receivedRecord); CollectionAssert.AreEqual(expectedList, receivedList); //Testing pipe delimiter recordManager = new RecordManager(); expectedList = new List<PersonalRecord>(); expectedList.Add(_richard); recordManager.AddPersonalRecord(_richardString); Assert.AreEqual(recordManager.GetRecordsSortedByBirthday().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByGender().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByLastName().Count, 1); receivedList = recordManager.GetRecordsSortedByBirthday(); receivedRecord = receivedList.FirstOrDefault(); Assert.AreEqual(_richard, receivedRecord); CollectionAssert.AreEqual(expectedList, receivedList); //Testing space delimiter recordManager = new RecordManager(); expectedList = new List<PersonalRecord>(); expectedList.Add(_galatea); recordManager.AddPersonalRecord(_galateaString); Assert.AreEqual(recordManager.GetRecordsSortedByBirthday().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByGender().Count, 1); Assert.AreEqual(recordManager.GetRecordsSortedByLastName().Count, 1); receivedList = recordManager.GetRecordsSortedByBirthday(); receivedRecord = receivedList.FirstOrDefault(); Assert.AreEqual(_galatea, receivedRecord); CollectionAssert.AreEqual(expectedList, receivedList); }