public void CreateMessage_CreatesExpectedMessage() { // multiple recipients JObject input = new JObject { { "to", new JArray { "*****@*****.**", "Test Account 2 <*****@*****.**>" } }, { "from", "Test Account 3 <*****@*****.**>" }, { "subject", "Test Subject" }, { "text", "Test Text" } }; SendGridMessage result = SendGridHelpers.CreateMessage(input); Assert.Equal(2, result.To.Length); Assert.Equal("*****@*****.**", result.To[0].Address); Assert.Equal("*****@*****.**", result.To[1].Address); Assert.Equal("Test Account 2", result.To[1].DisplayName); Assert.Equal("*****@*****.**", result.From.Address); Assert.Equal("Test Account 3", result.From.DisplayName); Assert.Equal("Test Subject", result.Subject); Assert.Equal("Test Text", result.Text); // single recipient input = new JObject { { "to", "Test Account 2 <*****@*****.**>" }, { "from", "Test Account 3 <*****@*****.**>" }, { "subject", "Test Subject" }, { "text", "Test Text" } }; result = SendGridHelpers.CreateMessage(input); Assert.Equal(1, result.To.Length); Assert.Equal("*****@*****.**", result.To[0].Address); Assert.Equal("Test Account 2", result.To[0].DisplayName); Assert.Equal("*****@*****.**", result.From.Address); Assert.Equal("Test Account 3", result.From.DisplayName); Assert.Equal("Test Subject", result.Subject); Assert.Equal("Test Text", result.Text); }
public void CreateMessage_CreatesExpectedMessage() { // multiple recipients string mail = @"{ 'personalizations': [ { 'to': [ { 'email': '*****@*****.**' }, { 'email': '*****@*****.**', 'name': 'Test Account 2' } ] } ], 'from': { 'email': '*****@*****.**', 'name': 'Test Account 3' }, 'subject': 'Test Subject', 'content': [ { 'type': 'text/plain', 'value': 'Test Text' } ] }"; SendGridMessage result = SendGridHelpers.CreateMessage(mail); Personalization p = result.Personalizations.Single(); Assert.Equal(2, p.Tos.Count); Assert.Equal("*****@*****.**", p.Tos[0].Email); Assert.Equal("*****@*****.**", p.Tos[1].Email); Assert.Equal("Test Account 2", p.Tos[1].Name); Assert.Equal("*****@*****.**", result.From.Email); Assert.Equal("Test Account 3", result.From.Name); Assert.Equal("Test Subject", result.Subject); Assert.Equal("Test Text", result.Contents.Single().Value); // single recipient mail = @"{ 'personalizations': [ { 'to': [ { 'email': '*****@*****.**', 'name': 'Test Account 2' } ] } ], 'from': { 'email': '*****@*****.**', 'name': 'Test Account 3' }, 'subject': 'Test Subject', 'content': [ { 'type': 'text/plain', 'value': 'Test Text' } ] }"; result = SendGridHelpers.CreateMessage(mail); p = result.Personalizations.Single(); Assert.Equal(1, p.Tos.Count); Assert.Equal("*****@*****.**", p.Tos[0].Email); Assert.Equal("Test Account 2", p.Tos[0].Name); Assert.Equal("*****@*****.**", result.From.Email); Assert.Equal("Test Account 3", result.From.Name); Assert.Equal("Test Subject", result.Subject); Assert.Equal("Test Text", result.Contents.Single().Value); }