public void TestParser() { EmailAddressParser emailaddressparser=new EmailAddressParser(); String name1="Test Tester"; String email1="*****@*****.**"; EmailAddress emailaddress=emailaddressparser.ParseRawEmailAddress(String.Format("{0} <{1}>", name1, email1)); Assert.IsNull(emailaddressparser.LastError); Assert.IsNotNull(emailaddress, emailaddressparser.LastError); Assert.AreEqual(name1, emailaddress.Name); Assert.AreEqual(email1, emailaddress.Email); emailaddress=emailaddressparser.ParseRawEmailAddress(email1); Assert.IsNull(emailaddressparser.LastError); Assert.IsNotNull(emailaddress, emailaddressparser.LastError); Assert.AreEqual("", emailaddress.Name); Assert.AreEqual(email1, emailaddress.Email); emailaddress=emailaddressparser.ParseRawEmailAddress(String.Format("\"{0}\" <{1}>", name1, email1)); Assert.IsNotNull(emailaddress, emailaddressparser.LastError); Assert.IsNull(emailaddressparser.LastError, emailaddressparser.LastError); Assert.AreEqual("\""+name1+"\"", emailaddress.Name); Assert.AreEqual(email1, emailaddress.Email); emailaddress=emailaddressparser.ParseRawEmailAddress(String.Format("{0} <{1}>", name1, "test@localhost")); Assert.IsNotNull(emailaddress, emailaddressparser.LastError); Assert.IsNull(emailaddressparser.LastError, emailaddressparser.LastError); Assert.AreEqual(name1, emailaddress.Name); Assert.AreEqual("test@localhost", emailaddress.Email); }
private EmailAddress ParseEmail(String email) { EmailAddressParser emailaddressparser=new EmailAddressParser(); EmailAddress emailaddress=emailaddressparser.ParseRawEmailAddress(email); if (emailaddress==null) { return null; } else { return emailaddress; } }