Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        public void TestContactIndexerFindsExistingContacts()
        {
            List<IContact> contacts = new List<IContact>();
            contacts.Add(new Contact("John Doe"));
            contacts.Add(new Contact("Another contact"));
            contacts.Add(new Contact("", "*****@*****.**"));
            contacts.Add(new Contact("", "*****@*****.**"));
            contacts.Add(new Contact((string)null));

            IContact c = new Contact("MultiMail");
            c.addMail("*****@*****.**");
            c.addMail("*****@*****.**");
            contacts.Add(c);

            ContactIndexer indexer = new ContactIndexer(contacts);
            Assert.AreEqual(1, indexer.GetContactsFor("John Doe").Count());
            Assert.AreEqual(0, indexer.GetContactsFor("Foo Bar").Count());
            Assert.AreEqual(2, indexer.GetContactsFor("*****@*****.**").Count());
            Assert.AreEqual(1, indexer.GetContactsFor("MultiMail").Count());
            Assert.AreEqual(1, indexer.GetContactsFor("*****@*****.**").Count());
            Assert.AreEqual(1, indexer.GetContactsFor("*****@*****.**").Count());
            Assert.AreEqual(0, indexer.GetContactsFor(null).Count());

            Assert.AreEqual(1, indexer.GetSameContactsAs(new Contact("MultiMail")).Count());
            // Can match Name to email...
            Assert.AreEqual(2, indexer.GetSameContactsAs(new Contact("*****@*****.**")).Count());
        }
Ejemplo n.º 3
0
 public void TestCanCopyContact()
 {
     string mail = "*****@*****.**";
     IContact c1 = new Contact("J. Doe", mail);
     IContact c2 = new Contact(c1);
     Assert.IsTrue(c1.IsSameAs(c2));
     IEnumerable<string> A = c1.Emails;
     IEnumerable<string> B = c2.Emails;
     Assert.IsTrue(A.Count() == B.Count() && A.Intersect(B).Count() == B.Count());
 }
Ejemplo n.º 4
0
        public void TestCreateAGoogleContact()
        {
            GContactSync.Contact c = new GContactSync.Contact("John Doe");
            c.addMail("*****@*****.**");

            GoogleContactDownloader gcd = new GoogleContactDownloader(GoogleContactDownloader.TestUser, GoogleContactDownloader.TestPass);
            int oldCount = gcd.GetContacts().Count();

            IContact gc = gcd.NewContact(c);
            gc.Update();

            Assert.AreEqual(gcd.GetContacts().Count(), oldCount + 1);
        }
Ejemplo n.º 5
0
        public void TestCreateAGoogleContact()
        {
            GContactSync.Contact c = new GContactSync.Contact("John Doe");
            c.addMail("*****@*****.**");

            GoogleContactDownloader gcd = new GoogleContactDownloader(GoogleContactDownloader.TestUser, GoogleContactDownloader.TestPass);
            int oldCount = gcd.GetContacts().Count();

            IContact gc = gcd.NewContact(c);

            gc.Update();

            Assert.AreEqual(gcd.GetContacts().Count(), oldCount + 1);
        }
Ejemplo n.º 6
0
 public void TestWithNullNameAndSameMailIsNoop()
 {
     Contact c1 = new Contact("", "*****@*****.**");
     Contact c2 = new Contact(null, "*****@*****.**");
     Assert.IsFalse(c1.MergeFrom(c2));
     Assert.IsFalse(c2.MergeFrom(c1));
 }
Ejemplo n.º 7
0
        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("*****@*****.**"));
        }
Ejemplo n.º 8
0
 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());
 }
Ejemplo n.º 9
0
 public void TestMergingDoesNotDuplicateEmails()
 {
     IContact c1 = new Contact("J. Doe", "*****@*****.**");
     IContact c2 = new Contact("John Doe", "*****@*****.**");
     bool merged = c2.MergeFrom(c1);
     Assert.IsFalse(merged);
     Assert.AreEqual(c2.FullName, "John Doe");
     Assert.AreEqual(c2.Emails.Count(), 1);
     Assert.IsTrue(c2.Emails.Contains("*****@*****.**"));
 }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
 public void TestTwoContactsWithDifferentFullNamesAreNotEqual()
 {
     IContact c1 = new Contact("John Doe");
     IContact c2 = new Contact("Nancy Botwin");
     Assert.IsFalse(c1.IsSameAs(c2));
 }
