00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using NUnit.Framework;
00005 using MarekMailSystem2;
00006 using System.Net.Mime;
00007
00008 namespace MarekMailSystem2Tests
00009 {
00013 [TestFixture]
00014 public class NormalTests
00015 {
00016
00017 private Dictionary<string, string> context;
00018 private List<string> receivers;
00019 private List<string> names;
00020 private string template =
00021 "Top secret message to: $SURNAME $NAME\n" +
00022 "$HEADER $NAME !\n" +
00023 "blablabla $NOTUSED blebleble\n" +
00024 "blublu blu\n" +
00025 " $FOOT !\n" +
00026 " Date: $DATE";
00027
00031 [SetUp]
00032 public void Init()
00033 {
00034 context = new Dictionary<string, string>();
00035 context["NAME"] = "Ziomal";
00036 context["SURNAME"] = "Luzny";
00037 context["DATE"] = DateTime.Now.ToString();
00038 context["HEADER"] = "Hello";
00039 context["FOOT"] = "Bye";
00040 context["FROM"] = "dummy667@gmail.com";
00041 context["TO"] = "dummy667@gmail.com";
00042 context["SUBJECT"] = "EmailTemplateTest....";
00043
00044 receivers = new List<string>();
00045 receivers.Add("fgsklgbshgjkb1@hotmail.com");
00046 receivers.Add("fgsklgbshgjkb2@hotmail.com");
00047 receivers.Add("fgsklgbshgjkb3@hotmail.com");
00048 receivers.Add("fgsklgbshgjkb4@hotmail.com");
00049 receivers.Add("fgsklgbshgjkb5@hotmail.com");
00050
00051 names = new List<string>();
00052 names.Add("Mr Dummy 1");
00053 names.Add("Mr Dummy 2");
00054 names.Add("Mr Dummy 3");
00055 names.Add("Mr Dummy 4");
00056 names.Add("Mr Dummy 5");
00057
00058 Assert.AreEqual(receivers.Count, names.Count);
00059 }
00060
00064 [Test]
00065 public void EmailManagerTest1()
00066 {
00067
00068 EmailManager manager = new EmailManager();
00069 EmailStatus result = manager.Send(
00070 "dummy667@gmail.com",
00071 "some subject",
00072 "this email was sent by EmailManagerTest1");
00073 Console.WriteLine(result);
00074 Assert.AreEqual(result.Status, StatusCode.Sent);
00075 }
00076
00077 [Test]
00078 public void EmailManagerTest2()
00079 {
00080 EmailManager manager = new EmailManager();
00081 EmailStatus result = manager.Send(
00082 "dummy668@o2.pl",
00083 "some subject",
00084 "this email was sent by EmailManagerTest2");
00085 Console.WriteLine(result);
00086 Assert.AreEqual(result.Status, StatusCode.Sent);
00087 }
00088
00092 [Test]
00093 public void EmailManagerTemplateTest1()
00094 {
00095 EmailManager manager = new EmailManager(
00096 new DummyEmailTable("ErrorTable"),
00097 new TestTemplateEmailTable(),
00098 new SmtpEmailSender()
00099 );
00100 EmailStatus result = manager.SendSavedTemplate("temp1", context);
00101 Console.WriteLine(result);
00102 Assert.AreEqual(result.Status, StatusCode.Sent);
00103 result = manager.SendSavedTemplate("dummy667@gmail.com", "temp2", context);
00104 Console.WriteLine(result);
00105 Assert.AreEqual(result.Status, StatusCode.Sent);
00106 }
00107
00108
00109 [Test]
00110 public void EmailManagerTemplateTest2()
00111 {
00112 EmailManager manager = new EmailManager();
00113 foreach (string r in receivers)
00114 {
00115 context["TO"] = r;
00116 EmailStatus result = manager.SendSavedTemplate("temp1", context);
00117 Assert.AreEqual(result.Status, StatusCode.Sent);
00118 }
00119
00120 }
00121
00122 [Test]
00123 public void EmailManagerTemplateTest3()
00124 {
00125 EmailManager manager = new EmailManager();
00126 for (int a = 1; a < receivers.Count; a++)
00127 {
00128 context["TO"] = receivers[a];
00129 context["NAME"] = names[a];
00130 EmailStatus result = manager.SendSavedTemplate("temp2", context);
00131 Assert.AreEqual(result.Status, StatusCode.Sent);
00132 }
00133
00134 }
00135
00136 [Test]
00137 public void SmtpEmailSenderTest1()
00138 {
00139 SmtpEmailSender sender = new SmtpEmailSender();
00140
00141 Email email = new Email(
00142 "dummy667@gmail.com",
00143 "some subject",
00144 "this email was sent by SmtpEmailSenderTest1");
00145
00146 sender.Send(email);
00147 Console.WriteLine(email.SendingStatus);
00148 Assert.AreEqual(email.SendingStatus.Status, StatusCode.Sent);
00149 }
00150
00151
00152 [Test]
00153 public void SmtpEmailSenderTest2()
00154 {
00155 SmtpEmailSender sender = new SmtpEmailSender();
00156 sender.Host = "smtp.gmail.com";
00157 sender.Port = 587;
00158 sender.Ssl = true;
00159 sender.UserName = "dummy667@gmail.com";
00160 sender.Password = "pasfort689";
00161
00162 Email email = new Email(
00163 "dummy667@gmail.com",
00164 "dummy668@o2.pl",
00165 "some subject",
00166 "This email was sent by SmtpEmailSenderTest2");
00167
00168 sender.Send(email);
00169 Console.WriteLine(email.SendingStatus);
00170 Assert.AreEqual(email.SendingStatus.Status, StatusCode.Sent);
00171 }
00172
00173
00174
00175 [Test]
00176 public void EmailAltViewTest1()
00177 {
00178 SmtpEmailSender sender = new SmtpEmailSender();
00179
00180
00181 Email email = new Email(
00182 "dummy667@gmail.com",
00183 "some subject",
00184 "<html><body>This html email was sent by EmailTest1</body></html>");
00185 email.IsBodyHtml = true;
00186
00187 sender.Send(email);
00188 Console.WriteLine(email.SendingStatus);
00189 Assert.AreEqual(email.SendingStatus.Status, StatusCode.Sent);
00190
00191
00192 email.AltView = true;
00193
00194 sender.Send(email);
00195 Console.WriteLine(email.SendingStatus);
00196 Assert.AreEqual(email.SendingStatus.Status, StatusCode.Sent);
00197
00198
00199 email.Body = "This plain text email was sent by EmailTest1 (with alternative html version)";
00200 email.IsBodyHtml = false;
00201
00202 sender.Send(email);
00203 Console.WriteLine(email.SendingStatus);
00204 Assert.AreEqual(email.SendingStatus.Status, StatusCode.Sent);
00205 }
00206
00207
00208 [Test]
00209 public void EmailTemplateTest1()
00210 {
00211 Email email = new Email("$FROM", "$TO", "$SUBJECT", template);
00212 email.ProcessTemplate(context);
00213 Console.WriteLine(email);
00214 }
00215
00216
00217 [Test]
00218 public void EmailTemplateTest2()
00219 {
00220 SmtpEmailSender sender = new SmtpEmailSender();
00221
00222 foreach (string r in receivers) {
00223 Email email = new Email("$FROM", r, "$SUBJECT", template);
00224 email.ProcessTemplate(context);
00225 sender.Send(email);
00226 }
00227 }
00228
00232 [Test]
00233 public void StupidTests()
00234 {
00235 Console.WriteLine(MediaTypeNames.Application.Octet);
00236 Console.WriteLine(MediaTypeNames.Application.Pdf);
00237 Console.WriteLine(MediaTypeNames.Application.Rtf);
00238 Console.WriteLine(MediaTypeNames.Application.Soap);
00239 Console.WriteLine(MediaTypeNames.Application.Zip);
00240 Console.WriteLine(MediaTypeNames.Text.Html);
00241 Console.WriteLine(MediaTypeNames.Text.Plain);
00242 Console.WriteLine(MediaTypeNames.Text.RichText);
00243 Console.WriteLine(MediaTypeNames.Text.Xml);
00244 }
00245
00246 }
00247 }