mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-17 11:21:39 -10:00
* ContentType.cs : for SubjectEncoding, null is returned instead of ASCII (.net compat way). For this cosmetic change, BodyEncoding is changed to fill ASCII automatically. * MailMessage.cs : fixing cosmetic .net compatibility. Automatically fill ASCII when guessed encoding is nothing. * MailMessageTest.cs : fixed test to just compare codepage. I can't stand with this trivial difference (w/ BOM or not) as regression, and fixing this "regression" causes practical bug (garbage BOM insertion). svn path=/trunk/mcs/; revision=90771
169 lines
4.0 KiB
C#
169 lines
4.0 KiB
C#
//
|
|
// MailMessageTest.cs - NUnit Test Cases for System.Net.MailAddress.MailMessage
|
|
//
|
|
// Authors:
|
|
// John Luke ([email protected])
|
|
//
|
|
// (C) 2005, 2006 John Luke
|
|
//
|
|
#if NET_2_0
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Net.Mail;
|
|
|
|
namespace MonoTests.System.Net.Mail
|
|
{
|
|
[TestFixture]
|
|
public class MailMessageTest
|
|
{
|
|
MailMessage msg;
|
|
MailMessage msg2;
|
|
|
|
[SetUp]
|
|
public void GetReady ()
|
|
{
|
|
msg = new MailMessage ("[email protected]", "[email protected]");
|
|
msg.Subject = "the subject";
|
|
msg.Body = "hello";
|
|
//msg.AlternateViews.Add (AlternateView.CreateAlternateViewFromString ("<html><body>hello</body></html>", "text/html"));
|
|
//Attachment a = Attachment.CreateAttachmentFromString ("blah blah", "text/plain");
|
|
//msg.Attachments.Add (a);
|
|
|
|
msg2 = new MailMessage ("[email protected]", "[email protected], [email protected]");
|
|
}
|
|
|
|
[Test]
|
|
public void TestRecipients ()
|
|
{
|
|
Assert.AreEqual (msg2.To.Count, 2);
|
|
Assert.AreEqual (msg2.To[0].Address, "[email protected]");
|
|
Assert.AreEqual (msg2.To[1].Address, "[email protected]");
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
public void ArgumentNullCtor1 ()
|
|
{
|
|
new MailMessage (null, "[email protected]");
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
public void ArgumentNullCtor2 ()
|
|
{
|
|
new MailMessage (null, new MailAddress ("[email protected]"));
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
public void ArgumentNullCtor3 ()
|
|
{
|
|
new MailMessage ("[email protected]", null);
|
|
}
|
|
|
|
[Test]
|
|
[ExpectedException (typeof (ArgumentNullException))]
|
|
public void ArgumentNullCtor4 ()
|
|
{
|
|
new MailMessage (new MailAddress ("[email protected]"), null);
|
|
}
|
|
|
|
/*[Test]
|
|
public void AlternateView ()
|
|
{
|
|
Assert.AreEqual (msg.AlternateViews.Count, 1);
|
|
AlternateView av = msg.AlternateViews[0];
|
|
// test that the type is ok, etc.
|
|
}*/
|
|
|
|
/*[Test]
|
|
public void Attachment ()
|
|
{
|
|
Assert.AreEqual (msg.Attachments.Count, 1);
|
|
Attachment at = msg.Attachments[0];
|
|
Assert.AreEqual (at.ContentType.MediaType, "text/plain");
|
|
}*/
|
|
|
|
[Test]
|
|
public void Body ()
|
|
{
|
|
Assert.AreEqual (msg.Body, "hello");
|
|
}
|
|
|
|
[Test]
|
|
public void BodyEncoding ()
|
|
{
|
|
Assert.AreEqual (msg.BodyEncoding, Encoding.ASCII);
|
|
}
|
|
|
|
[Test]
|
|
public void From ()
|
|
{
|
|
Assert.AreEqual (msg.From.Address, "[email protected]");
|
|
}
|
|
|
|
[Test]
|
|
public void IsBodyHtml ()
|
|
{
|
|
Assert.IsFalse (msg.IsBodyHtml);
|
|
}
|
|
|
|
[Test]
|
|
public void Priority ()
|
|
{
|
|
Assert.AreEqual (msg.Priority, MailPriority.Normal);
|
|
}
|
|
|
|
[Test]
|
|
public void Subject ()
|
|
{
|
|
Assert.AreEqual (msg.Subject, "the subject");
|
|
}
|
|
|
|
[Test]
|
|
public void To ()
|
|
{
|
|
Assert.AreEqual (msg.To.Count, 1, "#A1");
|
|
Assert.AreEqual (msg.To[0].Address, "[email protected]", "#A2");
|
|
|
|
msg = new MailMessage ();
|
|
msg.To.Add ("[email protected]");
|
|
msg.To.Add ("[email protected]");
|
|
Assert.AreEqual (msg.To.Count, 2, "#B1");
|
|
Assert.AreEqual (msg.To[0].Address, "[email protected]", "#B2");
|
|
Assert.AreEqual (msg.To[1].Address, "[email protected]", "#B3");
|
|
}
|
|
|
|
[Test]
|
|
public void BodyAndEncoding ()
|
|
{
|
|
MailMessage msg = new MailMessage ("[email protected]", "[email protected]");
|
|
Assert.AreEqual (null, msg.BodyEncoding, "#1");
|
|
msg.Body = "test";
|
|
Assert.AreEqual (Encoding.ASCII, msg.BodyEncoding, "#2");
|
|
msg.Body = "test\u3067\u3059";
|
|
Assert.AreEqual (Encoding.ASCII, msg.BodyEncoding, "#3");
|
|
msg.BodyEncoding = null;
|
|
msg.Body = "test\u3067\u3059";
|
|
Assert.AreEqual (Encoding.UTF8.CodePage, msg.BodyEncoding.CodePage, "#4");
|
|
}
|
|
|
|
[Test]
|
|
public void SubjectAndEncoding ()
|
|
{
|
|
MailMessage msg = new MailMessage ("[email protected]", "[email protected]");
|
|
Assert.AreEqual (null, msg.SubjectEncoding, "#1");
|
|
msg.Subject = "test";
|
|
Assert.AreEqual (null, msg.SubjectEncoding, "#2");
|
|
msg.Subject = "test\u3067\u3059";
|
|
Assert.AreEqual (Encoding.UTF8.CodePage, msg.SubjectEncoding.CodePage, "#3");
|
|
msg.SubjectEncoding = null;
|
|
msg.Subject = "test\u3067\u3059";
|
|
Assert.AreEqual (Encoding.UTF8.CodePage, msg.SubjectEncoding.CodePage, "#4");
|
|
}
|
|
}
|
|
}
|
|
#endif
|