Esempio n. 1
0
        public void ArgumentExceptionTests()
        {
            var mailbox = new MailboxAddress("Johnny Appleseed", "*****@*****.**");
            var route   = new [] { "route.com" };

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null, "name", route, "example.com"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", null, "example.com"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", null, "example.com"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress((IEnumerable <string>)null, "example.com"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null, "name", "example.com"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null));

            Assert.Throws <ArgumentNullException> (() => mailbox.Encoding = null);

            Assert.Throws <ArgumentNullException> (() => mailbox.CompareTo(null));
        }
Esempio n. 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.");
        }
        public void ArgumentExceptionTests()
        {
            var mailbox = new MailboxAddress("Johnny Appleseed", "*****@*****.**");
            var route   = new [] { "route.com" };

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null, "name", route, "*****@*****.**"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", null, "*****@*****.**"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", null, "*****@*****.**"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress((IEnumerable <string>)null, "*****@*****.**"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(route, null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null, "name", "*****@*****.**"));
            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(Encoding.UTF8, "name", null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress("name", null));

            Assert.Throws <ArgumentNullException> (() => new MailboxAddress(null));

            Assert.Throws <ArgumentNullException> (() => mailbox.Address = null);

            Assert.Throws <ArgumentNullException> (() => mailbox.Encoding = null);

            Assert.Throws <ArgumentNullException> (() => mailbox.CompareTo(null));

            Assert.Throws <ArgumentNullException> (() => mailbox.ToString(null, true));

            Assert.Throws <ArgumentNullException> (() => MailboxAddress.EncodeAddrspec(null));
            Assert.Throws <ArgumentNullException> (() => MailboxAddress.DecodeAddrspec(null));

            // SecureMailboxAddress
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(null, "name", route, "*****@*****.**", "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", null, "*****@*****.**", "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", route, null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", route, "*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", route, "*****@*****.**", "not hex encoded"));

            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("name", null, "*****@*****.**", "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("name", route, null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("name", route, "*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress("name", route, "*****@*****.**", "not hex encoded"));

            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress((IEnumerable <string>)null, "*****@*****.**", "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(route, null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(route, "*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress(route, "*****@*****.**", "not hex encoded"));

            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(null, "name", "*****@*****.**", "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", "*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress(Encoding.UTF8, "name", "*****@*****.**", "not hex encoded"));

            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("name", null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("name", "*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress("name", "*****@*****.**", "not hex encoded"));

            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress(null, "ffff"));
            Assert.Throws <ArgumentNullException> (() => new SecureMailboxAddress("*****@*****.**", null));
            Assert.Throws <ArgumentException> (() => new SecureMailboxAddress("*****@*****.**", "not hex encoded"));
        }