当前位置: 首页>>代码示例>>C#>>正文


C# Contact.UpdateFirstNames方法代码示例

本文整理汇总了C#中Contact.UpdateFirstNames方法的典型用法代码示例。如果您正苦于以下问题:C# Contact.UpdateFirstNames方法的具体用法?C# Contact.UpdateFirstNames怎么用?C# Contact.UpdateFirstNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contact的用法示例。


在下文中一共展示了Contact.UpdateFirstNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateFirstNameTest

        public void GenerateFirstNameTest()
        {
            Contact contact = new Contact { Name = "Todd", FirstNames = "Test business", };
            contact.AddPerson(new Person { FirstName="John", IncludeInDisplayName=true});
            contact.AddPerson(new Person { FirstName="Anne", IncludeInDisplayName=true});
            contact.AddPerson(new Person { FirstName="David", IncludeInDisplayName=true});

            //Test - 3 people included
            string expected = "John, Anne & David";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.FirstNames);
            //Test - 2 people included
            contact.People[2].IncludeInDisplayName = false;
            expected = "John & Anne";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.FirstNames);
            //Test - just one person included
            contact.People[1].IncludeInDisplayName = false;
            expected = "John";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.FirstNames);
            //Test - error if no people included
            contact.People[0].IncludeInDisplayName = false;
            //ExceptionAssert.Throws<ArgumentException>(() => contact.UpdateFirstNames());
            //Test - if business, return Display name directly
            contact.IsBusiness = true;
            expected = "";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.FirstNames);
        }
开发者ID:honchoman,项目名称:ContactManager,代码行数:30,代码来源:ContactTest.cs

示例2: GetAddressBookFromLookup

        /// <summary>
        /// Gets the address book from CSV dictionary.
        /// </summary>
        //(This would be private, but test generation wouldn't work...)
        internal static AddressBook GetAddressBookFromLookup(IEnumerable<Dictionary<string, string>> csv)
        {
            AddressBook book = new AddressBook();
            foreach(var row in csv)
            {
                bool isbusiness = (row[Keys.HomePhone] == "" && row[Keys.WorkPhone] != ""); //is business if no home phone AND has business phone
                bool multiperson = row[Keys.FirstName].Contains('&');
                var contact = new Contact
                {
                    Name = row[Keys.LastName],
                    Email = ContactMailLogic(row, multiperson),
                    IsBusiness = isbusiness,
                    PhoneNumber = isbusiness ? row[Keys.WorkPhone] : row[Keys.HomePhone],
                    Address = GetAddress(row),
                    Notes = row[Keys.Notes]
                };
                //Add one or two people, based on first name containing &
                if(multiperson)
                {
                    contact.AddPerson(FirstPerson(row, false));
                    contact.AddPerson(SecondPerson(row));
                }
                else
                {
                    contact.AddPerson(FirstPerson(row, true));
                }

                //Update first names with new people
                contact.UpdateFirstNames();
                book.AddContact(contact);
            }

            return book;
        }
开发者ID:honchoman,项目名称:ContactManager,代码行数:38,代码来源:ImportTools.cs

示例3: OrderByNameDisplayNameTest

        public void OrderByNameDisplayNameTest()
        {
            Contact contact = new Contact { Name = "Todd", FirstNames = "Test business", };
            contact.AddPerson(new Person { FirstName = "John", IncludeInDisplayName = true });
            contact.AddPerson(new Person { FirstName = "Anne", IncludeInDisplayName = true });
            contact.AddPerson(new Person { FirstName = "David", IncludeInDisplayName = true });

            //Test - 3 people included
            string expected = "John, Anne & David Todd";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.DisplayName);
            expected = "Todd, John, Anne & David";
            Assert.Equal(expected, contact.OrderByName);
            //Test - 2 people included
            contact.People[2].IncludeInDisplayName = false;
            expected = "John & Anne Todd";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.DisplayName);
            expected = "Todd, John & Anne";
            Assert.Equal(expected, contact.OrderByName);
            //Test - just one person included
            contact.People[1].IncludeInDisplayName = false;
            expected = "John Todd";
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.DisplayName);
            expected = "Todd, John";
            Assert.Equal(expected, contact.OrderByName);
            //Test - if business, return Display name directly
            contact.IsBusiness = true;
            expected = contact.Name;
            contact.UpdateFirstNames();
            Assert.Equal(expected, contact.DisplayName);
            Assert.Equal(expected, contact.OrderByName);
        }
开发者ID:honchoman,项目名称:ContactManager,代码行数:34,代码来源:ContactTest.cs


注:本文中的Contact.UpdateFirstNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。