Author: jluke
Date: 2006-01-13 15:55:56 -0500 (Fri, 13 Jan 2006)
New Revision: 55549

Added:
   trunk/mcs/class/System/Test/System.Net.Mail/SmtpClientTest.cs
Modified:
   trunk/mcs/class/System/ChangeLog
   trunk/mcs/class/System/System.Net.Mail/ChangeLog
   trunk/mcs/class/System/System.Net.Mail/MailMessage.cs
   trunk/mcs/class/System/System.Net.Mail/SmtpClient.cs
   trunk/mcs/class/System/System_test.dll.sources
   trunk/mcs/class/System/Test/ChangeLog
   trunk/mcs/class/System/Test/System.Net.Mail/MailMessageTest.cs
Log:
2006-1-13  John Luke  <[EMAIL PROTECTED]>

        * MailMessage.cs: add [MonoTODO] for FormatException in ctor,
        throw ArugmentNullException's from the ctors,
        add internal BodyContentType property,
        change BodyEncoding to use BodyContentType,
        change IsBodyHtml to use BodyContentType,
        * SmtpClient.cs: set timeout initially to 100000,
        don't throw ArgumentOutOfRangeException when Timeout = 0,
        add [MonoTODO] for set_host, and throw Exceptions for it,
        add [MonoTODO] for UseDefaultCredentials,
        get messageContentType from the message,
        use "127.0.0.1" for Host and 25 for Port
        if host or port is not specified until reading
        them from the configuration files is done



Modified: trunk/mcs/class/System/ChangeLog
===================================================================
--- trunk/mcs/class/System/ChangeLog    2006-01-13 20:41:38 UTC (rev 55548)
+++ trunk/mcs/class/System/ChangeLog    2006-01-13 20:55:56 UTC (rev 55549)
@@ -1,3 +1,7 @@
+2005-01-13  John Luke  <[EMAIL PROTECTED]>
+
+       * System_test.dll.sources: add System.Net.Mail.SmtpClient tests
+       
 2006-01-09  Chris Toshok  <[EMAIL PROTECTED]>
 
        * Makefile (LIB_MCS_FLAGS): if we're building net_2_0, define

Modified: trunk/mcs/class/System/System.Net.Mail/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.Net.Mail/ChangeLog    2006-01-13 20:41:38 UTC 
(rev 55548)
+++ trunk/mcs/class/System/System.Net.Mail/ChangeLog    2006-01-13 20:55:56 UTC 
(rev 55549)
@@ -1,3 +1,19 @@
+2006-1-13  John Luke  <[EMAIL PROTECTED]>
+
+       * MailMessage.cs: add [MonoTODO] for FormatException in ctor,
+       throw ArugmentNullException's from the ctors,
+       add internal BodyContentType property,
+       change BodyEncoding to use BodyContentType,
+       change IsBodyHtml to use BodyContentType,
+       * SmtpClient.cs: set timeout initially to 100000,
+       don't throw ArgumentOutOfRangeException when Timeout = 0,
+       add [MonoTODO] for set_host, and throw Exceptions for it,
+       add [MonoTODO] for UseDefaultCredentials,
+       get messageContentType from the message,
+       use "127.0.0.1" for Host and 25 for Port
+       if host or port is not specified until reading
+       them from the configuration files is done
+
 2006-1-02  John Luke  <[EMAIL PROTECTED]>
 
        * DeliveryNotificationOptions: fix value of Delay

Modified: trunk/mcs/class/System/System.Net.Mail/MailMessage.cs
===================================================================
--- trunk/mcs/class/System/System.Net.Mail/MailMessage.cs       2006-01-13 
20:41:38 UTC (rev 55548)
+++ trunk/mcs/class/System/System.Net.Mail/MailMessage.cs       2006-01-13 
20:55:56 UTC (rev 55549)
@@ -31,6 +31,7 @@
 #if NET_2_0
 
 using System.Collections.Specialized;
+using System.Globalization;
 using System.Net.Mime;
 using System.Text;
 
@@ -44,17 +45,16 @@
                AttachmentCollection attachments;
                MailAddressCollection bcc;
                string body;
-               bool isBodyHtml;
                MailPriority priority;
                MailAddress replyTo, sender;
                DeliveryNotificationOptions deliveryNotificationOptions;
-               Encoding bodyEncoding;
                MailAddressCollection cc;
                MailAddress from;
                NameValueCollection headers;
                MailAddressCollection to;
                string subject;
                Encoding subjectEncoding;
+               ContentType bodyContentType;
 
                #endregion // Fields
 
@@ -64,8 +64,12 @@
                {
                }
 
+               [MonoTODO ("FormatException")]
                public MailMessage (MailAddress from, MailAddress to)
                {
+                       if (from == null || to == null)
+                               throw new ArgumentNullException ();
+                       
                        From = from;
 
                        this.to = new MailAddressCollection ();
@@ -83,11 +87,15 @@
                public MailMessage (string from, string to)
                        : this (new MailAddress (from), new MailAddress (to))
                {
+                       if (from == null || to == null)
+                               throw new ArgumentNullException ();
                }
 
                public MailMessage (string from, string to, string subject, 
string body)
                        : this (new MailAddress (from), new MailAddress (to))
                {
+                       if (from == null || to == null)
+                               throw new ArgumentNullException ();
                        Body = body;
                        Subject = subject;
                }
@@ -113,14 +121,19 @@
                        set { body = value; }
                }
 
