summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xSendGrid/SendGridMail/Transport/REST.cs6
-rwxr-xr-xSendGrid/SendGridMail/Utils.cs20
-rwxr-xr-xSendGrid/Tests/TestSendgrid.cs33
-rwxr-xr-xSendGrid/Tests/TestUtils.cs24
-rwxr-xr-xSendGrid/Tests/Transport/TestREST.cs28
5 files changed, 76 insertions, 35 deletions
diff --git a/SendGrid/SendGridMail/Transport/REST.cs b/SendGrid/SendGridMail/Transport/REST.cs
index 0370b42..614e024 100755
--- a/SendGrid/SendGridMail/Transport/REST.cs
+++ b/SendGrid/SendGridMail/Transport/REST.cs
@@ -66,7 +66,7 @@ namespace SendGridMail.Transport
#region Support Methods
- private HttpClient InitializeTransport(out MultipartEntity multipartEntity, out HttpPost postMethod)
+ internal HttpClient InitializeTransport(out MultipartEntity multipartEntity, out HttpPost postMethod)
{
var client = new HttpClient();
postMethod = new HttpPost(new Uri(_restEndpoint));
@@ -115,7 +115,7 @@ namespace SendGridMail.Transport
}
}
- private List<KeyValuePair<String, String>> FetchFormParams(ISendGrid message)
+ internal List<KeyValuePair<String, String>> FetchFormParams(ISendGrid message)
{
var result = new List<KeyValuePair<string, string>>()
{
@@ -149,7 +149,7 @@ namespace SendGridMail.Transport
return result.Where(r => !String.IsNullOrEmpty(r.Value)).ToList();
}
- private List<KeyValuePair<String, FileInfo>> FetchFileBodies(ISendGrid message)
+ internal List<KeyValuePair<String, FileInfo>> FetchFileBodies(ISendGrid message)
{
if(message.Attachments == null)
return new List<KeyValuePair<string, FileInfo>>();
diff --git a/SendGrid/SendGridMail/Utils.cs b/SendGrid/SendGridMail/Utils.cs
index cb6413c..31fe92f 100755
--- a/SendGrid/SendGridMail/Utils.cs
+++ b/SendGrid/SendGridMail/Utils.cs
@@ -28,25 +28,5 @@ namespace SendGridMail
return "{"+String.Join(",",dic.Select(kvp => Serialize(kvp.Key) + ":" + Serialize(kvp.Value)))+"}";
}
- public static Dictionary<String, Stream> PrepareAttachments()
- {
- var attach = new Attachment("D:/att_proj/21.jpg");
- Console.WriteLine("preparing message attachment");
- var sr = new StreamReader(attach.ContentStream);
-
- Console.WriteLine(sr.ReadToEnd());
-
- Console.WriteLine(":D");
- var request = (HttpWebRequest)WebRequest.Create("");
-
-
- //attach.ContentStream.CopyTo(request.GetRequestStream());
-
- Console.WriteLine("attachment: ");
-
- Console.WriteLine("DONE");
-
- return new Dictionary<string, Stream>();
- }
}
}
diff --git a/SendGrid/Tests/TestSendgrid.cs b/SendGrid/Tests/TestSendgrid.cs
index 3631dc1..95604d3 100755
--- a/SendGrid/Tests/TestSendgrid.cs
+++ b/SendGrid/Tests/TestSendgrid.cs
@@ -191,16 +191,34 @@ namespace Tests
var text = "<% %>";
var html = "<% name %>";
- var replace = "John";
- sendgrid.EnableUnsubscribe(text, html);
- var jsonText = "\"text\\/plain\" : \""+text+"\"";
- var jsonHtml = "\"text\\/html\" : \""+html+"\"";
- var jsonReplace = "\"replace\" : \""+replace+"\"";
+ var jsonText = "\"text\\/plain\" : \"" + text + "\"";
+ var jsonHtml = "\"text\\/html\" : \"" + html + "\"";
+
+ sendgrid.EnableUnsubscribe(text, html);
String json = header.AsJson();
Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\","+
- jsonText+","+jsonHtml+","+jsonReplace+","+"}}}}", json);
+ jsonText+","+jsonHtml+"}}}}", json);
+
+ header = new Header();
+ sendgrid = new SendGrid(header);
+
+ var replace = "John";
+ var jsonReplace = "\"replace\" : \"" + replace + "\"";
+
+ sendgrid.EnableUnsubscribe(replace);
+
+ json = header.AsJson();
+ Assert.AreEqual("{\"filters\" : {\"subscriptiontrack\" : {\"settings\" : {\"enable\" : \"1\"," + jsonReplace + "}}}}", json);
+
+ text = "bad";
+ html = "<% name %>";
+ Assert.Throws<Exception>(delegate { sendgrid.EnableUnsubscribe(text, html); });
+
+ text = "<% %>";
+ html = "bad";
+ Assert.Throws<Exception>(delegate { sendgrid.EnableUnsubscribe(text, html); });
}
@@ -257,6 +275,9 @@ namespace Tests
String json = header.AsJson();
Assert.AreEqual("{\"filters\" : {\"template\" : {\"settings\" : {\"enable\" : \"1\",\"text\\/html\" : \""+escHtml+"\"}}}}", json);
+
+ escHtml = "bad";
+ Assert.Throws<Exception>(delegate { sendgrid.EnableTemplate(escHtml); });
}
[Test]
diff --git a/SendGrid/Tests/TestUtils.cs b/SendGrid/Tests/TestUtils.cs
index dda9d19..48febcf 100755
--- a/SendGrid/Tests/TestUtils.cs
+++ b/SendGrid/Tests/TestUtils.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
+using SendGridMail;
namespace Tests
{
@@ -10,9 +11,28 @@ namespace Tests
public class TestUtils
{
[Test]
- public void Test()
+ public void TestSerialize()
{
-
+ var testcase = "foo";
+ String result = Utils.Serialize(testcase);
+ Assert.AreEqual("\"foo\"", result);
+
+ var testcase2 = 1;
+ result = Utils.Serialize(testcase2);
+ Assert.AreEqual("1", result);
+ }
+
+ [Test]
+ public void TestSerializeDictionary()
+ {
+ var test = new Dictionary<string, string>
+ {
+ {"a", "b"},
+ {"c", "d/e"}
+ };
+ var result = Utils.SerializeDictionary(test);
+ var expected = "{\"a\":\"b\",\"c\":\"d\\/e\"}";
+ Assert.AreEqual(expected, result);
}
}
}
diff --git a/SendGrid/Tests/Transport/TestREST.cs b/SendGrid/Tests/Transport/TestREST.cs
index ccbab48..15c31ed 100755
--- a/SendGrid/Tests/Transport/TestREST.cs
+++ b/SendGrid/Tests/Transport/TestREST.cs
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Text;
+using Moq;
using NUnit.Framework;
+using SendGridMail;
+using SendGridMail.Transport;
namespace Tests.Transport
{
@@ -10,15 +14,31 @@ namespace Tests.Transport
class TestREST
{
[Test]
- public void TestDeliver()
+ public void TestFetchFileBodies()
{
-
+ var test = REST.GetInstance(new NetworkCredential("foo", "bar"));
+ var message = new Mock<ISendGrid>();
+ message.SetupProperty(foo => foo.Attachments, null);
+ var result = test.FetchFileBodies(message.Object);
+ Assert.AreEqual(0, result.Count);
+
+ message.SetupProperty(foo => foo.Attachments, new string[] {"foo", "bar", "raz"});
+ result = test.FetchFileBodies(message.Object);
+ Assert.AreEqual(3, result.Count);
+ }
+
+ [Test]
+ public void TestFetchFormParams()
+ {
+ var bar = REST.GetInstance(new NetworkCredential("foo", "bar"));
+ //bar.FetchFormParams();
}
[Test]
- public void TestConstructor()
+ public void TestInitializeTransport()
{
-
+ var bar = REST.GetInstance(new NetworkCredential("foo", "bar"));
+ //bar.InitializeTransport();
}
}
}