summaryrefslogtreecommitdiffstats
path: root/SendGrid/Tests/Transport/TestSMTP.cs
diff options
context:
space:
mode:
authorCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-11 16:46:26 -0800
committerCJ Buchmann <cj.buchmann@sendgrid.com>2012-01-11 16:46:26 -0800
commita0d5ea910ca3ff41fc911af47ce77f31cb59938c (patch)
tree2a9262109a6d50de0b875a3423b2a265aa90d870 /SendGrid/Tests/Transport/TestSMTP.cs
parentb4db907a4c69a483b00aba9ef0b624c9e5d58c86 (diff)
parentd77d9340304ad40940b1e77e12f484df351fc47a (diff)
downloadsendgrid-csharp-a0d5ea910ca3ff41fc911af47ce77f31cb59938c.zip
sendgrid-csharp-a0d5ea910ca3ff41fc911af47ce77f31cb59938c.tar.gz
sendgrid-csharp-a0d5ea910ca3ff41fc911af47ce77f31cb59938c.tar.bz2
Merge branch 'us1882' of github.com:sendgrid/sendgrid-csharp into us1882
Conflicts: SendGrid/Example/Program.cs
Diffstat (limited to 'SendGrid/Tests/Transport/TestSMTP.cs')
-rwxr-xr-xSendGrid/Tests/Transport/TestSMTP.cs54
1 files changed, 49 insertions, 5 deletions
diff --git a/SendGrid/Tests/Transport/TestSMTP.cs b/SendGrid/Tests/Transport/TestSMTP.cs
index fcfb050..e0e4fe5 100755
--- a/SendGrid/Tests/Transport/TestSMTP.cs
+++ b/SendGrid/Tests/Transport/TestSMTP.cs
@@ -1,10 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
using System.Net;
-using System.Text;
+using System.Net.Mail;
using Moq;
using NUnit.Framework;
+using SendGridMail;
using SendGridMail.Transport;
namespace Tests.Transport
@@ -13,12 +12,57 @@ namespace Tests.Transport
public class TestSMTP
{
[Test]
- public void Deliver()
+ public void TestDeliver()
{
+ var mockMessage = new Mock<ISendGrid>();
+ var mime = new MailMessage("test-from@sendgrid.com", "test-to@sendgrid.com", "this is a test", "it is only a test");
+ mockMessage.Setup(foo => foo.CreateMimeMessage()).Returns(mime);
+ var message = mockMessage.Object;
+
+ var mockClient = new Mock<SMTP.ISmtpClient>();
+ mockClient.Setup(foo => foo.Send(mime));
+ var client = mockClient.Object;
+ var credentials = new NetworkCredential("username", "password");
+ var test = SMTP.GenerateInstance(client, credentials);
+ test.Deliver(message);
+
+ mockClient.Verify(foo => foo.Send(mime), Times.Once());
+ mockMessage.Verify(foo => foo.CreateMimeMessage(), Times.Once());
+ }
+
+ [Test]
+ public void TestConstructor()
+ {
+ //Test on defaults of port 25 and
var mock = new Mock<SMTP.ISmtpClient>();
+ mock.SetupProperty(foo => foo.EnableSsl);
var client = mock.Object;
var credentials = new NetworkCredential("username", "password");
- SMTP.GenerateInstance(client, credentials);
+ var test = SMTP.GenerateInstance(client, credentials);
+ mock.Verify(foo => foo.EnableSsl, Times.Never());
+
+ mock = new Mock<SMTP.ISmtpClient>();
+ mock.SetupProperty(foo => foo.EnableSsl);
+ client = mock.Object;
+ credentials = new NetworkCredential("username", "password");
+ test = SMTP.GenerateInstance(client, credentials, port:SMTP.SslPort);
+ mock.VerifySet(foo => foo.EnableSsl = true);
+
+ mock = new Mock<SMTP.ISmtpClient>();
+ mock.SetupProperty(foo => foo.EnableSsl);
+ client = mock.Object;
+ credentials = new NetworkCredential("username", "password");
+ try
+ {
+ test = SMTP.GenerateInstance(client, credentials, port: SMTP.TlsPort);
+ Assert.Fail("should have thrown an unsupported port exception");
+ }
+ catch (NotSupportedException ex)
+ {
+ Assert.AreEqual("TLS not supported", ex.Message);
+ }
+
+
}
}
}