public void Execute(string[] args)
        {
            ConsoleInput consoleInput = new ConsoleInput(args, name);
            if (consoleInput.IsValidCommandName())
            {
                ActivateParameters();
                var minimumParameters = parameters.MandatoryLength();
                var maximumParameters = parameters.ParametersLength();

                if (consoleInput.Parameters.Length >= minimumParameters && consoleInput.Parameters.Length <= maximumParameters)
                {
                    var phoneBook = new PhoneBook();
                    var fileIO = new InputOutput("PhoneBook.txt");
                    fileIO.ReadFile(ref phoneBook);
                    string index = consoleInput[0];
                    if (phoneBook.ValidIndex(index))
                    {
                        KeyValuePair<string, Contact> currentItem = phoneBook.GetElementTo(index);
                        ////Console.WriteLine("{0} {1} {2}", new object[] { index, currentItem.Value.Name, currentItem.Value.PhoneNumber });
                        message = string.Format("{0} {1} {2} {3}", index, currentItem.Value.Name, currentItem.Value.PhoneNumber, currentItem.Value.BirthDate);
                    }
                    else message = string.Format("Your input '{0}' is not valid.", index);
                }
                else
                {
                    message = string.Format("This command requires 1 mandatory parameter");
                    message += System.Environment.NewLine;
                    message += string.Format("{0}", string.Join(" ", parameters.Mandatory()[0].Name));
                }

                Console.WriteLine(Message());
            }
        }
示例#2
0
        public void ModifyNameAndPhone()
        {
            PhoneBook phoneBook = new PhoneBook();
            phoneBook.Add("Nick", "0744596866");
            phoneBook.Add("John Smith", "0745516", "3gd");

            phoneBook.Modify(id: "3gd", phoneNumber: "0744578999", name: "Johnny");
            KeyValuePair<string, Contact> contactToModify = phoneBook.GetElementTo("3gd");

            KeyValuePair<string, Contact> contactToCompare = new KeyValuePair<string, Contact>("3gd", new Contact("Johnny", "0744578999"));

            Assert.AreEqual(contactToCompare, contactToModify);
        }
示例#3
0
        public void GetElementToFalse()
        {
            PhoneBook phoneBook = new PhoneBook();
            phoneBook.Add("Nick", "0744596866");
            phoneBook.Add("John Smith", "0745516", "3gd");
            phoneBook.Add("Samuel", "444");

            KeyValuePair<string, Contact> contactToCompare = new KeyValuePair<string, Contact>("3gd", new Contact("John Smith 2", "0745516"));
            KeyValuePair<string, Contact> contactToRetrieve = phoneBook.GetElementTo("3gd");

            Assert.AreNotEqual(contactToCompare, contactToRetrieve);
        }