コード例 #1
0
        public void SearchAddressTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Drottningsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Parken", 0));

            Contact c1 = new Contact("John Johansson");
            Contact c2 = new Contact("John Johansson");
            Contact c3 = new Contact("Hans Johansson");
            Contact c4 = new Contact("Karl Johansson");
            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            Assert.AreEqual(spb.Search("Ku").Count, 1);
            Assert.AreEqual(spb.Search("Ku").FirstOrDefault(), c);
        }
コード例 #2
0
        public void TestFieldListenersTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");

            spb.addContact(c);

            Assert.AreEqual(spb.Search("Jo").Count, 1);

            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));

            Assert.AreEqual(spb.Search("Ku").Count, 1);

            c.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Assert.AreEqual(spb.Search("sten").Count, 1);

            c.removeAddress(c.Addresses.ElementAt(0));

            Assert.AreEqual(spb.Search("Ku").Count, 0);
            Assert.AreEqual(spb.Search("sten").Count, 1);
        }
コード例 #3
0
        public void SearchMultipleFieldsTest()
        {
            SearchablePhoneBook spb = new SearchablePhoneBook();
            Contact c = new Contact("John Johansson");
            c.addAddress(new Address("Sverige", "Göteborg", "Kungsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Drottningsgatan", 0));
            c.addAddress(new Address("Sverige", "Göteborg", "Parken", 0));
            c.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Contact c1 = new Contact("John Johansson");
            c1.addAddress(new Address("Sverige", "Göteborg", "Kugsten 15", 0));

            Contact c2 = new Contact("John Johansson");
            c2.addNumber(new Number("Kugge 0720564", ContactType.WORK, 0));

            Contact c3 = new Contact("Hans Johansson");
            c3.addEmail(new Email("*****@*****.**", ContactType.WORK, 0));

            Contact c4 = new Contact("Karl Johansson");
            c4.addEmail(new Email("*****@*****.**",ContactType.HOME,0));

            spb.addContact(c);
            spb.addContact(c1);
            spb.addContact(c2);
            spb.addContact(c3);
            spb.addContact(c4);

            Assert.AreEqual(spb.Search("Ku").Count, 5);
        }