public void ParseWithEmptyStringTest()
        {
            string testString = "";
            Human  human      = HumanParser.Parse(testString);

            if (human != null)
            {
                Assert.Fail();
            }
        }
        public void ParseWithBarTest()
        {
            string testString = "Vladyslav | Bazyliak | Male | White | 8/22/1995";
            Human  human      = HumanParser.Parse(testString);

            if (human == null)
            {
                Assert.Fail();
            }
        }
        public void ParseWithSpaceTest()
        {
            string testString = "Vladyslav Bazyliak Male White 8/22/1995";
            Human  human      = HumanParser.Parse(testString);

            if (human == null)
            {
                Assert.Fail();
            }
        }
        public void ParseWithCommaTest()
        {
            string testString = "Vladyslav, Bazyliak, Male, White, 8/22/1995";
            Human  human      = HumanParser.Parse(testString);

            if (human == null)
            {
                Assert.Fail();
            }
        }
Beispiel #5
0
        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;
        }
Beispiel #6
0
        public void PhoneBookAdd(string name, string town, string number)
        {
            var parser = new HumanParser();
            var human  = parser.CreateHuman(new string[] { name, town, number });

            book.Add(human);

            var actual = book.GetHumanData();

            Assert.AreEqual(mockHumans[0].Length + 1, actual.Length);
            Assert.AreEqual(town, actual.Last().Town);
            Assert.AreEqual(number, actual.Last().Number);
        }
        public object Index([FromBody] string record)
        {
            var human = HumanParser.Parse(record);

            if (human != null)
            {
                humanManager.AddHuman(human);
                return(human);
            }
            else
            {
                return(BadRequest("Invalid request"));
            }
        }
Beispiel #8
0
        public void Init()
        {
            var input = mockHumans[0];

            var reader = new Mock <IReader>();
            var saver  = new Mock <ISaver>();
            var parser = new HumanParser();

            reader.SetupSequence(r => r.ReadLine())
            .Returns(input[0])
            .Returns(input[1])
            .Returns(input[2])
            .Returns(input[3])
            .Returns(input[4])
            .Returns(input[5]);

            book = new PhoneBook(reader.Object, saver.Object, parser);
            book.Init();
        }