Пример #1
0
        public void TestFetchFormParamsHelper(Web webApi, bool credentials)
        {
            // Test Variables
            const string toAddress = "*****@*****.**";
            const string ccAddress = "*****@*****.**";
            const string bcc1Address = "*****@*****.**";
            const string bcc2Address = "*****@*****.**";
            MailAddress[] bccAddresses = {new MailAddress(bcc1Address), new MailAddress(bcc2Address)};
            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 SendGridMessage();
            message.AddTo(toAddress);
            message.AddCc(ccAddress);
            message.Bcc = bccAddresses;
            message.From = new MailAddress(fromAddress);
            message.Subject = subject;
            message.Text = textBody;
            message.Html = htmlBody;
            message.AddHeaders(testHeader);
            message.Header.SetCategory(categoryName);

            var result = webApi.FetchFormParams(message);
            if (credentials)
            {
                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 == bcc1Address));
            Assert.True(result.Any(r => r.Key == "bcc[]" && r.Value == bcc2Address));
            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)));
        }