예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }