public void findPerson() { //Arrange var pBook = new PhoneBook(); //Act var p = pBook.FindPerson("John Smith"); Assert.IsNull(p); }
public void addPerson() { //Arrange var pBook = new PhoneBook(); var person = new Person() { Name = "test person" }; //Act pBook.AddPerson(person); Assert.Pass(); }
static void Main(string[] args) { try { Person[] persons = { new Person("John Smith", "(248) 123-4567", "1234 Sand Hill Dr, Royal Oak, MI"), new Person("Cynthia Smith", "(824) 128-8758", "875 Main St, Ann Arbor, MI") }; DatabaseUtil.InitializeDatabase(null); PhoneBook phoneBook = new PhoneBook(); phoneBook.AddPerson(persons[0]); phoneBook.AddPerson(persons[1]); for (int i = 0; i < phoneBook.Length; ++i) { Console.WriteLine(phoneBook[i].GetInfo); } Person p = phoneBook.FindPerson("Cynthia Smith"); Console.WriteLine(p?.GetInfo); Console.ReadLine(); #region Test //Console.ReadLine(); ///* TODO: create person objects and put them in the PhoneBook and database //* John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI //* Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI //*/ //// TODO: print the phone book out to System.out //// TODO: find Cynthia Smith and print out just her entry //// TODO: insert the new person objects into the database #endregion } finally { DatabaseUtil.CleanUp(); } }
static void Main(string[] args) { try { var dbConnection = new SQLiteConnection("Data Source= MyDatabase.sqlite;Version=3;"); dbConnection.Open(); SQLiteCommand command = new SQLiteCommand( "drop table PHONEBOOK", dbConnection); command.ExecuteNonQuery(); DatabaseUtil.InitializeDatabase(); //Add phonebooks to In-memory Phonebook Collection var phoneBook = new PhoneBook(new PersonRepository()); phoneBook.AddPerson(new Person() { Name = "John Smith", Address = "1234 Sand Hill Dr, Royal Oak, MI", PhoneNumber = "(248) 123-4567" }); phoneBook.AddPerson(new Person() { Name = "Cynthia Smith", Address = "875 Main St, Ann Arbor, MI", PhoneNumber = "(824) 128-8758" }); //Print phonebook Console.WriteLine("---------PRINT Phonebook"); Console.WriteLine(phoneBook.ToString()); //get and print cynthia Console.WriteLine("---------PRINT Cynthia"); var person = phoneBook.FindPerson("Cynthia Smith"); Console.WriteLine(person.ToString()); //persist in-memory phonebook collection to DB phoneBook.Persist(); Console.WriteLine("Press Enter to exit"); Console.ReadLine(); } finally { DatabaseUtil.CleanUp(); } }
public void printPhonebook(PhoneBook book) { try { foreach (Person person in book.getAllPerson()) { printPersonDetails(person); } } catch (Exception ex) { Logger.Log(LoggerType.Console, "Printing phonebook Failed!", ex.StackTrace); Logger.Log(LoggerType.File, "Printing phonebook Failed!", ex.StackTrace); throw ex; } }
//private PhoneBook phonebook = new PhoneBook(); static void Main(string[] args) { try { // DatabaseUtil.initializeDatabase(); /* TODO: create person objects and put them in the PhoneBook and database * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI */ // TODO: print the phone book out to System.out // TODO: find Cynthia Smith and print out just her entry // TODO: insert the new person objects into the database PhoneBook phonebook = new PhoneBook(); Person person = new Person(); person.name = "John Smith"; person.phoneNumber = "(248) 123-4567"; person.address = "1234 Sand Hill Dr, Royal Oak, MI"; phonebook.addPerson(person); Console.Write(phonebook); Person person1 = new Person(); person1.name = "Cynthia Smith "; person1.phoneNumber = "(824) 128-8758, 875"; person1.address = "875 Main St, Ann Arbor, MI"; phonebook.addPerson(person1); string name = person.name; phonebook.findPerson(name); //Console.WriteLine("record added"); // Console.ReadLine(); } catch (Exception) { throw; } //finally { DatabaseUtil.CleanUp(); } }
static void Main(string[] args) { try { //DatabaseUtil.CleanUp(); DatabaseUtil.initializeDatabase(); PhoneBook phonebook = new PhoneBook(); /* TODO: create person objects and put them in the PhoneBook and database * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI */ // TODO: insert the new person objects into the database Person objPerson1 = new Person { name = "John Smith", phoneNumber = "(248) 123-4567", address = "1234 Sand Hill Dr, Royal Oak, MI" }; Person objPerson2 = new Person { name = "Cynthia Smith", phoneNumber = "(824) 128-8758", address = "875 Main St, Ann Arbor, MI" }; phonebook.addPerson(objPerson1); phonebook.addPerson(objPerson2); // TODO: print the phone book out to System.out Console.WriteLine("###########PHONE BOOK##############"); foreach (Person person in phonebook.GetPhoneBook) { Console.WriteLine("Name: {0}, Phone Number: {1}, Address: {2}", person.name, person.phoneNumber, person.address); } Console.WriteLine("###################################"); // TODO: find Cynthia Smith and print out just her entry string strFN = "Cynthia"; string strLN = "Smith"; Person findpersion = phonebook.findPerson(strFN, strLN); Console.WriteLine("Name: " + findpersion.name); Console.WriteLine("Phone Number: " + findpersion.phoneNumber); Console.WriteLine("Address: "+ findpersion.address); Console.ReadLine(); } finally { DatabaseUtil.CleanUp(); } }
public void addNewPerson(PhoneBook book) { try { Console.Write("Enter Person First Name: "); string pFName = Console.ReadLine(); Console.Write("Enter Person Last Name: "); string pLName = Console.ReadLine(); Console.Write("Enter Person Phone: "); string pPhone = Console.ReadLine(); Console.Write("Enter Person Address: "); string pAddress = Console.ReadLine(); book.addPerson(createPerson(pFName, pLName, pPhone, pAddress)); } catch (Exception ex) { Logger.Log(LoggerType.Console, "Adding Person object into phonebook Failed!", ex.StackTrace); Logger.Log(LoggerType.File, "Adding Person object into phonebook Failed!", ex.StackTrace); throw ex; } }
public void findPersonDetails(PhoneBook book, string firstName, string lastName) { try { Person foundPerson = book.findPerson(firstName, lastName); if (foundPerson != null) { printPersonDetails(foundPerson); } else { throw new Exception(string.Format("No Person found with the name: '{0} {1}'", firstName, lastName)); } } catch (Exception ex) { Logger.Log(LoggerType.Console, "Find & Print Person object Failed!", ex.StackTrace); Logger.Log(LoggerType.File, "Find & Print Person object Failed!", ex.StackTrace); throw ex; } }
static void Main(string[] args) { var context = new PhoneBookContext(); try { DatabaseUtil.initializeDatabase(context); /* TODO: create person objects and put them in the PhoneBook and database * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI */ var John = new Person("John", "Smith", "(248) 123 - 4567", "1234 Sand Hill Dr", "Royal Oak", "MI"); var Cynthia = new Person("Cynthia", "Smith", "(824) 128 - 8758", "875 Main St", "Ann Arbor", "MI"); var phoneBook = new PhoneBook(context); phoneBook.AddPerson(John); phoneBook.AddPerson(Cynthia); // TODO: print the phone book out to System.out new PhoneBookPrinter().Print(phoneBook); // TODO: find Cynthia Smith and print out just her entry var cynthiaRecord = phoneBook.Find(m => m.FirstName == "Cynthia" && m.LastName == "Smith") .FirstOrDefault(); Console.WriteLine(); Console.WriteLine(cynthiaRecord?.ToString()); // TODO: insert the new person objects into the database Console.ReadLine(); DatabaseUtil.CleanUp(context); } finally { DatabaseUtil.CleanUp(context); } }
private static void Main(string[] args) { var dataProvider = new PhoneBookDataProvider(); _phonebook = new PhoneBook(dataProvider); dataProvider.CreateDatabase(); try { dataProvider.InitializeDatabase(); CreatePersonAddedDatabase(); FindAndPrintPerson(); AddPersonToDatabase(); Console.ReadKey(); } finally { dataProvider.CleanUp(); } }
static void Main(string[] args) { try { DatabaseUtil.initializeDatabase(); //create person objects and put them in the PhoneBook PhoneBook objPhonebook = new PhoneBook(); objPhonebook.addPerson(new Person { name = "John Smith", address = "1234 Sand Hill Dr, Royal Oak, MI", phoneNumber = "(248) 123-4567" }); objPhonebook.addPerson(new Person { name = "Cynthia Smith", address = "875 Main St, Ann Arbor, MI", phoneNumber = "(824) 128-8758" }); //create person objects and put them in the Database DatabaseUtil.Savecontacts(objPhonebook.personList); // print the phone book out to System.out Console.Write("********** List of Contact details ************"); foreach (var item in objPhonebook.personList) { Console.WriteLine("Name:{0}, PhoneNumber: {1}, Address : {2}", item.name, item.phoneNumber, item.address); } // find Cynthia Smith and print out just her entry var foundPerson = objPhonebook.findPerson("Cynthia", "Smith"); Console.WriteLine(foundPerson.name); //insert the new person objects into the database Console.Write("********** To Store a Person details in phonebook and Database************"); bool confirmed = false; Person objPerson; List <Person> ObjpersonToAdd = new List <Person>(); while (!confirmed) { objPerson = new Person(); Console.Write("\n Enter Name: "); objPerson.name = Console.ReadLine(); Console.Write("Enter Address: "); objPerson.address = Console.ReadLine(); Console.Write("Enter Mobile Number: "); objPerson.phoneNumber = Console.ReadLine(); objPhonebook.addPerson(objPerson); ObjpersonToAdd.Add(objPerson); Console.WriteLine("Do you want to add more contact? [yes/no]"); string option = Console.ReadLine(); if (option == "no") { confirmed = true; } } DatabaseUtil.Savecontacts(ObjpersonToAdd); // TODO: print the phone book out to System.out // TODO: find Cynthia Smith and print out just her entry // TODO: insert the new person objects into the database } finally { DatabaseUtil.CleanUp(); } }
static void Main(string[] args) { try { DatabaseUtil.initializeDatabase(); IPhoneBook phoneBook = new PhoneBook(); /* TODO: create person objects and put them in the PhoneBook and database * John Smith, (248) 123-4567, 1234 Sand Hill Dr, Royal Oak, MI * Cynthia Smith, (824) 128-8758, 875 Main St, Ann Arbor, MI */ Console.WriteLine("Adding John Smith to the phone book..."); phoneBook.addPerson( new Person() { Name = "John Smith", Address = "1234 Sand Hill Dr, Royal Oak, MI", PhoneNumber = "(248) 123-4567" }); Console.WriteLine(); Console.WriteLine("Adding Cynthia Smith to the phone book..."); phoneBook.addPerson( new Person() { Name = "Cynthia Smith", Address = "875 Main St, Ann Arbor, MI", PhoneNumber = "(824) 128-8758" }); // TODO: print the phone book out to System.out Console.WriteLine(); Console.WriteLine("Printing the phone book to the console..."); foreach (Person person in phoneBook.getAllPeople()) { Console.WriteLine(person); } // TODO: find Cynthia Smith and print out just her entry Console.WriteLine("Finding Cynthia Smith in the phone book..."); Person cynthiaSmith = phoneBook.findPerson("Cynthia Smith"); if (cynthiaSmith == null) { Console.WriteLine("\"Cynthia Smith\" is not in the phone book."); } else { Console.WriteLine(cynthiaSmith); } // TODO: insert the new person objects into the database // TODO: Didn't we already do that above? The instructions say to "person objects and put them in the PhoneBook and database" above... Console.WriteLine("Press Enter or Return to close"); Console.ReadLine(); } finally { DatabaseUtil.CleanUp(); } }