aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.UnitTesting')
-rw-r--r--Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs
index 785fa42bf..9465676ef 100644
--- a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs
+++ b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs
@@ -3,10 +3,14 @@ using SendGrid;
using SendGrid.Helpers.Mail;
using System;
using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
using System.IO;
using System.Linq;
+using System.Net;
using System.Text;
using System.Threading.Tasks;
+using Tango.PMR.TCC;
namespace Tango.UnitTesting.SendGrid
{
@@ -35,5 +39,59 @@ namespace Tango.UnitTesting.SendGrid
Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Accepted);
}
+
+ [TestMethod]
+ public void Send_Template_Email()
+ {
+ var client = new SendGridClient(KEY);
+ SendGridMessage msg = new SendGridMessage();
+ msg.SetFrom("test@example.com");
+ msg.AddTo("roy.mail.net@gmail.com");
+ msg.Subject = "SnapMatch Color Result";
+ msg.SetTemplateId("d-619b8adc604d4f6fa486d7bbc9e3c2cc");
+
+ Bitmap rect = new Bitmap(80, 80);
+ using (Graphics g = Graphics.FromImage(rect))
+ {
+ g.Clear(Color.FromArgb(255, 0, 0));
+ }
+
+ String image64 = String.Empty;
+
+ using (MemoryStream ms = new MemoryStream())
+ {
+ rect.Save(ms, ImageFormat.Jpeg);
+ ms.Position = 0;
+ image64 = Convert.ToBase64String(ms.ToArray());
+ }
+
+ var dynamicTemplateData = new ExampleTemplateData
+ {
+ Name = "Roy",
+ Message = "This is my personal note...",
+ ImageSource = image64,
+ };
+
+ msg.SetTemplateData(dynamicTemplateData);
+
+
+ DetectionColorFile file = new DetectionColorFile();
+ file.RawColor = new DetectionColor() { R = 10, G = 20, B = 30 };
+ file.ProcessedColor = new DetectionColor() { R = 11, G = 21, B = 31 };
+
+ var base64 = Convert.ToBase64String(file.ToBytes());
+ msg.AddAttachment("SnapMatch Color.tcc", base64, "application/octet-stream");
+
+ var result = client.SendEmailAsync(msg).GetAwaiter().GetResult();
+
+ Assert.IsTrue(result.StatusCode == HttpStatusCode.Accepted);
+ }
+
+ public class ExampleTemplateData
+ {
+ public String Name { get; set; }
+ public String ImageSource { get; set; }
+ public String Message { get; set; }
+ }
}
}