public static void Main(string[] args) { Console.Clear(); if (args.Length != 1 || new string[] { "?", "help", "/help", "help?", "?help" }.Contains(args[0])) // new string[] { "?", "help", "/help", "help?", "?help" } is an array that contains all calls of "Help" { Console.WriteLine("This program requries only one argument - File Path.\nOutput is the set of records sorted in one of three ways."); } else { HumanManager humanManager = new HumanManager(); try { using (StreamReader sr = new StreamReader(args[0])) { string line; while ((line = sr.ReadLine()) != null) { var human = HumanParser.Parse(line); if (human != null) { humanManager.AddHuman(human); } else { Console.WriteLine("Bad data."); break; } } } int option = 0; int[] acceptableChoices = new int[] { 1, 2, 3 }; while (!acceptableChoices.Contains(option)) { Console.WriteLine("Please choose how you'd like to print result.\n1) Sorted by gender (females before males) then by last name ascending.\n2) Sorted by birth date, ascending.\n3) Sorted by last name, descending."); Int32.TryParse(Console.ReadLine(), out option); } List <Human> resultList = humanManager.GetHumans((SortType)option); foreach (var item in resultList) { Console.WriteLine($"{item.LastName} {item.FirstName} {item.Gender} {item.FavoriteColor} {String.Format("{0:d}", item.DateOfBirth)}"); } } catch (Exception e) { Console.WriteLine("Unable to open this file. Please, check the File Path."); } } Console.WriteLine("Please, press \"Enter\" key to exit ..."); Console.ReadLine(); return; }
public object Index([FromBody] string record) { var human = HumanParser.Parse(record); if (human != null) { humanManager.AddHuman(human); return(human); } else { return(BadRequest("Invalid request")); } }
public void AddHumanTest() { Human testHuman = new Human { FirstName = "John", LastName = "Doe", FavoriteColor = Colors.Silver, DateOfBirth = new DateTime(1995, 8, 22), Gender = Genders.Male }; HumanManager hm = new HumanManager(); List <Human> correctList = new List <Human> { testHuman }; hm.Clear(); hm.AddHuman(testHuman); var result = hm.GetHumans(); if (result.Count == 0) { Assert.Fail(); } bool invalidResult = false; for (int i = 0; i < result.Count && i < correctList.Count; i++) { if (!result[i].IsEqual(correctList[i])) { invalidResult = true; break; } } if (invalidResult) { Assert.Fail(); } }
public void GetHumansByGenderAndLastNameTest() { Human humanA = new Human { FirstName = "Anna", LastName = "Martin", FavoriteColor = Colors.Silver, DateOfBirth = new DateTime(1995, 8, 22), Gender = Genders.Female }; Human humanB = new Human { FirstName = "Caroline", LastName = "Smith", FavoriteColor = Colors.Silver, DateOfBirth = new DateTime(1995, 8, 22), Gender = Genders.Female }; Human humanC = new Human { FirstName = "John", LastName = "Doe", FavoriteColor = Colors.Silver, DateOfBirth = new DateTime(1995, 8, 22), Gender = Genders.Male }; Human humanD = new Human { FirstName = "Peter", LastName = "Griffin", FavoriteColor = Colors.Silver, DateOfBirth = new DateTime(1995, 8, 22), Gender = Genders.Male }; List <Human> correctList = new List <Human> { humanA, humanB, humanC, humanD }; HumanManager hm = new HumanManager(); hm.Clear(); hm.AddHuman(humanD); hm.AddHuman(humanA); hm.AddHuman(humanC); hm.AddHuman(humanB); var result = hm.GetHumans(SortType.ByGenderAndLastName); bool invalidResult = false; for (int i = 0; i < result.Count && i < correctList.Count; i++) { if (!result[i].IsEqual(correctList[i])) { invalidResult = true; break; } } if (invalidResult) { Assert.Fail(); } }