public void testMergeWithGoogle() { try { GoogleContactDownloader gcd = new GoogleContactDownloader(GoogleContactDownloader.TestUser, GoogleContactDownloader.TestPass); IContact c1 = new GContactSync.Contact("John Doe", "*****@*****.**"); IContactManager m1 = new MockContactManager { GetContactsImpl = () => { var l = new List <IContact>(); l.Add(c1); return(l); } }; IEnumerable <IContact> googleContacts = gcd.GetContacts(); googleContacts = googleContacts.Where(c => c.FullName != null && c.FullName.Contains("Doe")); ContactMerger.Merge(gcd, m1, googleContacts, m1.GetContacts()); } catch (System.Exception ex) { throw ex; } }
public void TestMergeBothWays() { Contact c1 = new Contact("John Doe", "*****@*****.**"); IContactManager m1 = new MockContactManager { GetContactsImpl = () => { var l = new List <IContact>(); l.Add(c1); return(l); } }; Contact c2 = new Contact("John Doe", "*****@*****.**"); IContactManager m2 = new MockContactManager { GetContactsImpl = () => { var l = new List <IContact>(); l.Add(c2); return(l); } }; Assert.IsTrue(c1.Emails.Contains("*****@*****.**")); Assert.IsFalse(c2.Emails.Contains("*****@*****.**")); Assert.IsFalse(c1.Emails.Contains("*****@*****.**")); Assert.IsTrue(c2.Emails.Contains("*****@*****.**")); ContactMerger.Merge(m1, m2, m1.GetContacts(), m2.GetContacts()); Assert.IsTrue(c1.Emails.Contains("*****@*****.**")); Assert.IsTrue(c2.Emails.Contains("*****@*****.**")); Assert.IsTrue(c1.Emails.Contains("*****@*****.**")); Assert.IsTrue(c2.Emails.Contains("*****@*****.**")); }
public void TestMergerPerformance() { // Runtime should be pretty negligible, around 0.1s const int nb = 5000; List <IContact> l1 = new List <IContact>(); List <IContact> l2 = new List <IContact>(); for (int i = 0; i < nb; ++i) { string s1 = Guid.NewGuid().ToString(); string s2 = Guid.NewGuid().ToString(); string s3 = Guid.NewGuid().ToString(); IContact c1 = new Contact(s1); c1.addMail(s2); c1.addMail(s3); l1.Add(c1); IContact c2 = new Contact(s1); c2.addMail(s2); c2.addMail(s3); l2.Add(c2); } IContactManager m1 = new MockContactManager { GetContactsImpl = () => { return(l1); } }; IContactManager m2 = new MockContactManager { GetContactsImpl = () => { return(l2); } }; ContactMerger.Merge(m1, m2, m1.GetContacts(), m2.GetContacts()); }
public void TestMergeTheOtherWay() { List <IContact> l1 = new List <IContact>(); List <IContact> l2 = new List <IContact>(); Contact c2 = new Contact("John Doe", "*****@*****.**"); l2.Add(c2); IContactManager m1 = new MockContactManager { GetContactsImpl = () => { return(l1); } }; IContactManager m2 = new MockContactManager { GetContactsImpl = () => { return(l2); } }; ContactMerger.Merge(m1, m2, m1.GetContacts(), m2.GetContacts()); Assert.AreEqual(l1.Count(), 1); IContact c1 = l1.ElementAt(0); Assert.AreEqual(c1.FullName, "John Doe"); Assert.IsTrue(c1.Emails.Contains("*****@*****.**")); }
public void TestGetEmptyListOfContacts() { IContactManager cd = new MockContactManager { GetContactsImpl = () => { return(new List <IContact>()); } }; IEnumerable <IContact> contacts = cd.GetContacts(); Assert.IsFalse(contacts.GetEnumerator().MoveNext()); }
public void TestGetListOfOneContact() { IContactManager cd = new MockContactManager { GetContactsImpl = () => { var l = new List <IContact>(); l.Add(new GContactSync.Contact("John Doe")); return(l); } }; IEnumerable <IContact> contacts = cd.GetContacts(); var it = contacts.GetEnumerator(); Assert.IsTrue(it.MoveNext()); Assert.IsTrue(it.Current.FullName.Equals("John Doe")); }