AttachmentTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // AttachmentTest.cs - NUnit Test Cases for System.Net.MailAddress.Attachment
  3. //
  4. // Authors:
  5. // John Luke ([email protected])
  6. //
  7. // (C) 2005 John Luke
  8. //
  9. using NUnit.Framework;
  10. using System;
  11. using System.IO;
  12. using System.Text;
  13. using System.Net.Mail;
  14. using System.Net.Mime;
  15. namespace MonoTests.System.Net.Mail
  16. {
  17. [TestFixture]
  18. public class AttachmentTest
  19. {
  20. Attachment attach;
  21. [SetUp]
  22. public void GetReady ()
  23. {
  24. attach = Attachment.CreateAttachmentFromString ("test", "attachment-name");
  25. }
  26. [Test]
  27. [ExpectedException (typeof (ArgumentNullException))]
  28. public void ArgumentNullException ()
  29. {
  30. Stream s = null;
  31. new Attachment (s, "application/octet-stream");
  32. }
  33. [Test]
  34. public void ConstructorNullName ()
  35. {
  36. new Attachment (new MemoryStream (), null, "application/octet-stream");
  37. }
  38. [Test]
  39. public void CreateAttachmentFromStringNullName ()
  40. {
  41. Attachment.CreateAttachmentFromString ("", null, Encoding.ASCII, "application/octet-stream");
  42. }
  43. [Test]
  44. public void ContentDisposition ()
  45. {
  46. Assert.IsNotNull (attach.ContentDisposition, "#1");
  47. Assert.AreEqual ("attachment", attach.ContentDisposition.DispositionType, "#2");
  48. }
  49. [Test]
  50. public void ContentType ()
  51. {
  52. Assert.IsNotNull (attach.ContentType, "#1");
  53. Assert.AreEqual ("text/plain", attach.ContentType.MediaType, "#2");
  54. Attachment a2 = new Attachment (new MemoryStream (), "myname");
  55. Assert.IsNotNull (a2.ContentType, "#1");
  56. Assert.AreEqual ("application/octet-stream", a2.ContentType.MediaType, "#2");
  57. }
  58. [Test]
  59. public void NameEncoding ()
  60. {
  61. Assert.IsNull (attach.NameEncoding, "#1");
  62. Attachment a = new Attachment (new MemoryStream (), "myname");
  63. Assert.IsNull (a.NameEncoding, "#2");
  64. a = new Attachment (new MemoryStream (), "myname\u3067");
  65. Assert.IsNull (a.NameEncoding, "#3");
  66. }
  67. [Test]
  68. public void ContentStream ()
  69. {
  70. Assert.IsNotNull (attach.ContentStream);
  71. Assert.IsTrue (attach.ContentStream.Length == 4);
  72. }
  73. [Test]
  74. public void Name ()
  75. {
  76. Assert.AreEqual ("attachment-name", attach.Name, "#1");
  77. Attachment a2 = new Attachment (new MemoryStream (), new ContentType ("image/jpeg"));
  78. Assert.AreEqual (null, a2.Name, "#2");
  79. a2.Name = null; // nullable
  80. }
  81. [Test]
  82. public void TransferEncodingTest ()
  83. {
  84. Assert.AreEqual (TransferEncoding.QuotedPrintable, attach.TransferEncoding);
  85. }
  86. }
  87. }