public void TestReadFile() { var contacts = Helpers.GenerateContactList( Helpers.MinListLength, Helpers.MaxListLength); using (StreamWriter stream = new StreamWriter(Filepath)) { try { foreach (Contact contact in contacts) { ContactIOManager.Write(contact, stream); } } catch { Assert.IsTrue(false); } } ArrayList arrContacts = ContactExtensions.ReadFile(Filepath); try { for (int i = 0; i < contacts.Count; ++i) { Assert.IsTrue(contacts[i].Equals(arrContacts[i])); } } catch { Assert.IsTrue(false); } }
public void TestSaveSortedContactsToFile() { var contacts = Helpers.GenerateContactList( Helpers.MinListLength, Helpers.MaxListLength); contacts.Sort((Contact left, Contact right) => { return(left.Name.CompareTo(right.Name)); }); try { ContactExtensions.SaveSortedContactsToFile(contacts, Filepath); var arrContacts = ContactExtensions.ReadFile(Filepath); for (int i = 0; i < contacts.Count; ++i) { Assert.IsTrue(contacts[i].Equals(arrContacts[i])); } } catch { Assert.IsTrue(false); } }