@@ -592,6 +592,91 @@ public void TestCreateMultipleEmailsToMultipleRecipients()
592592 Assert . Equal ( "{\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" },\" personalizations\" :[{\" to\" :[{\" email\" :\" [email protected] \" }],\" subject\" :\" Test Subject1\" ,\" substitutions\" :{\" -name-\" :\" Name1\" }},{\" to\" :[{\" email\" :\" [email protected] \" }],\" subject\" :\" Test Subject2\" ,\" substitutions\" :{\" -name-\" :\" Name1\" }},{\" to\" :[{\" email\" :\" [email protected] \" }],\" subject\" :\" Test Subject3\" ,\" substitutions\" :{\" -name-\" :\" Name1\" }}],\" content\" :[{\" type\" :\" text/plain\" ,\" value\" :\" Hello -name-\" }]}" , msg5 . Serialize ( ) ) ; 593593 }
594594
595+ [ Fact ]
596+ public void TestAddFrom ( )
597+ {
598+ // Personalization not passed in, Personalization does not exist
599+ var msg = new SendGridMessage ( ) ;
600+ msg . AddTo ( new EmailAddress ( "[email protected] " , "Example User" ) ) ; 601+ msg . SetFrom ( new EmailAddress ( "[email protected] " , "Example User" ) ) ; 602+ Assert . Equal ( "{\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" },\" personalizations\" :[{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]}]}" , msg . Serialize ( ) ) ; 603+
604+ // Personalization passed in, no Personalizations
605+ msg = new SendGridMessage ( ) ;
606+ var toEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 607+ var fromEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 608+ var personalization = new Personalization ( )
609+ {
610+ Tos = new List < EmailAddress > ( )
611+ {
612+ toEmail
613+ } ,
614+ From = fromEmail
615+ } ;
616+ msg . AddTo ( new EmailAddress ( "[email protected] " , "Example User" ) , 0 , personalization ) ; 617+ Assert . Equal ( "{\" personalizations\" :[{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }," + 618+ "{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]," + 619+ "\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }}]}" , msg . Serialize ( ) ) ; 620+
621+ // Personalization passed in, Personalization exists
622+ msg = new SendGridMessage ( ) ;
623+ toEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 624+ fromEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 625+ msg . Personalizations = new List < Personalization > ( ) {
626+ new Personalization ( ) {
627+ Tos = new List < EmailAddress > ( )
628+ {
629+ toEmail
630+ } ,
631+ From = fromEmail
632+ }
633+ } ;
634+ toEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 635+ fromEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 636+ personalization = new Personalization ( )
637+ {
638+ Tos = new List < EmailAddress > ( )
639+ {
640+ toEmail
641+ } ,
642+ From = fromEmail
643+ } ;
644+ msg . AddTo ( toEmail , 1 , personalization ) ;
645+ Assert . Equal ( "{\" personalizations\" :[{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]," + 646+ "\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }}," + 647+ "{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]," + 648+ "\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }}]}" , msg . Serialize ( ) ) ; 649+
650+
651+ // Personalization not passed in Personalizations exists
652+ msg = new SendGridMessage ( ) ;
653+ toEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 654+ fromEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 655+ msg . Personalizations = new List < Personalization > ( ) {
656+ new Personalization ( ) {
657+ Tos = new List < EmailAddress > ( )
658+ {
659+ toEmail
660+ } ,
661+ From = fromEmail
662+ }
663+ } ;
664+ toEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 665+ fromEmail = new EmailAddress ( "[email protected] " , "Example User" ) ; 666+ personalization = new Personalization ( )
667+ {
668+ Tos = new List < EmailAddress > ( )
669+ {
670+ toEmail
671+ } ,
672+ From = fromEmail
673+ } ;
674+ msg . Personalizations . Add ( personalization ) ;
675+ msg . AddTo ( new EmailAddress ( "[email protected] " , "Example User" ) ) ; 676+ Assert . Equal ( "{\" personalizations\" :[{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" },{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]," + 677+ "\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }},{\" to\" :[{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }]," + 678+ "\" from\" :{\" name\" :\" Example User\" ,\" email\" :\" [email protected] \" }}]}" , msg . Serialize ( ) ) ; 679+ }
595680 [ Fact ]
596681 public void TestAddTo ( )
597682 {
0 commit comments