-               public Encoding BodyEncoding {
-                       get { return bodyEncoding; }
-                       set { 
-                               bodyEncoding = value;
-                               //bodyContentType.CharSet = value.WebName; 
+               internal ContentType BodyContentType {
+                       get {
+                               if (bodyContentType == null)
+                                       bodyContentType = new ContentType 
("text/plain; charset=us-ascii");
+                               return bodyContentType;
                        }
                }
 
+               public Encoding BodyEncoding {
+                       get { return Encoding.GetEncoding 
(BodyContentType.CharSet); }
+                       set { BodyContentType.CharSet = value.WebName; }
+               }
+
                public MailAddressCollection CC {
                        get { return cc; }
                }
@@ -140,8 +153,13 @@
                }
 
                public bool IsBodyHtml {
-                       get { return isBodyHtml; }
-                       set { isBodyHtml = value; }
+                       get { return String.Compare (BodyContentType.MediaType, 
"text/html", true, CultureInfo.InvariantCulture) == 0; }
+                       set {
+                               if (value)
+                                       BodyContentType.MediaType = "text/html";
+                               else
+                                       BodyContentType.MediaType = 
"text/plain";
+                       }
                }
 
                public MailPriority Priority {

Modified: trunk/mcs/class/System/System.Net.Mail/SmtpClient.cs
===================================================================
--- trunk/mcs/class/System/System.Net.Mail/SmtpClient.cs        2006-01-13 
20:41:38 UTC (rev 55548)
+++ trunk/mcs/class/System/System.Net.Mail/SmtpClient.cs        2006-01-13 
20:55:56 UTC (rev 55549)
@@ -48,7 +48,7 @@
 
                string host;
                int port;
-               int timeout;
+               int timeout = 100000;
                ICredentialsByHost credentials;
                bool useDefaultCredentials;
                string pickupDirectoryLocation;
@@ -83,8 +83,19 @@
                [MonoTODO ("Load default settings from configuration.")]
                public SmtpClient (string host, int port)
                {
-                       Host = host;
-                       Port = port;
+                       // FIXME: load from configuration
+                       if (String.IsNullOrEmpty (host))
+                               Host = "127.0.0.1";
+                       else
+                               Host = host;
+                       
+                       // FIXME: load from configuration
+                       if (port == 0)
+                               Port = 25;
+                       else
+                               Port = port;
+
+                       // FIXME: load credentials from configuration
                }
 
                #endregion // Constructors
@@ -113,7 +124,14 @@
 
                public string Host {
                        get { return host; }
-                       set { host = value; }
+                       [MonoTODO ("Check to make sure an email is not being 
sent.")]
+                       set {
+                               if (value == null)
+                                       throw new ArgumentNullException ();
+                               if (value.Length == 0)
+                                       throw new ArgumentException ();
+                               host = value;
+                       }
                }
 
                public string PickupDirectoryLocation {
@@ -140,12 +158,13 @@
                        get { return timeout; }
                        [MonoTODO ("Check to make sure an email is not being 
sent.")]
                        set { 
-                               if (value <= 0)
+                               if (value < 0)
                                        throw new ArgumentOutOfRangeException 
();
                                timeout = value; 
                        }
                }
 
+               [MonoTODO]
                public bool UseDefaultCredentials {
                        get { return useDefaultCredentials; }
                        set { useDefaultCredentials = value; }
@@ -263,9 +282,8 @@
                                throw new SmtpException (status.StatusCode);
 
                        // Figure out the message content type
-                       ContentType messageContentType = new ContentType 
("text/plain");
+                       ContentType messageContentType = 
message.BodyContentType;
                        if (hasAttachments || hasAlternateViews) {
-                               //messageContentType = new ContentType ();
                                messageContentType.Boundary = boundary;
 
                                if (hasAttachments)

Modified: trunk/mcs/class/System/System_test.dll.sources
===================================================================
--- trunk/mcs/class/System/System_test.dll.sources      2006-01-13 20:41:38 UTC 
(rev 55548)
+++ trunk/mcs/class/System/System_test.dll.sources      2006-01-13 20:55:56 UTC 
(rev 55549)
@@ -170,6 +170,7 @@
 System.Net.Mail/AttachmentTest.cs
 System.Net.Mail/AlternateViewTest.cs
 System.Net.Mail/LinkedResourceCollectionTest.cs
+System.Net.Mail/SmtpClientTest.cs
 System.Net.Mime/ContentDispositionTest.cs
 System.Net.Mime/ContentTypeTest.cs
 System.Security.Cryptography/AsnEncodedDataTest.cs

Modified: trunk/mcs/class/System/Test/ChangeLog
===================================================================
--- trunk/mcs/class/System/Test/ChangeLog       2006-01-13 20:41:38 UTC (rev 
55548)
+++ trunk/mcs/class/System/Test/ChangeLog       2006-01-13 20:55:56 UTC (rev 
55549)
@@ -1,3 +1,7 @@
+2006-01-13  John Luke  <[EMAIL PROTECTED]>
+
+       * System.Net.Mail/*Test.cs: update tests
+
 2006-01-06  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * System.Net.Mime/ContentDispositionTest.cs: Use Assert.AreEqual

Modified: trunk/mcs/class/System/Test/System.Net.Mail/MailMessageTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Net.Mail/MailMessageTest.cs      
2006-01-13 20:41:38 UTC (rev 55548)
+++ trunk/mcs/class/System/Test/System.Net.Mail/MailMessageTest.cs      
2006-01-13 20:55:56 UTC (rev 55549)
@@ -4,7 +4,7 @@
 // Authors:
 //   John Luke ([EMAIL PROTECTED])
 //
-// (C) 2005 John Luke
+// (C) 2005, 2006 John Luke
 //
 #if NET_2_0
 using NUnit.Framework;
@@ -30,11 +30,39 @@
                        //Attachment a = Attachment.CreateAttachmentFromString 
("blah blah", "text/plain");
                        //msg.Attachments.Add (a);
                }
+               
+               [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.IsTrue (msg.AlternateViews.Count == 1);
+                       Assert.AreEqual (msg.AlternateViews.Count, 1);
                        AlternateView av = msg.AlternateViews[0];
                        // test that the type is ok, etc.
                }*/
@@ -42,21 +70,27 @@
                /*[Test]
                public void Attachment ()
                {
-                       Assert.IsTrue (msg.Attachments.Count == 1);
+                       Assert.AreEqual (msg.Attachments.Count, 1);
                        Attachment at = msg.Attachments[0];
-                       Assert.IsTrue (at.ContentType.MediaType == 
"text/plain");
+                       Assert.AreEqual (at.ContentType.MediaType, 
"text/plain");
                }*/
 
                [Test]
                public void Body ()
                {
-                       Assert.IsTrue (msg.Body == "hello");
+                       Assert.AreEqual (msg.Body, "hello");
                }
+               
+               [Test]
+               public void BodyEncoding ()
+               {
+                       Assert.AreEqual (msg.BodyEncoding, Encoding.ASCII);
+               }
 
                [Test]
                public void From ()
                {
-                       Assert.IsTrue (msg.From.Address == "[EMAIL PROTECTED]");
+                       Assert.AreEqual (msg.From.Address, "[EMAIL PROTECTED]");
                }
 
                [Test]
@@ -68,20 +102,20 @@
                [Test]
                public void Priority ()
                {
-                       Assert.IsTrue (msg.Priority == MailPriority.Normal);
+                       Assert.AreEqual (msg.Priority, MailPriority.Normal);
                }
 
                [Test]
                public void Subject ()
                {
-                       Assert.IsTrue (msg.Subject == "the subject");
+                       Assert.AreEqual (msg.Subject, "the subject");
                }
 
                [Test]
                public void To ()
                {
-                       Assert.IsTrue (msg.To.Count == 1);
-                       Assert.IsTrue (msg.To[0].Address == "[EMAIL 
PROTECTED]");
+                       Assert.AreEqual (msg.To.Count, 1);
+                       Assert.AreEqual (msg.To[0].Address, "[EMAIL 
PROTECTED]");
                }
        }
 }

Added: trunk/mcs/class/System/Test/System.Net.Mail/SmtpClientTest.cs
===================================================================
--- trunk/mcs/class/System/Test/System.Net.Mail/SmtpClientTest.cs       
2006-01-13 20:41:38 UTC (rev 55548)
+++ trunk/mcs/class/System/Test/System.Net.Mail/SmtpClientTest.cs       
2006-01-13 20:55:56 UTC (rev 55549)
@@ -0,0 +1,64 @@
+//
+// SmtpClientTest.cs - NUnit Test Cases for System.Net.Mail.SmtpClient
+//
+// Authors:
+//   John Luke ([EMAIL PROTECTED])
+//
+// (C) 2006 John Luke
+//
+#if NET_2_0
+using NUnit.Framework;
+using System;
+using System.IO;
+using System.Net.Mail;
+using System.Net.Mime;
+
+namespace MonoTests.System.Net.Mail
+{
+       [TestFixture]
+       public class SmtpClientTest
+       {
+               SmtpClient smtp;
+               
+               [SetUp]
+               public void GetReady ()
+               {
+                       smtp = new SmtpClient ();
+               }
+
+               [Test]
+               public void InitialTimeout ()
+               {
+                       Assert.AreEqual (smtp.Timeout, 100000);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void NegativePortValue ()
+               {
+                       smtp.Port = -1;
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void NegativeTimeoutValue ()
+               {
+                       smtp.Timeout = -1;
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void NullHost ()
+               {
+                       smtp.Host = null;
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void EmptyHost ()
+               {
+                       smtp.Host = String.Empty;
+               }
+       }
+}
+#endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to