Beispiel #1
0
        public void StartsWithPrintTest()
        {
            var book = new AddressBook();
            var a1   = new Contact {
                Name = "a1", Number = "1"
            };
            var b1 = new Contact {
                Name = "b1", Number = "1"
            };
            var b2 = new Contact {
                Name = "b2", Number = "2"
            };
            var b3 = new Contact {
                Name = "b3", Number = "3"
            };
            var c1 = new Contact {
                Name = "c1", Number = "1"
            };

            book.AddContact(b2);
            book.AddContact(b1);
            book.AddContact(b3);
            book.AddContact(c1);
            book.AddContact(a1);

            var expected = new List <Contact> {
                b1, b2, b3
            };
            var actual = book.GetContactStartsWith("b").ToSortedList();

            CollectionAssert.AreEqual(expected, actual);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            // Create a few contacts
            Contact bob = new Contact()
            {
                FirstName = "Bob",
                LastName  = "Smith",
                Email     = "*****@*****.**",
                Address   = "100 Some Ln, Testville, TN 11111"
            };
            Contact sue = new Contact()
            {
                FirstName = "Sue",
                LastName  = "Jones",
                Email     = "*****@*****.**",
                Address   = "322 Hard Way, Testville, TN 11111"
            };
            Contact juan = new Contact()
            {
                FirstName = "Juan",
                LastName  = "Lopez",
                Email     = "*****@*****.**",
                Address   = "888 Easy St, Testville, TN 11111"
            };


            // Create an AddressBook and add some contacts to it
            AddressBook addressBook = new AddressBook();

            addressBook.AddContact(bob);
            addressBook.AddContact(sue);
            addressBook.AddContact(juan);

            // Try to addd a contact a second time
            addressBook.AddContact(sue);


            // Create a list of emails that match our Contacts
            List <string> emails = new List <string>()
            {
                "*****@*****.**",
                "*****@*****.**",
                "*****@*****.**",
            };

            // Insert an email that does NOT match a Contact
            emails.Insert(1, "*****@*****.**");


            //  Search the AddressBook by email and print the information about each Contact
            foreach (string email in emails)
            {
                Contact contact = addressBook.GetByEmail(email);
                Console.WriteLine("----------------------------");
                Console.WriteLine($"Name: {contact.FullName}");
                Console.WriteLine($"Email: {contact.Email}");
                Console.WriteLine($"Address: {contact.Address}");
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var logger = new CAB.ConsoleLogger.ConsoleLogger();

            var abUK = new AddressBook(logger);

            abUK.Country = Countries.UK;
            abUK.AddContact(fnGetContacts());
            abUK.AddContact(fnGetContacts());
            abUK.Display();
            Console.ReadKey();
        }
    static void Main(string[] args)
    {
        // Create a few contacts utilizing the constructor
        Contact bob = new Contact("Bob", "Smith", "*****@*****.**", "100 Some ln Testville, TN 11111");
        Contact sue = new Contact("Sue", "Jones", "*****@*****.**", "322 Hard Way, Testville, TN 11111");
        Contact juan = new Contact("Juan", "Lopez", "*****@*****.**", "888 EasyVille, Testville, TN 12341");

        // Create an AddressBook and add some contacts to it
        AddressBook addressBook = new AddressBook();

        //Adding each of the Contacts from above to the address book (Dictionaary)
        addressBook.AddContact(bob);
        addressBook.AddContact(sue);
        addressBook.AddContact(juan);

        // Try to adda  contact a second time
        //Will likely throw an error becuase we dont want to add the same contact twice will print message at bottom
        addressBook.AddContact(sue);

        // Create a list of emails that match our Contacts
        List<string> emails = new List<string>() {
            "*****@*****.**",
            "*****@*****.**",
            "*****@*****.**",
        };

        // Insert an email that does NOT match a Contact
        //Will likely throw an error becuase we dont want to add the same contact twice will print message at bottom
        emails.Insert(1, "*****@*****.**");

        //  Search the AddressBook by email and print the information about each Contact
        foreach (string email in emails)
        {
        /*
        Add try/catch blocks to prevent the program from crashing
            Print meaningful error messages in the catch blocks.
        */
            try{
            Contact contact = addressBook.GetByEmail(email);
                Console.WriteLine("----------------------------");
                Console.WriteLine($"Name: {contact.FullName}");
                Console.WriteLine($"Email: {contact.Email}");
                Console.WriteLine($"Address: {contact.Address}");
            }
            catch(KeyNotFoundException){
                Console.WriteLine("You are trying to add the same contact more than once.");
            }
        }
    }
Beispiel #5
0
        public void AddContact_TwoContact_CorrectOrder()
        {
            var addressBook = new AddressBook();

            addressBook.AddContact(new Contact()
            {
                FirstName = "Magnus",
                LastName = "Ahlberg"
            });

            addressBook.AddContact(new Contact()
            {
                FirstName = "Hans",
                LastName = "Fjällmark"
            });

            Assert.That(addressBook.GetContacts(), Has.Count.EqualTo(2));
        }
Beispiel #6
0
        public void AddContact_TwoContact_CorrectOrder()
        {
            var addressBook = new AddressBook();

            addressBook.AddContact(new Contact()
            {
                FirstName = "Magnus",
                LastName  = "Ahlberg"
            });

            addressBook.AddContact(new Contact()
            {
                FirstName = "Hans",
                LastName  = "Fjällmark"
            });

            Assert.That(addressBook.GetContacts(), Has.Count.EqualTo(2));
        }
Beispiel #7
0
        public void Search_SearchingForNumber_CorrectHits(string query, int hits)
        {
            var addressBook = new AddressBook();

            var contact = Contact();

            contact.AddContactEntry(new PhoneNumer("0702-937123"));
            addressBook.AddContact(contact);

            var contact2 = Contact();

            contact2.AddContactEntry(new PhoneNumer("0701-879874"));
            addressBook.AddContact(contact2);

            var contacts = addressBook.Search(query);

            Assert.That(contacts, Has.Count.EqualTo(hits));
        }
Beispiel #8
0
        public void Search_SearchingForEmail_CorrectHits(string query, int hits)
        {
            var addressBook = new AddressBook();

            var contact = Contact();

            contact.AddContactEntry(new Email("*****@*****.**"));
            addressBook.AddContact(contact);

            var contact2 = Contact();

            contact2.AddContactEntry(new Email("*****@*****.**"));
            addressBook.AddContact(contact2);

            var contacts = addressBook.Search(query);

            Assert.That(contacts, Has.Count.EqualTo(hits));
        }
Beispiel #9
0
        public void AddContact_GetContactsByLastName_CorrectOrder()
        {
            var addressBook = new AddressBook();

            addressBook.AddContact(new Contact()
            {
                FirstName = "Hans",
                LastName = "Fjällmark"
            });
            addressBook.AddContact(new Contact()
            {
                FirstName = "Magnus",
                LastName = "Ahlberg"
            });

            var contacts = addressBook.GetContactsOrderedByLastName();

            Assert.That(contacts, Has.Count.EqualTo(2));
            Assert.That(contacts[0].FirstName, Is.EqualTo("Magnus"));
            Assert.That(contacts[1].FirstName, Is.EqualTo("Hans"));
        }
Beispiel #10
0
        public void AddContact_GetContactsByLastName_CorrectOrder()
        {
            var addressBook = new AddressBook();

            addressBook.AddContact(new Contact()
            {
                FirstName = "Hans",
                LastName  = "Fjällmark"
            });
            addressBook.AddContact(new Contact()
            {
                FirstName = "Magnus",
                LastName  = "Ahlberg"
            });

            var contacts = addressBook.GetContactsOrderedByLastName();

            Assert.That(contacts, Has.Count.EqualTo(2));
            Assert.That(contacts[0].FirstName, Is.EqualTo("Magnus"));
            Assert.That(contacts[1].FirstName, Is.EqualTo("Hans"));
        }
Beispiel #11
0
        /**
         * Imports a single buddy group.
         */

        private void ImportBuddyGroup(TrillianBuddyGroup group)
        {
            foreach (TrillianBuddy buddy in group.Buddies)
            {
                IResource account = FindOrCreateTrillianAccount(buddy.Protocol, buddy.Address, buddy.Nick);
                IResource contact = account.GetLinkProp(_propTrillianAcct);

                _trillianAB.AddContact(contact);
            }
            foreach (TrillianBuddyGroup childGroup in group.Groups)
            {
                ImportBuddyGroup(childGroup);
            }
        }
Beispiel #12
0
        private void newContact_Click(object sender, EventArgs e)
        {
            dlgContact dlg = new dlgContact();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                IMORZEContact contact = dlg.MORZEContact;
                string        err     = m_book.AddContact(contact);
                if (string.IsNullOrEmpty(err) == true)
                {
                    m_book.Save();
                    AddContactToList(contact);
                }
                else
                {
                    MessageBox.Show(err, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            dlg.Dispose();
        }
Beispiel #13
0
        private static void OnNewContactSaved(IResource res, object tag)
        {
            Trace.WriteLine("OnNewContactSaved is called for " + res.DisplayName);
            // NB: SetPropAsync does not work properly under Windows2000
//            new ResourceProxy( res ).SetPropAsync( ContactHelper._propUserCreated, true );
            new ResourceProxy(res).SetProp(ContactManager._propUserCreated, true);

            if (tag != null)
            {
                NewContactLocation location = (NewContactLocation)tag;
                if (location.AddressBook != null)
                {
                    AddressBook ab = new AddressBook(location.AddressBook);
                    ab.AddContact(res);
                }
                if (location.Category != null)
                {
                    Core.CategoryManager.AddResourceCategory(res, location.Category);
                }
            }

            Core.WorkspaceManager.AddToActiveWorkspace(res);
        }
 public void GivenContactDetail_ShouldAnalyse_ReturnContactCount()
 {
     //Arrange
     address.AddContact();
 }
Beispiel #15
0
        public void Search_SearchingForNumber_CorrectHits(string query, int hits)
        {
            var addressBook = new AddressBook();

            var contact = Contact();
            contact.AddContactEntry(new PhoneNumer("0702-937123"));
            addressBook.AddContact(contact);

            var contact2 = Contact();
            contact2.AddContactEntry(new PhoneNumer("0701-879874"));
            addressBook.AddContact(contact2);

            var contacts = addressBook.Search(query);

            Assert.That(contacts, Has.Count.EqualTo(hits));
        }
Beispiel #16
0
        public void Search_SearchingForEmail_CorrectHits(string query, int hits)
        {
            var addressBook = new AddressBook();

            var contact = Contact();
            contact.AddContactEntry(new Email("*****@*****.**"));
            addressBook.AddContact(contact);

            var contact2 = Contact();
            contact2.AddContactEntry(new Email("*****@*****.**"));
            addressBook.AddContact(contact2);

            var contacts = addressBook.Search(query);

            Assert.That(contacts, Has.Count.EqualTo(hits));
        }
Beispiel #17
0
        private void ImportICQContact(IMirandaContact contact, IMirandaContactSettings settings,
                                      string group, bool myself)
        {
            if (!settings.Settings.Contains("UIN"))
            {
                return;
            }

            int    UIN       = (int)settings.Settings ["UIN"];
            string firstName = (string)settings.Settings ["FirstName"];
            string lastName  = (string)settings.Settings ["LastName"];
            string email     = (string)settings.Settings ["e-mail"];
            string nick      = (string)settings.Settings ["Nick"];

            if (firstName == null)
            {
                firstName = "";
            }
            if (lastName == null)
            {
                lastName = "";
            }

            IResource contactRes;
            IResource icqAccount = Core.ResourceStore.FindUniqueResource(ResourceTypes.MirandaICQAccount,
                                                                         Props.UIN, UIN);

            if (icqAccount == null || !icqAccount.HasProp(Props.MirandaAcct))
            {
                if (icqAccount == null)
                {
                    icqAccount = Core.ResourceStore.BeginNewResource(ResourceTypes.MirandaICQAccount);
                    icqAccount.SetProp(Props.UIN, UIN);
                    icqAccount.SetProp(Props.NickName, nick);
                    icqAccount.EndUpdate();
                }

                if (firstName == "" && lastName == "")
                {
                    string contactName;
                    if (!string.IsNullOrEmpty(nick))
                    {
                        contactName = nick;
                    }
                    else
                    {
                        contactName = UIN.ToString();
                    }

                    IContact ct = Core.ContactManager.FindOrCreateContact(email, contactName);
                    contactRes = ct.Resource;
                }
                else
                {
                    IContact ct = Core.ContactManager.FindOrCreateContact(email, firstName, lastName);
                    contactRes = ct.Resource;
                }

                icqAccount.AddLink(Props.MirandaAcct, contactRes);
            }
            else
            {
                contactRes = icqAccount.GetLinkProp(Props.MirandaAcct);
            }

            AssignCategory(contactRes, group);
            if (_mirandaAB != null)
            {
                _mirandaAB.AddContact(contactRes);
            }

            else if (!contactRes.HasLink(Props.MirandaAcct, icqAccount))
            {
                contactRes.AddLink(Props.MirandaAcct, icqAccount);
            }

            if (myself)
            {
                _selfContact          = contactRes;
                _selfAccounts ["ICQ"] = icqAccount;
            }
            else
            {
                ImportContactEvents(contact, icqAccount, "ICQ");
            }
        }