summaryrefslogtreecommitdiffstats
path: root/SendGrid/Tests/Transport/TestWebApi.cs
diff options
context:
space:
mode:
authorRobin J <me@rbin.co>2014-02-17 16:44:40 +0000
committerRobin J <me@rbin.co>2014-02-17 16:44:40 +0000
commit8b6c3c4772814e29c0e5f606383fa7fc41fefea7 (patch)
tree12f95acd718e2f16db5a84cc83869ad17241bc3e /SendGrid/Tests/Transport/TestWebApi.cs
parent849ece5e6b93b0fb965f6d52a78958ef1a014f9a (diff)
parent5fdf5dab9931fcb1aef0383ab67754b0664eb792 (diff)
downloadsendgrid-csharp-8b6c3c4772814e29c0e5f606383fa7fc41fefea7.zip
sendgrid-csharp-8b6c3c4772814e29c0e5f606383fa7fc41fefea7.tar.gz
sendgrid-csharp-8b6c3c4772814e29c0e5f606383fa7fc41fefea7.tar.bz2
Merge pull request #45 from Xerax/master
Cleaned up Unit Tests
Diffstat (limited to 'SendGrid/Tests/Transport/TestWebApi.cs')
-rw-r--r--SendGrid/Tests/Transport/TestWebApi.cs79
1 files changed, 79 insertions, 0 deletions
diff --git a/SendGrid/Tests/Transport/TestWebApi.cs b/SendGrid/Tests/Transport/TestWebApi.cs
new file mode 100644
index 0000000..49e0e94
--- /dev/null
+++ b/SendGrid/Tests/Transport/TestWebApi.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Mail;
+using Moq;
+using NUnit.Framework;
+using SendGridMail;
+
+namespace Tests.Transport
+{
+ [TestFixture]
+ internal class TestWebApi
+ {
+ private const string TestUsername = "username";
+ private const string TestPassword = "password";
+
+ [Test]
+ public void TestFetchFileBodies()
+ {
+ var webApi = Web.GetInstance(new NetworkCredential(TestUsername, TestPassword));
+ var message = new Mock<ISendGrid>();
+ var attachments = new[] {"foo", "bar", "foobar"};
+ message.SetupProperty(foo => foo.Attachments, null);
+ var result = webApi.FetchFileBodies(message.Object);
+ Assert.AreEqual(0, result.Count);
+
+ message.SetupProperty(foo => foo.Attachments, attachments);
+ result = webApi.FetchFileBodies(message.Object);
+ Assert.AreEqual(attachments.Count(), result.Count);
+ for (var index = 0; index < attachments.Length; index++)
+ Assert.AreEqual(result[index].Value.Name, attachments[index]);
+ }
+
+ [Test]
+ public void TestFetchFormParams()
+ {
+ // Test Variables
+ const string toAddress = "foobar@outlook.com";
+ const string ccAddress = "foo@outlook.com";
+ const string bccAddress = "bar@outlook.com";
+ const string fromAddress = "test@outlook.com";
+ const string subject = "Test Subject";
+ const string textBody = "Test Text Body";
+ const string htmlBody = "<p>Test HTML Body</p>";
+ const string headerKey = "headerkey";
+ var testHeader = new Dictionary<string, string> { { headerKey, "headervalue" } };
+ const string categoryName = "Example Category";
+
+ var message = SendGrid.GetInstance();
+ message.AddTo(toAddress);
+ message.AddCc(ccAddress);
+ message.AddBcc(bccAddress);
+ message.From = new MailAddress(fromAddress);
+ message.Subject = subject;
+ message.Text = textBody;
+ message.Html = htmlBody;
+ message.AddHeaders(testHeader);
+ message.Header.SetCategory(categoryName);
+
+ var webApi = Web.GetInstance(new NetworkCredential(TestUsername, TestPassword));
+ var result = webApi.FetchFormParams(message);
+ Assert.True(result.Any(r => r.Key == "api_user" && r.Value == TestUsername));
+ Assert.True(result.Any(r => r.Key == "api_key" && r.Value == TestPassword));
+ Assert.True(result.Any(r => r.Key == "to[]" && r.Value == toAddress));
+ Assert.True(result.Any(r => r.Key == "cc[]" && r.Value == ccAddress));
+ Assert.True(result.Any(r => r.Key == "bcc[]" && r.Value == bccAddress));
+ Assert.True(result.Any(r => r.Key == "from" && r.Value == fromAddress));
+ Assert.True(result.Any(r => r.Key == "subject" && r.Value == subject));
+ Assert.True(result.Any(r => r.Key == "text" && r.Value == textBody));
+ Assert.True(result.Any(r => r.Key == "html" && r.Value == htmlBody));
+ Assert.True(
+ result.Any(
+ r => r.Key == "headers" && r.Value == String.Format("{{\"{0}\":\"{1}\"}}", headerKey, testHeader[headerKey])));
+ Assert.True(
+ result.Any(r => r.Key == "x-smtpapi" && r.Value == String.Format("{{\"category\" : \"{0}\"}}", categoryName)));
+ }
+ }
+} \ No newline at end of file