public void TestFetchFormParams() { // Test Variables const string toAddress = "*****@*****.**"; const string ccAddress = "*****@*****.**"; const string bccAddress = "*****@*****.**"; const string fromAddress = "*****@*****.**"; 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 = new SendGrid(); 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 = new Web(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))); }
public void TestAddCc() { var foo = new Mock<IHeader>(); var sg = new SendGrid(foo.Object); sg.AddCc("*****@*****.**"); Assert.AreEqual("*****@*****.**", sg.Cc.First().ToString(), "Single CC Address"); sg = new SendGrid(foo.Object); var strings = new String[2]; strings[0] = "*****@*****.**"; strings[1] = "*****@*****.**"; sg.AddCc(strings); Assert.AreEqual("*****@*****.**", sg.Cc[0].ToString(), "Multiple CC addresses, check first one"); Assert.AreEqual("*****@*****.**", sg.Cc[1].ToString(), "Multiple CC addresses, check second one"); sg = new SendGrid(foo.Object); var a = new Dictionary<String, String>(); a.Add("DisplayName", "Eric"); var datastruct = new Dictionary<string, IDictionary<string, string>> { { "*****@*****.**", a } }; sg.AddCc(datastruct); Assert.AreEqual("Eric", sg.Cc.First().DisplayName, "Single CC address with args"); }
public void TestGetRcpts() { var foo = new Mock<IHeader>(); var sg = new SendGrid(foo.Object); sg.AddTo("*****@*****.**"); sg.AddCc("*****@*****.**"); sg.AddBcc("*****@*****.**"); sg.AddBcc("*****@*****.**"); var rcpts = sg.GetRecipients(); Assert.AreEqual("*****@*****.**", rcpts.First(), "getRecipients check To"); Assert.AreEqual("*****@*****.**", rcpts.Skip(1).First(), "getRecipients check Cc"); Assert.AreEqual("*****@*****.**", rcpts.Skip(2).First(), "getRecipients check Bcc"); Assert.AreEqual("*****@*****.**", rcpts.Skip(3).First(), "getRecipients check Bcc x2"); }