public static void CreatePhoneBook(StreamReader fileReader, PhoneBook phoneBook) { string line = null; while ((line = fileReader.ReadLine()) != null) { string[] data = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string[] name = data[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var person = new Person(data[0].Trim(), data[1].Trim(), data[2].Trim()); phoneBook.Add(person, name); phoneBook.Add(person, data[1].Trim()); } }
public void PhoneBookWorkCorrect(int requestsCount, string[] commands, string[] responses) { // Arrange var listResult = new List <string>(); // Act var sut = new PhoneBook(); for (int i = 0; i < requestsCount; i++) { var command = commands[i].Split(' '); switch (command[0]) { case "add": //sut.Add(new PhoneBookOnLists.Contact(command[1],command[2])); sut.Add(command[1], command[2]); break; case "find": listResult.Add(sut.Find(command[1])); break; case "del": sut.Delete(command[1]); break; default: break; } } // Assert Assert.AreEqual(responses, listResult.ToArray()); }
public void Add_Contact_Success() { var book = new PhoneBook(); var contact = new Contact(); book.Add(contact); Assert.Equal(book.First(), contact); }
public void Constructor_withphonebook_Success() { var book = new PhoneBook(); var contact = new Contact(); book.Add(contact); var newbook = new PhoneBook(book); Assert.Equal(book.First(), newbook.First()); }
public void Adds() { // Arrange var sut = new PhoneBook(new PhoneBookEntry[0]); // Act var data = new PhoneBookEntry("JkHASD", 45654654); sut.Add(data); // Assert Assert.IsTrue(sut.Addresses.Count() == 1 && sut.Addresses[data.Name] == data.Number); }
static void Main(string[] args) { PhoneCreator creator = new PhoneCreator(); PhoneBook phones = new PhoneBook(); phones.Add(creator.CreatePhone("0296704790", "Ivan Petrov")); phones.Add(creator.CreatePhone("0447235235", "Petya Sidorov")); phones.Add(creator.CreatePhone("0252435345", "Borzenkov")); phones.Add(creator.CreatePhone("0446423424", "Student Bezfamilniy")); Console.WriteLine("Text format: \n"); phones.SaveToTextfile("data.txt"); foreach (Phone phone in phones) Console.WriteLine(phone.ToString()); phones.LoadFromTextfile("data.txt"); Console.WriteLine("\nBinary format: \n"); phones.SaveToBinaryFile("data.bin"); foreach (Phone phone in phones) Console.WriteLine(phone.ToString()); phones.LoadFromBinaryFile("data.bin"); Console.WriteLine("\nXML format: \n"); phones.SaveToXmlFile("data.xml"); foreach (Phone phone in phones) Console.WriteLine(phone.ToString()); phones.LoadFromXmlFile("data.xml"); Console.Read(); }
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 void UpdatesError() { // Arrange var sut = new PhoneBook(new PhoneBookEntry[0]); // Act var data = new PhoneBookEntry("JkHASD", 45654654); sut.Add(data); var updated = new PhoneBookEntry("asdasd", 5444); sut.Update(updated); // Assert Assert.IsFalse(sut.Update(updated)); }
public void Updates() { // Arrange var sut = new PhoneBook(new PhoneBookEntry[0]); // Act var data = new PhoneBookEntry("JkHASD", 45654654); sut.Add(data); var updated = new PhoneBookEntry("JkHASD", 5444); sut.Update(updated); // Assert Assert.IsTrue(sut.Addresses.Single().Value == 5444); }
static void Main() { var phoneBook = new PhoneBook(); phoneBook.Start(); bool run = true; while (run) { Console.Clear(); Console.WriteLine("your options are\na = Add; f = Find; d = Delete; l = List; q = Quit"); char key = Console.ReadKey().KeyChar; switch (key) { case 'a': Console.Write("Name: "); string name = Console.ReadLine(); Console.Write("Phone: "); string phone = Console.ReadLine(); Console.Write("E-mail: "); string email = Console.ReadLine(); phoneBook.Add(name, phone, email); break; case 'f': Console.Write("Name: "); string f_name = Console.ReadLine(); if (phoneBook.Find(f_name, out string f_phone, out string f_email)) { Console.WriteLine("Phone: " + f_phone); Console.WriteLine("E-mail: " + f_email); } else { Console.WriteLine("Not Found!!!"); } Console.ReadLine(); break;
/// <summary> /// Gets the phone book entries of phonebook 0 /// </summary> /// <returns> a list of deserialized entries </returns> public virtual PhoneBook GetPhoneBook() { var result = new PhoneBook(); this.phonebookControl.host = this.Host.Host; this.phonebookControl.HTTPpassword = this.UserPassword; var phoneBookResult = this.phonebookControl.OpenPort() as Hashtable; this.phonebookAccess.host = this.Host.Host; if (this.phonebookAccess.port == "0") { if (phoneBookResult != null) { this.phonebookAccess.port = (string)phoneBookResult["Port"]; } } var phonebookEntryCount = (int)this.phonebookAccess.GetEntryCount(); for (var i = 0; i < phonebookEntryCount; i++) { var x = this.phonebookAccess.GetEntry(i) as XmlNodeList; if (x == null || x.Count < 1) { continue; } try { var contact = Tools.LoadFromString <Contact>(x[0].OuterXml); result.Add(contact); } catch (Exception ex) { throw new TechnicalException("Serialization problem with FritzBox-entity.", ex, new KeyValuePair <string, object>("serialized entity", x[0])); } } return(result); }
internal static void Main() { var myPhoneBook = new PhoneBook(); var reader = new StreamReader(@"..\..\phonebook.txt"); var commandReader = new StreamReader(@"..\..\commands.txt"); string[] separators = { " | " }; string[] comSeparators = { "(", ")", "," }; using (reader) { using (commandReader) { for (string line = reader.ReadLine(); line != null; line = reader.ReadLine()) { myPhoneBook.Add(new PhoneRecord(line.Split(separators, StringSplitOptions.RemoveEmptyEntries))); } for (string line = commandReader.ReadLine(); line != null; line = commandReader.ReadLine()) { ExecuteCommand(myPhoneBook, line.Split(comSeparators, StringSplitOptions.RemoveEmptyEntries)); } } } }
public static void Main() { //var sampleText = "This is the TEXT. Text, text, text - THIS TEXT! Is this the text?"; //OccurencesCounter.GetOccurrencesFromText(sampleText).StringJoin().Print(); //var hashy = new HashTable<string, string>(); //var rng = new Random(); //var names = new string[] //{ // "gosho", "tosho", "ivan", "skumriq", "gencho", "pencho", "penka", "stamat", "pako", // "djodjo", "strahil", "maria", "uruspiq", "ginka", "nikola", "djena", "plamena", "enrike" //}; //names.ForEach(n => //{ // hashy.Add(n, names[rng.Next(0, names.Length)]); //}); //// remove first 10 //names.Take(10).ForEach(x => hashy.Remove(x)); //// print second 10 via indexer //names.Skip(10).ForEach(x => hashy[x].Print()); var phonebook = new PhoneBook(); var info = new string[] { "Mimi Shmatkata | Plovdiv | 0888 12 34 56", "Kireto | Varna | 052 23 45 67", "Daniela Ivanova Petrova | Karnobat | 0899 999 888", "Bat Gancho | Sofia | 02 946 946 946", "Bat Gancho | Pleven | 02 888 946 946", }; info.ForEach(x => { var groomedArray = x.Split('|').Select(y => y.Trim()).ToArray(); phonebook.Add(new PersonInfo() { Name = groomedArray[0], City = groomedArray[1], PhoneNumber = groomedArray[2] }); }); var queries = new string[][] { new string[] { "Mimi" }, new string[] { "Bat Gancho" }, new string[] { "Bat Gancho", "Pleven" } }; queries.ForEach(x => { if (x.Length == 1) { phonebook.Find(x[0]).StringJoin().Print(); } else { phonebook.Find(x[0], x[1]).StringJoin().Print(); } }); }
void ChooseAction(string select) { string surname = ""; string name = ""; string patronymic = ""; string number = ""; string country = ""; string birthday = ""; string organization = ""; string position = ""; string other = ""; switch (select) { case "0": while (name == "") { Console.WriteLine("Введите Имя:"); name = Console.ReadLine(); } while (surname == "") { Console.WriteLine("Введите Фамилию: "); surname = Console.ReadLine(); } Console.WriteLine("Введите Отчество: "); patronymic = Console.ReadLine(); Console.WriteLine("Введите Номер: "); long result; number = Console.ReadLine(); while (number == "") { Console.WriteLine("Внимание!!! Введите Номер!"); number = Console.ReadLine(); } result = Convert.ToInt64(number); while (country == "") { Console.WriteLine("Введите Страну проживания: "); country = Console.ReadLine(); } Console.WriteLine("Введите Дату рождения: "); birthday = Console.ReadLine(); Console.WriteLine("Введите Организацию: "); organization = Console.ReadLine(); Console.WriteLine("Введите должность: "); position = Console.ReadLine(); Console.WriteLine("Введите Прочая информация: "); other = Console.ReadLine(); book.Add(surname, name, patronymic, number, country, birthday, organization, position, other); break; case "1": Console.WriteLine("Введите Имя для изменения: "); name = Console.ReadLine(); Contacts date; if (book.Find2(name)) { date = book.Find(name); } else { Console.WriteLine("Введите Фамилию для изменения: "); surname = Console.ReadLine(); date = book.Findtogether(name, surname); } if (date == null) { Console.WriteLine("Контакт с именем {0} не найден. Нажмите кнопку для продолжения.", name); Console.ReadKey(); } else { string edition = ""; Notes edit = new Notes(); Console.WriteLine("Введите что вы меняете(на английском): "); edition = Console.ReadLine(); edit.ChooseAction(edition); switch (edition) { case "surname": Console.WriteLine("Введите Фамилию: "); date.surname = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "name": Console.WriteLine("Введите Имя: "); date.name = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "patronymic": Console.WriteLine("Введите Отчество: "); date.patronymic = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "number": Console.WriteLine("Введите Номер: "); date.number = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "country": Console.WriteLine("Введите Страну проживания: "); date.country = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "birthday": Console.WriteLine("Введите День рождения: "); date.birthday = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "organization": Console.WriteLine("Введите Организацию: "); date.organization = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "position": Console.WriteLine("Введите Должность: "); date.position = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; case "other": Console.WriteLine("Введите Прочую информацию: "); date.other = Console.ReadLine(); Console.WriteLine("Обновлены данные для {0}", name); break; } } break; case "2": Console.WriteLine("Введите Имя удаляемого контакта: "); name = Console.ReadLine(); if (book.Remove(name)) { Console.WriteLine("Контакт удален"); } else { Console.WriteLine("Контакт с именем {0} не найден. Нажмите кнопку для продолжения.", name); Console.ReadKey(); } break; case "3": Console.WriteLine("Введите Имя: "); name = Console.ReadLine(); Contacts find; if (book.Find2(name)) { find = book.Find(name); } else { Console.WriteLine("Введите Фамилию: "); surname = Console.ReadLine(); find = book.Findtogether(name, surname); } if (find == null) { Console.WriteLine("Контакт с именем {0} не найден. Нажмите кнопку для продолжения.", name); Console.ReadKey(); } else { Console.WriteLine("Contact:"); Console.WriteLine("Фамилию:{0}, Имя:{1}, Отчество:{2}, Номер телефона:{3}, Страна:{4}, Дата рождения:{5}, Организация:{6}, Должность:{7}, Другое:{8}" , find.surname, find.name, find.patronymic, find.number, find.country, find.birthday, find.organization, find.position, find.other); } break; case "4": if (book.IsEmpty()) { Console.WriteLine("Записная книжка пуста."); Console.ReadKey(); } else { Console.WriteLine("Контакты:"); book.List( delegate(Contacts a) { Console.WriteLine("{0} - {1} - {2}", a.surname, a.name, a.number); } ); } break; } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { pb.Add(this.txtName.Text, int.Parse(this.txtNumber.Text)); }