Ejemplo n.º 12
0
 public void TestAnEmptyContactHasNoInformation()
 {
     IContact c1 = new Contact("");
     Assert.IsFalse(c1.ContainsSomeInformation());
 }
Ejemplo n.º 13
0
 public void TestMergingCopiesFullNameIfDestNull()
 {
     string fn = "J. Doe";
     IContact c1 = new Contact(fn);
     IContact c2 = new Contact("");
     c2.MergeFrom(c1);
     Assert.AreEqual(c2.FullName, fn);
 }
Ejemplo n.º 14
0
 public void TestAContactWithAMailHasSomeInformation()
 {
     IContact c1 = new Contact("", "*****@*****.**");
     Assert.IsTrue(c1.ContainsSomeInformation());
 }
Ejemplo n.º 15
0
 public void TestAContactWithANameHasSomeInformation()
 {
     IContact c1 = new Contact("John Doe");
     Assert.IsTrue(c1.ContainsSomeInformation());
 }
Ejemplo n.º 16
0
 public void TestTwoContactsWithSameFullNameAreEqual()
 {
     IContact c1 = new Contact("John Doe");
     IContact c2 = new Contact("John Doe", "*****@*****.**");
     Assert.IsTrue(c1.IsSameAs(c2));
 }
Ejemplo n.º 17
0
 public void TestTwoContactsWithSameEmailAreEqualEvenWithDifferentNames()
 {
     IContact c1 = new Contact("J. Doe", "*****@*****.**");
     IContact c2 = new Contact("John Doe", "*****@*****.**");
     Assert.IsTrue(c1.IsSameAs(c2));
 }
Ejemplo n.º 18
0
 public void TestTwoContactsWithSameEmailAreEqual()
 {
     string mail = "*****@*****.**";
     IContact c1 = new Contact("", mail);
     IContact c2 = new Contact("", mail);
     Assert.IsTrue(c1.IsSameAs(c2));
 }
Ejemplo n.º 19
0
 public void TestMergingDoesNotCopyFullNameIfDestNotNull()
 {
     string fn = "J. Doe";
     IContact c1 = new Contact(fn);
     IContact c2 = new Contact("John Doe");
     c2.MergeFrom(c1);
     Assert.AreEqual(c2.FullName, "John Doe");
 }
Ejemplo n.º 20
0
 public void TestInsertingEmptyEmailAddressIsNoop()
 {
     IContact c1 = new Contact("John Doe");
     Assert.IsFalse(c1.addMail(""));
     Assert.AreEqual(c1.Emails.Count(), 0);
 }
Ejemplo n.º 21
0
        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("*****@*****.**"));
        }
Ejemplo n.º 22
0
 public IContact NewContact(IContact other)
 {
     IContact newC = new Contact(other);
     GetContactsImpl().Add(newC);
     return newC;
 }
Ejemplo n.º 23
0
 public void TestMergingAddsEmailsFromOther()
 {
     IContact c1 = new Contact("J. Doe", "*****@*****.**");
     IContact c2 = new Contact("John Doe", "*****@*****.**");
     bool merged = c2.MergeFrom(c1);
     Assert.IsTrue(merged);
     Assert.AreEqual(c2.FullName, "John Doe");
     Assert.AreEqual(c2.Emails.Count(), 2);
     Assert.IsTrue(c2.Emails.Contains("*****@*****.**"));
     Assert.IsTrue(c2.Emails.Contains("*****@*****.**"));
 }
Ejemplo n.º 24
0
 public void TestTwoContactsWithCommonEmailAreEqualEvenWithDifferentNames()
 {
     string mail = "*****@*****.**";
     IContact c1 = new Contact("J. Doe", mail);
     IContact c2 = new Contact("John Doe", "*****@*****.**");
     Assert.IsFalse(c1.IsSameAs(c2));
     c2.addMail(mail);
     Assert.IsTrue(c1.IsSameAs(c2));
 }