Beispiel #1
0
        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];
                    var currentItem = new KeyValuePair<string, Contact>();

                    if (phoneBook.RemoveAt(index, out currentItem))
                    {
                        // KeyValuePair<string, string> currentItem = phoneBook.GetElementTo(index);
                        // phoneBook.Remove(currentItem);
                        fileIO.WriteFile(ref phoneBook);
                        ////Console.WriteLine("The contact '{0} => {1}: {2}' has been deleted.", new object[] { currentItem.Key, currentItem.Value.Name, currentItem.Value.PhoneNumber });
                        message = string.Format("The contact '{0} => {1}: {2}' has been deleted.", currentItem.Key, currentItem.Value.Name, currentItem.Value.PhoneNumber);
                    }
                    else ////Console.WriteLine("Your input must be an integer between 0 and {0}", new object[] { phoneBook.Count() });
                        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());
            }
        }
Beispiel #2
0
 public void RemoveAt()
 {
     PhoneBook phoneBook = new PhoneBook();
     phoneBook.Add("Nick", "0744596866");
     phoneBook.Add("John Smith", "0745516", "3gd");
     phoneBook.Add("Samuel", "444");
     phoneBook.RemoveAt("3gd");
     Assert.AreEqual(2, phoneBook.Count());
 }