public void SortByLastName_Success() { //1. arrange var t = new TelephoneBook(); t.People = new List <IPerson>() { new Person() { LastName = "BBB" }, new Person() { LastName = "CCC" }, new Person() { LastName = "AAA" } }; //2. act var result = t.SortByLastName(); //3. assert Assert.AreEqual("AAA", result[0].LastName); Assert.AreEqual("BBB", result[1].LastName); Assert.AreEqual("CCC", result[2].LastName); }
static void Main(string[] args) { string character = "e"; TelephoneBook phoneBook = new TelephoneBook(); phoneBook.PersonList.Add(new Person("aaa", "a")); phoneBook.PersonList.Add(new Person("aaa", "b")); phoneBook.PersonList.Add(new Person("bbb", "b")); phoneBook.PersonList.Add(new Person("bbb", "b")); phoneBook.PersonList.Add(new Person("bbb", "c")); phoneBook.PersonList.Add(new Person("ccc", "c")); phoneBook.PersonList.Add(new Person("ddd", "d")); phoneBook.PersonList.Add(new Person("eee", "e")); phoneBook.PersonList.Add(new Person("fff", "b")); phoneBook.PersonList.Add(new Person("ggg", "d")); Console.WriteLine("PersonList:"); PrintPersonList(phoneBook.PersonList); Console.WriteLine(); Console.WriteLine("Sorted on last name:"); PrintPersonList(phoneBook.SortOnLastName()); Console.WriteLine(); Console.WriteLine("First name starts with: " + character); PrintPersonList(phoneBook.FirstNameStartsWith(character)); Console.WriteLine(); Console.ReadKey(); }
public ActionResult SortedContacts(bool asc = true) { var telephoneBook = new TelephoneBook(); ViewBag.Contacts = telephoneBook.GetSortedContacts(asc); return(View()); }
// GET: Home public ActionResult Index() { var telephoneBook = new TelephoneBook(); ViewBag.Contacts = telephoneBook.GetContacts(); return(View()); }
public ActionResult Search(string ln) { var telephoneBook = new TelephoneBook(); if (string.IsNullOrEmpty(ln)) { ViewBag.Contacts = telephoneBook.GetContacts(); } else { ViewBag.Contacts = telephoneBook.GetContactsByLastName(ln); } return(View()); }