public void IsToValid()
        {
            // Null Personalization
            SendGridMessage mail = new SendGridMessage();

            mail.Personalizations = null;
            Assert.False(SendGridHelpers.IsToValid(mail));

            // Empty Personalization
            mail.Personalizations = new List <Personalization>();
            Assert.False(SendGridHelpers.IsToValid(mail));

            // 'To' with no address
            Personalization personalization = new Personalization();

            personalization.Tos = new List <EmailAddress>
            {
                new EmailAddress()
            };
            mail.Personalizations.Add(personalization);
            Assert.False(SendGridHelpers.IsToValid(mail));

            // Personalization with no 'To'
            mail = new SendGridMessage();
            mail.Personalizations = new List <Personalization>();

            Personalization personalization1 = new Personalization();

            personalization1.Tos = new List <EmailAddress>
            {
                new EmailAddress("*****@*****.**")
            };
            mail.Personalizations.Add(personalization1);

            Personalization personalization2 = new Personalization();

            personalization2.Bccs = new List <EmailAddress>
            {
                new EmailAddress("*****@*****.**")
            };
            mail.Personalizations.Add(personalization2);

            Assert.False(SendGridHelpers.IsToValid(mail));

            // valid
            personalization2.Tos = new List <EmailAddress>
            {
                new EmailAddress("*****@*****.**")
            };
            Assert.True(SendGridHelpers.IsToValid(mail));
        }
Ejemplo n.º 2
0
        public void IsToValid()
        {
            // Null Personalization
            Mail mail = new Mail();

            mail.Personalization = null;
            Assert.False(SendGridHelpers.IsToValid(mail));

            // Empty Personalization
            mail.Personalization = new List <Personalization>();
            Assert.False(SendGridHelpers.IsToValid(mail));

            // 'To' with no address
            Personalization personalization = new Personalization();

            personalization.AddTo(new Email());
            mail.AddPersonalization(personalization);
            Assert.False(SendGridHelpers.IsToValid(mail));

            // Personalization with no 'To'
            mail = new Mail();

            Personalization personalization1 = new Personalization();

            personalization1.AddTo(new Email("*****@*****.**"));

            Personalization personalization2 = new Personalization();

            personalization2.AddBcc(new Email("*****@*****.**"));

            mail.AddPersonalization(personalization1);
            mail.AddPersonalization(personalization2);

            Assert.False(SendGridHelpers.IsToValid(mail));

            // valid
            personalization2.AddTo(new Email("*****@*****.**"));
            Assert.True(SendGridHelpers.IsToValid(mail));
        }