public void TestClone()
        {
            const string encoded = "Group Name: First Name <*****@*****.**>, Second Name <*****@*****.**>,\n Inner Group Name: First Inner Name <*****@*****.**>,\n Second Inner Name <*****@*****.**>;, Third Name <*****@*****.**>;";
            var          options = FormatOptions.Default.Clone();

            options.NewLineFormat = NewLineFormat.Unix;
            options.International = true;

            var inner = new GroupAddress("Inner Group Name");

            inner.Members.Add(new MailboxAddress("First Inner Name", "*****@*****.**"));
            inner.Members.Add(new MailboxAddress("Second Inner Name", "*****@*****.**"));

            var group = new GroupAddress("Group Name");

            group.Members.Add(new MailboxAddress("First Name", "*****@*****.**"));
            group.Members.Add(new MailboxAddress("Second Name", "*****@*****.**"));
            group.Members.Add(inner);
            group.Members.Add(new MailboxAddress("Third Name", "*****@*****.**"));

            var clone = group.Clone();

            Assert.AreEqual(0, group.CompareTo(clone), "CompareTo");

            var actual = clone.ToString(options, true);

            Assert.AreEqual(encoded, actual, "Encode");
        }
Beispiel #2
0
        public void TestCompareTo()
        {
            var list1 = new InternetAddressList();

            list1.Add(new GroupAddress("Local recipients", new InternetAddress[] {
                new MailboxAddress("", "phil"),
                new MailboxAddress("", "joe"),
                new MailboxAddress("", "alex"),
                new MailboxAddress("", "bob"),
            }));
            list1.Add(new MailboxAddress("Joey", "*****@*****.**"));
            list1.Add(new MailboxAddress("Chandler", "*****@*****.**"));

            var list2 = new InternetAddressList();

            list2.Add(new MailboxAddress("Chandler", "*****@*****.**"));
            list2.Add(new GroupAddress("Local recipients", new InternetAddress[] {
                new MailboxAddress("", "phil"),
                new MailboxAddress("", "joe"),
                new MailboxAddress("", "alex"),
                new MailboxAddress("", "bob"),
            }));
            list2.Add(new MailboxAddress("Joey", "*****@*****.**"));

            Assert.IsTrue(list1.CompareTo(list2) > 0, "CompareTo() should return < 0.");
            Assert.IsTrue(list2.CompareTo(list1) < 0, "CompareTo() should return > 0.");

            var mailbox = new MailboxAddress("Joe", "*****@*****.**");
            var group   = new GroupAddress("Joe", new InternetAddress[] {
                new MailboxAddress("Joe", "*****@*****.**")
            });

            // MailboxAddresses with the same name should always sort first
            Assert.IsTrue(mailbox.CompareTo(group) < 0, "CompareTo() should return < 0.");
            Assert.IsTrue(group.CompareTo(mailbox) > 0, "CompareTo() should return > 0.");

            Assert.IsTrue(mailbox.CompareTo(group.Members[0]) == 0, "CompareTo() should return 0.");
        }