Skip to content

Commit ac3dad8

Browse files
Updated all non-nullable types, added another unit test
1 parent bcca4db commit ac3dad8

File tree

2 files changed

+203
-24
lines changed

2 files changed

+203
-24
lines changed

SendGrid/SendGrid/Helpers/Mail/Mail.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,11 @@ public String Get()
354354

355355
public class ClickTracking
356356
{
357-
private bool enable;
358-
private bool enableText;
357+
private bool? enable;
358+
private bool? enableText;
359359

360360
[JsonProperty(PropertyName = "enable")]
361-
public bool Enable
361+
public bool? Enable
362362
{
363363
get
364364
{
@@ -372,7 +372,7 @@ public bool Enable
372372
}
373373

374374
[JsonProperty(PropertyName = "enable_text")]
375-
public bool EnableText
375+
public bool? EnableText
376376
{
377377
get
378378
{
@@ -389,11 +389,11 @@ public bool EnableText
389389

390390
public class OpenTracking
391391
{
392-
private bool enable;
392+
private bool? enable;
393393
private String substitutionTag;
394394

395395
[JsonProperty(PropertyName = "enable")]
396-
public bool Enable
396+
public bool? Enable
397397
{
398398
get
399399
{
@@ -424,13 +424,13 @@ public string SubstitutionTag
424424

425425
public class SubscriptionTracking
426426
{
427-
private bool enable;
427+
private bool? enable;
428428
private String text;
429429
private String html;
430430
private String substitutionTag;
431431

432432
[JsonProperty(PropertyName = "enable")]
433-
public bool Enable
433+
public bool? Enable
434434
{
435435
get
436436
{
@@ -489,15 +489,15 @@ public string SubstitutionTag
489489

490490
public class Ganalytics
491491
{
492-
private bool enable;
492+
private bool? enable;
493493
private String utmSource;
494494
private String utmMedium;
495495
private String utmTerm;
496496
private String utmContent;
497497
private String utmCampaign;
498498

499499
[JsonProperty(PropertyName = "enable")]
500-
public bool Enable
500+
public bool? Enable
501501
{
502502
get
503503
{
@@ -649,11 +649,11 @@ public Ganalytics Ganalytics
649649

650650
public class BCCSettings
651651
{
652-
private bool enable;
652+
private bool? enable;
653653
private String email;
654654

655655
[JsonProperty(PropertyName = "enable")]
656-
public bool Enable
656+
public bool? Enable
657657
{
658658
get
659659
{
@@ -684,10 +684,10 @@ public string Email
684684

685685
public class BypassListManagement
686686
{
687-
private bool enable;
687+
private bool? enable;
688688

689689
[JsonProperty(PropertyName = "enable")]
690-
public bool Enable
690+
public bool? Enable
691691
{
692692
get
693693
{
@@ -704,12 +704,12 @@ public bool Enable
704704

705705
public class FooterSettings
706706
{
707-
private bool enable;
707+
private bool? enable;
708708
private String text;
709709
private String html;
710710

711711
[JsonProperty(PropertyName = "enable")]
712-
public bool Enable
712+
public bool? Enable
713713
{
714714
get
715715
{
@@ -754,10 +754,10 @@ public string Html
754754

755755
public class SandboxMode
756756
{
757-
private bool enable;
757+
private bool? enable;
758758

759759
[JsonProperty(PropertyName = "enable")]
760-
public bool Enable
760+
public bool? Enable
761761
{
762762
get
763763
{
@@ -774,12 +774,12 @@ public bool Enable
774774

775775
public class SpamCheck
776776
{
777-
private bool enable;
778-
private int threshold;
777+
private bool? enable;
778+
private int? threshold;
779779
private String postToUrl;
780780

781781
[JsonProperty(PropertyName = "enable")]
782-
public bool Enable
782+
public bool? Enable
783783
{
784784
get
785785
{
@@ -793,7 +793,7 @@ public bool Enable
793793
}
794794

795795
[JsonProperty(PropertyName = "threshold")]
796-
public int Threshold
796+
public int? Threshold
797797
{
798798
get
799799
{
@@ -904,11 +904,11 @@ public SpamCheck SpamCheck
904904

905905
public class ASM
906906
{
907-
private int groupId;
907+
private int? groupId;
908908
private List<int> groupsToDisplay;
909909

910910
[JsonProperty(PropertyName = "group_id")]
911-
public int GroupId
911+
public int? GroupId
912912
{
913913
get
914914
{

SendGrid/UnitTest/UnitTest.cs

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,185 @@ public void TestKitchenSink()
265265
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Include });
266266
Assert.AreEqual(final, "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Hello World from the SendGrid CSharp Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051},{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Textual content\"},{\"type\":\"text/html\",\"value\":\"<html><body>HTML content</body></html>\"},{\"type\":\"text/calendar\",\"value\":\"Party Time!!\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"headers\":{\"X-Day\":\"Monday\",\"X-Month\":\"January\"},\"sections\":{\"%section1\":\"Substitution for Section 1 Tag\",\"%section2\":\"Substitution for Section 2 Tag\"},\"categories\":[\"customer\",\"vip\"],\"custom_args\":{\"campaign\":\"welcome\",\"sequence\":\"2\"},\"send_at\":1461775051,\"asm\":{\"group_id\":3,\"groups_to_display\":[1,4,5]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":true,\"email\":\"[email protected]\"},\"bypass_list_management\":{\"enable\":true},\"footer\":{\"enable\":true,\"text\":\"Some Footer Text\",\"html\":\"<bold>Some HTML Here</bold>\"},\"sandbox_mode\":{\"enable\":true},\"spam_check\":{\"enable\":true,\"threshold\":1,\"post_to_url\":\"https://gotchya.example.com\"}},\"tracking_settings\":{\"click_tracking\":{\"enable\":true,\"enable_text\":false},\"open_tracking\":{\"enable\":true,\"substitution_tag\":\"Optional tag to replace with the open image in the body of the message\"},\"subscription_tracking\":{\"enable\":true,\"text\":\"text to insert into the text/plain portion of the message\",\"html\":\"<bold>HTML to insert into the text/html portion of the message</bold>\",\"substitution_tag\":\"text to insert into the text/plain portion of the message\"},\"ganalytics\":{\"enable\":true,\"utm_source\":\"some source\",\"utm_medium\":\"some medium\",\"utm_term\":\"some term\",\"utm_content\":\"some content\",\"utm_campaign\":\"some campaign\"}},\"reply_to\":{\"email\":\"[email protected]\"}}");
267267
}
268+
269+
// All paramaters available for sending an email
270+
[Test]
271+
public void TestKitchenSinkInverse()
272+
{
273+
Mail mail = new Mail();
274+
275+
Email email = new Email();
276+
email.Name = "Example User";
277+
email.Address = "[email protected]";
278+
mail.From = email;
279+
280+
mail.Subject = "Hello World from the SendGrid CSharp Library";
281+
282+
Personalization personalization = new Personalization();
283+
email = new Email();
284+
email.Name = "Example User";
285+
email.Address = "[email protected]";
286+
personalization.AddTo(email);
287+
email = new Email();
288+
email.Name = "Example User";
289+
email.Address = "[email protected]";
290+
personalization.AddCc(email);
291+
email = new Email();
292+
email.Name = "Example User";
293+
email.Address = "[email protected]";
294+
personalization.AddCc(email);
295+
email = new Email();
296+
email.Name = "Example User";
297+
email.Address = "[email protected]";
298+
personalization.AddBcc(email);
299+
email = new Email();
300+
email.Name = "Example User";
301+
email.Address = "[email protected]";
302+
personalization.AddBcc(email);
303+
personalization.Subject = "Thank you for signing up, %name%";
304+
personalization.AddHeader("X-Test", "True");
305+
personalization.AddHeader("X-Mock", "True");
306+
personalization.AddSubstitution("%name%", "Example User");
307+
personalization.AddSubstitution("%city%", "Denver");
308+
personalization.AddCustomArgs("marketing", "false");
309+
personalization.AddCustomArgs("transactional", "true");
310+
personalization.SendAt = 1461775051;
311+
mail.AddPersonalization(personalization);
312+
313+
personalization = new Personalization();
314+
email = new Email();
315+
email.Name = "Example User";
316+
email.Address = "[email protected]";
317+
personalization.AddTo(email);
318+
email = new Email();
319+
email.Name = "Example User";
320+
email.Address = "[email protected]";
321+
personalization.AddCc(email);
322+
email = new Email();
323+
email.Name = "Example User";
324+
email.Address = "[email protected]";
325+
personalization.AddCc(email);
326+
email = new Email();
327+
email.Name = "Example User";
328+
email.Address = "[email protected]";
329+
personalization.AddBcc(email);
330+
email = new Email();
331+
email.Name = "Example User";
332+
email.Address = "[email protected]";
333+
personalization.AddBcc(email);
334+
personalization.Subject = "Thank you for signing up, %name%";
335+
personalization.AddHeader("X-Test", "True");
336+
personalization.AddHeader("X-Mock", "True");
337+
personalization.AddSubstitution("%name%", "Example User");
338+
personalization.AddSubstitution("%city%", "Denver");
339+
personalization.AddCustomArgs("marketing", "false");
340+
personalization.AddCustomArgs("transactional", "true");
341+
personalization.SendAt = 1461775051;
342+
mail.AddPersonalization(personalization);
343+
344+
Content content = new Content();
345+
content.Type = "text/plain";
346+
content.Value = "Textual content";
347+
mail.AddContent(content);
348+
content = new Content();
349+
content.Type = "text/html";
350+
content.Value = "<html><body>HTML content</body></html>";
351+
mail.AddContent(content);
352+
content = new Content();
353+
content.Type = "text/calendar";
354+
content.Value = "Party Time!!";
355+
mail.AddContent(content);
356+
357+
Attachment attachment = new Attachment();
358+
attachment.Content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12";
359+
attachment.Type = "application/pdf";
360+
attachment.Filename = "balance_001.pdf";
361+
attachment.Disposition = "attachment";
362+
attachment.ContentId = "Balance Sheet";
363+
mail.AddAttachment(attachment);
364+
365+
attachment = new Attachment();
366+
attachment.Content = "BwdW";
367+
attachment.Type = "image/png";
368+
attachment.Filename = "banner.png";
369+
attachment.Disposition = "inline";
370+
attachment.ContentId = "Banner";
371+
mail.AddAttachment(attachment);
372+
373+
mail.TemplateId = "13b8f94f-bcae-4ec6-b752-70d6cb59f932";
374+
375+
mail.AddHeader("X-Day", "Monday");
376+
mail.AddHeader("X-Month", "January");
377+
378+
mail.AddSection("%section1", "Substitution for Section 1 Tag");
379+
mail.AddSection("%section2", "Substitution for Section 2 Tag");
380+
381+
mail.AddCategory("customer");
382+
mail.AddCategory("vip");
383+
384+
mail.AddCustomArgs("campaign", "welcome");
385+
mail.AddCustomArgs("sequence", "2");
386+
387+
ASM asm = new ASM();
388+
asm.GroupId = 3;
389+
List<int> groups_to_display = new List<int>()
390+
{
391+
1, 4, 5
392+
};
393+
asm.GroupsToDisplay = groups_to_display;
394+
mail.Asm = asm;
395+
396+
mail.SendAt = 1461775051;
397+
398+
mail.SetIpPoolId = "23";
399+
400+
// This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
401+
// mail.BatchId = "some_batch_id";
402+
403+
MailSettings mailSettings = new MailSettings();
404+
BCCSettings bccSettings = new BCCSettings();
405+
bccSettings.Enable = false;
406+
mailSettings.BccSettings = bccSettings;
407+
BypassListManagement bypassListManagement = new BypassListManagement();
408+
bypassListManagement.Enable = false;
409+
mailSettings.BypassListManagement = bypassListManagement;
410+
FooterSettings footerSettings = new FooterSettings();
411+
footerSettings.Enable = false;
412+
mailSettings.FooterSettings = footerSettings;
413+
SandboxMode sandboxMode = new SandboxMode();
414+
sandboxMode.Enable = false;
415+
mailSettings.SandboxMode = sandboxMode;
416+
SpamCheck spamCheck = new SpamCheck();
417+
spamCheck.Enable = false;
418+
mailSettings.SpamCheck = spamCheck;
419+
mail.MailSettings = mailSettings;
420+
421+
TrackingSettings trackingSettings = new TrackingSettings();
422+
ClickTracking clickTracking = new ClickTracking();
423+
clickTracking.Enable = false;
424+
trackingSettings.ClickTracking = clickTracking;
425+
OpenTracking openTracking = new OpenTracking();
426+
openTracking.Enable = false;
427+
trackingSettings.OpenTracking = openTracking;
428+
SubscriptionTracking subscriptionTracking = new SubscriptionTracking();
429+
subscriptionTracking.Enable = false;
430+
trackingSettings.SubscriptionTracking = subscriptionTracking;
431+
Ganalytics ganalytics = new Ganalytics();
432+
ganalytics.Enable = false;
433+
trackingSettings.Ganalytics = ganalytics;
434+
mail.TrackingSettings = trackingSettings;
435+
436+
email = new Email();
437+
email.Address = "[email protected]";
438+
mail.ReplyTo = email;
439+
440+
String ret = mail.Get();
441+
String final = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(ret),
442+
Formatting.None,
443+
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore });
444+
Assert.AreEqual(final, "{\"from\":{\"name\":\"Example User\",\"email\":\"[email protected]\"},\"subject\":\"Hello World from the SendGrid CSharp Library\",\"personalizations\":[{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051},{\"to\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"cc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"bcc\":[{\"name\":\"Example User\",\"email\":\"[email protected]\"},{\"name\":\"Example User\",\"email\":\"[email protected]\"}],\"subject\":\"Thank you for signing up, %name%\",\"headers\":{\"X-Test\":\"True\",\"X-Mock\":\"True\"},\"substitutions\":{\"%name%\":\"Example User\",\"%city%\":\"Denver\"},\"custom_args\":{\"marketing\":\"false\",\"transactional\":\"true\"},\"send_at\":1461775051}],\"content\":[{\"type\":\"text/plain\",\"value\":\"Textual content\"},{\"type\":\"text/html\",\"value\":\"<html><body>HTML content</body></html>\"},{\"type\":\"text/calendar\",\"value\":\"Party Time!!\"}],\"attachments\":[{\"content\":\"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12\",\"type\":\"application/pdf\",\"filename\":\"balance_001.pdf\",\"disposition\":\"attachment\",\"content_id\":\"Balance Sheet\"},{\"content\":\"BwdW\",\"type\":\"image/png\",\"filename\":\"banner.png\",\"disposition\":\"inline\",\"content_id\":\"Banner\"}],\"template_id\":\"13b8f94f-bcae-4ec6-b752-70d6cb59f932\",\"headers\":{\"X-Day\":\"Monday\",\"X-Month\":\"January\"},\"sections\":{\"%section1\":\"Substitution for Section 1 Tag\",\"%section2\":\"Substitution for Section 2 Tag\"},\"categories\":[\"customer\",\"vip\"],\"custom_args\":{\"campaign\":\"welcome\",\"sequence\":\"2\"},\"send_at\":1461775051,\"asm\":{\"group_id\":3,\"groups_to_display\":[1,4,5]},\"ip_pool_name\":\"23\",\"mail_settings\":{\"bcc\":{\"enable\":false},\"bypass_list_management\":{\"enable\":false},\"footer\":{\"enable\":false},\"sandbox_mode\":{\"enable\":false},\"spam_check\":{\"enable\":false}},\"tracking_settings\":{\"click_tracking\":{\"enable\":false},\"open_tracking\":{\"enable\":false},\"subscription_tracking\":{\"enable\":false},\"ganalytics\":{\"enable\":false}},\"reply_to\":{\"email\":\"[email protected]\"}}");
445+
}
446+
268447
[Test]
269448
public void test_access_settings_activity_get()
270449
{

0 commit comments

Comments
 (0)