MailMessageTest.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // MailMessageTest.cs - NUnit Test Cases for System.Net.MailAddress.MailMessage
  3. //
  4. // Authors:
  5. // John Luke ([email protected])
  6. //
  7. // (C) 2005, 2006 John Luke
  8. //
  9. #if NET_2_0
  10. using NUnit.Framework;
  11. using System;
  12. using System.IO;
  13. using System.Text;
  14. using System.Net.Mail;
  15. namespace MonoTests.System.Net.Mail
  16. {
  17. [TestFixture]
  18. public class MailMessageTest
  19. {
  20. MailMessage msg;
  21. MailMessage msg2;
  22. [SetUp]
  23. public void GetReady ()
  24. {
  25. msg = new MailMessage ("[email protected]", "[email protected]");
  26. msg.Subject = "the subject";
  27. msg.Body = "hello";
  28. //msg.AlternateViews.Add (AlternateView.CreateAlternateViewFromString ("<html><body>hello</body></html>", "text/html"));
  29. //Attachment a = Attachment.CreateAttachmentFromString ("blah blah", "text/plain");
  30. //msg.Attachments.Add (a);
  31. msg2 = new MailMessage ("[email protected]", "[email protected], [email protected]");
  32. }
  33. [Test]
  34. public void TestRecipients ()
  35. {
  36. Assert.AreEqual (msg2.To.Count, 2);
  37. Assert.AreEqual (msg2.To[0].Address, "[email protected]");
  38. Assert.AreEqual (msg2.To[1].Address, "[email protected]");
  39. }
  40. [Test]
  41. [ExpectedException (typeof (ArgumentNullException))]
  42. public void ArgumentNullCtor1 ()
  43. {
  44. new MailMessage (null, "[email protected]");
  45. }
  46. [Test]
  47. [ExpectedException (typeof (ArgumentNullException))]
  48. public void ArgumentNullCtor2 ()
  49. {
  50. new MailMessage (null, new MailAddress ("[email protected]"));
  51. }
  52. [Test]
  53. [ExpectedException (typeof (ArgumentNullException))]
  54. public void ArgumentNullCtor3 ()
  55. {
  56. new MailMessage ("[email protected]", null);
  57. }
  58. [Test]
  59. [ExpectedException (typeof (ArgumentNullException))]
  60. public void ArgumentNullCtor4 ()
  61. {
  62. new MailMessage (new MailAddress ("[email protected]"), null);
  63. }
  64. /*[Test]
  65. public void AlternateView ()
  66. {
  67. Assert.AreEqual (msg.AlternateViews.Count, 1);
  68. AlternateView av = msg.AlternateViews[0];
  69. // test that the type is ok, etc.
  70. }*/
  71. /*[Test]
  72. public void Attachment ()
  73. {
  74. Assert.AreEqual (msg.Attachments.Count, 1);
  75. Attachment at = msg.Attachments[0];
  76. Assert.AreEqual (at.ContentType.MediaType, "text/plain");
  77. }*/
  78. [Test]
  79. public void Body ()
  80. {
  81. Assert.AreEqual (msg.Body, "hello");
  82. }
  83. [Test]
  84. public void BodyEncoding ()
  85. {
  86. Assert.AreEqual (msg.BodyEncoding, Encoding.ASCII);
  87. }
  88. [Test]
  89. public void From ()
  90. {
  91. Assert.AreEqual (msg.From.Address, "[email protected]");
  92. }
  93. [Test]
  94. public void IsBodyHtml ()
  95. {
  96. Assert.IsFalse (msg.IsBodyHtml);
  97. }
  98. [Test]
  99. public void Priority ()
  100. {
  101. Assert.AreEqual (msg.Priority, MailPriority.Normal);
  102. }
  103. [Test]
  104. public void Subject ()
  105. {
  106. Assert.AreEqual (msg.Subject, "the subject");
  107. }
  108. [Test]
  109. public void To ()
  110. {
  111. Assert.AreEqual (msg.To.Count, 1);
  112. Assert.AreEqual (msg.To[0].Address, "[email protected]");
  113. }
  114. }
  115. }
  116. #endif