private static void TestParseDomain(string str, string expected) { var na = new NamedAddress("b <example@" + str + ">"); Address addr = na.Address; Assert.AreEqual(expected, addr.Domain); }
private static void TestParseLocalPart(string str, string expected) { var na = new NamedAddress("b <" + str + "@example.com>"); Address addr = na.Address; Assert.AreEqual(expected, addr.LocalPart); }
public void TestNamedAddress() { { object objectTemp = "\"Me \" <*****@*****.**>"; object objectTemp2 = new NamedAddress( "Me ", "*****@*****.**").ToString(); Assert.AreEqual(objectTemp, objectTemp2); } { object objectTemp = "\" Me\" <*****@*****.**>"; object objectTemp2 = new NamedAddress( " Me", "*****@*****.**").ToString(); Assert.AreEqual(objectTemp, objectTemp2); } try { Assert.AreEqual(null, new Address(String.Empty)); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("a [email protected]")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new NamedAddress("a [email protected]")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new NamedAddress("ab.example.com")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("ab@exa mple.example")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("[email protected] addr")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { { string stringTemp = new NamedAddress("Me <*****@*****.**>").ToString(); Assert.AreEqual( "Me <*****@*****.**>", stringTemp); } } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { if ((new NamedAddress("Me\u00e0 <*****@*****.**>")) == null) { Assert.Fail(); } } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { if ((new NamedAddress("\"Me\" <*****@*****.**>")) == null) { Assert.Fail(); } } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { if ((new NamedAddress("\"Me\u00e0\" <*****@*****.**>")) == null) { Assert.Fail(); } } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("Me <*****@*****.**>")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("Me\u00e0 <*****@*****.**>")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("\"Me\" <*****@*****.**>")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { Assert.AreEqual(null, new Address("\"Me\u00e0\" <*****@*****.**>")); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } try { const string ValueSt = "Me <*****@*****.**>, Fred <*****@*****.**>"; Assert.AreEqual(null, new NamedAddress(ValueSt)); Assert.Fail("Should have failed"); } catch (ArgumentException) { new Object(); } catch (Exception ex) { Assert.Fail(ex.ToString()); throw new InvalidOperationException(String.Empty, ex); } Assert.IsFalse(new NamedAddress("*****@*****.**").IsGroup); { string stringTemp = new NamedAddress("*****@*****.**").Name; Assert.AreEqual( "*****@*****.**", stringTemp); } { string stringTemp = new NamedAddress( "*****@*****.**").Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } Assert.AreEqual( "\"(lo cal)\"@example.com", new Address("\"(lo cal)\"@example.com").ToString()); { string stringTemp = new Address("*****@*****.**").LocalPart; Assert.AreEqual( "local", stringTemp); } { string stringTemp = new Address("*****@*****.**").Domain; Assert.AreEqual( "example.com", stringTemp); } }
public void TestToString() { const string mbox = "Me <@example.org,@example.net,@example.com:[email protected]>"; var result = new NamedAddress(mbox); { string stringTemp = result.ToString(); Assert.AreEqual( "Me <*****@*****.**>", stringTemp); } }
public void TestName() { NamedAddress na; na = new NamedAddress("=?utf-8?q?Me?=", "*****@*****.**"); Assert.AreEqual("=?utf-8?q?Me?=", na.Name); }
public void TestNamedAddressParse() { NamedAddress na; IList<NamedAddress> groupAddr; na = new NamedAddress("*****@*****.**"); Assert.AreEqual("*****@*****.**", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } { string stringTemp = na.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = new NamedAddress("John's Office <*****@*****.**>"); Assert.AreEqual("John's Office", na.Name); na = new NamedAddress("Me <*****@*****.**>"); Assert.AreEqual("Me", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = new NamedAddress("(comment) Me (comment) <*****@*****.**> (comment)"); Assert.AreEqual("Me", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = new NamedAddress("=?utf-8?q?Me?= <*****@*****.**>"); Assert.AreEqual("Me", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } { string stringTemp = na.ToString(); Assert.AreEqual( "Me <*****@*****.**>", stringTemp); } na = new NamedAddress("=?utf-8?q?John=27s_Office?= <" + "*****@*****.**>"); Assert.AreEqual("John's Office", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } { string stringTemp = na.ToString(); Assert.AreEqual( "John's Office <*****@*****.**>", stringTemp); } na = new NamedAddress("\"Me\" <*****@*****.**>"); Assert.AreEqual("Me", na.Name); Assert.IsFalse(na.IsGroup); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } { string stringTemp = na.ToString(); Assert.AreEqual( "Me <*****@*****.**>", stringTemp); } //------------ na = new NamedAddress("Group: \"Me\" <*****@*****.**>;"); Assert.IsTrue(na.IsGroup); groupAddr = na.GroupAddresses; Assert.AreEqual(1, groupAddr.Count); na = groupAddr[0]; Assert.AreEqual("Me", na.Name); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = new NamedAddress("Group: \"Me\" <*****@*****.**>, Fred <*****@*****.**>;"); Assert.IsTrue(na.IsGroup); { string stringTemp = na.ToString(); const string s1 = "Group: Me <*****@*****.**>, Fred <*****@*****.**>;" ; Assert.AreEqual(s1, stringTemp); } groupAddr = na.GroupAddresses; Assert.AreEqual(2, groupAddr.Count); na = groupAddr[0]; Assert.AreEqual("Me", na.Name); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = groupAddr[1]; Assert.AreEqual("Fred", na.Name); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } //------------ na = new NamedAddress("Group: \"Me\" <*****@*****.**>, [email protected];"); Assert.AreEqual("Group", na.Name); Assert.IsTrue(na.IsGroup); { string stringTemp = na.ToString(); const string s1 = "Group: Me <*****@*****.**>, [email protected];"; Assert.AreEqual(s1, stringTemp); } groupAddr = na.GroupAddresses; Assert.AreEqual(2, groupAddr.Count); na = groupAddr[0]; Assert.AreEqual("Me", na.Name); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } na = groupAddr[1]; Assert.AreEqual("*****@*****.**", na.Name); { string stringTemp = na.Address.ToString(); Assert.AreEqual( "*****@*****.**", stringTemp); } }
public void TestIsGroup() { // not implemented yet NamedAddress na; var naList = new List<NamedAddress>(); naList.Add(new NamedAddress("*****@*****.**")); na=new NamedAddress("test",naList); Assert.IsTrue(na.IsGroup); na = new NamedAddress("*****@*****.**"); Assert.IsFalse(na.IsGroup); na = new NamedAddress("Test <*****@*****.**>"); Assert.IsFalse(na.IsGroup); na = new NamedAddress("Group: [email protected];"); Assert.IsTrue(na.IsGroup); na = new NamedAddress("Group: Test <*****@*****.**>;"); Assert.IsTrue(na.IsGroup); na = new NamedAddress("Group:;"); Assert.IsTrue(na.IsGroup); }