diff --git a/src/SendGrid.Extensions.DependencyInjection/InjectableSendGridClient.cs b/src/SendGrid.Extensions.DependencyInjection/InjectableSendGridClient.cs index 3e8241d90..e2df538ef 100644 --- a/src/SendGrid.Extensions.DependencyInjection/InjectableSendGridClient.cs +++ b/src/SendGrid.Extensions.DependencyInjection/InjectableSendGridClient.cs @@ -13,7 +13,7 @@ namespace SendGrid.Extensions.DependencyInjection /// internal class InjectableSendGridClient : BaseClient { - public InjectableSendGridClient(HttpClient httpClient, IOptions options) + public InjectableSendGridClient(HttpClient? httpClient, IOptions options) : base(httpClient, options.Value) { } diff --git a/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj b/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj index 1d92f7d69..b8b8a932f 100644 --- a/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj +++ b/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj @@ -7,6 +7,9 @@ true true ..\SendGrid\SendGrid.ruleset + enable + nullable + 8 diff --git a/src/SendGrid/BaseClient.cs b/src/SendGrid/BaseClient.cs index 3e2a351d6..7ff36ed24 100644 --- a/src/SendGrid/BaseClient.cs +++ b/src/SendGrid/BaseClient.cs @@ -30,7 +30,7 @@ public abstract class BaseClient : ISendGridClient /// /// The client assembly version to send in request User-Agent header. /// - private static readonly string ClientVersion = typeof(BaseClient).GetTypeInfo().Assembly.GetName().Version.ToString(); + private static readonly string ClientVersion = typeof(BaseClient).GetTypeInfo().Assembly.GetName().Version!.ToString(); /// /// The configuration to use with current client instance. @@ -47,7 +47,7 @@ public abstract class BaseClient : ISendGridClient /// /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - protected BaseClient(BaseClientOptions options) + protected BaseClient(BaseClientOptions? options) : this(httpClient: null, options) { } @@ -58,7 +58,7 @@ protected BaseClient(BaseClientOptions options) /// Web proxy. /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - protected BaseClient(IWebProxy webProxy, BaseClientOptions options) + protected BaseClient(IWebProxy? webProxy, BaseClientOptions options) : this(CreateHttpClientWithWebProxy(webProxy, options), options) { } @@ -69,7 +69,7 @@ protected BaseClient(IWebProxy webProxy, BaseClientOptions options) /// An optional HTTP client which may me injected in order to facilitate testing. /// A instance that defines the configuration settings to use with the client. /// Interface to the Twilio SendGrid REST API. - protected BaseClient(HttpClient httpClient, BaseClientOptions options) + protected BaseClient(HttpClient? httpClient, BaseClientOptions? options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); @@ -123,7 +123,7 @@ public string UrlPath /// /// The API version. /// - public string Version + public string? Version { get => this.options.Version; set => this.options.Version = value; @@ -151,7 +151,7 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePairThe parameters for the API call. /// Cancel the asynchronous call. /// Response object. - public virtual async Task MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)) + public virtual async Task MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default) { HttpResponseMessage response = await this.client.SendAsync(request, cancellationToken).ConfigureAwait(false); @@ -182,10 +182,10 @@ public virtual AuthenticationHeaderValue AddAuthorization(KeyValuePair public async Task RequestAsync( SendGridClient.Method method, - string requestBody = null, - string queryParams = null, - string urlPath = null, - CancellationToken cancellationToken = default(CancellationToken)) + string? requestBody = null, + string? queryParams = null, + string? urlPath = null, + CancellationToken cancellationToken = default) { var baseAddress = new Uri(this.options.Host); if (!baseAddress.OriginalString.EndsWith("/")) @@ -204,7 +204,7 @@ public async Task RequestAsync( // Drop the default UTF-8 content type charset for JSON payloads since some APIs may not accept it. if (request.Content != null && this.MediaType == DefaultMediaType) { - request.Content.Headers.ContentType.CharSet = null; + request.Content.Headers.ContentType!.CharSet = null; } // set header overrides @@ -229,7 +229,7 @@ public async Task RequestAsync( /// A SendGridMessage object with the details for the request. /// Cancel the asynchronous call. /// A Response object. - public async Task SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default(CancellationToken)) + public async Task SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default) { return await this.RequestAsync( Method.POST, @@ -249,7 +249,7 @@ private static HttpClient CreateHttpClientWithRetryHandler(BaseClientOptions opt /// the WebProxy. /// A instance that defines the configuration settings to use with the client. /// HttpClient with RetryDelegatingHandler and WebProxy if set. - private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy, BaseClientOptions options) + private static HttpClient CreateHttpClientWithWebProxy(IWebProxy? webProxy, BaseClientOptions options) { if (webProxy != null) { @@ -276,13 +276,12 @@ private static HttpClient CreateHttpClientWithWebProxy(IWebProxy webProxy, BaseC /// The URL path. /// A string of JSON formatted query parameters (e.g. {'param': 'param_value'}). /// Final URL. - private string BuildUrl(string urlPath, string queryParams = null) + private string BuildUrl(string? urlPath, string? queryParams = null) { - string url = null; - // create urlPAth - from parameter if overridden on call or from constructor parameter var urlpath = urlPath ?? this.options.UrlPath; + string url; if (this.options.Version != null) { url = this.options.Version + "/" + urlpath; @@ -338,7 +337,7 @@ private Dictionary> ParseJson(string json) { case JsonToken.PropertyName: { - propertyName = reader.Value.ToString(); + propertyName = reader.Value.ToString()!; if (!dict.ContainsKey(propertyName)) { dict.Add(propertyName, new List()); diff --git a/src/SendGrid/BaseClientOptions.cs b/src/SendGrid/BaseClientOptions.cs index f385c6d8f..406ee98da 100644 --- a/src/SendGrid/BaseClientOptions.cs +++ b/src/SendGrid/BaseClientOptions.cs @@ -29,22 +29,22 @@ public ReliabilitySettings ReliabilitySettings /// /// The base URL. /// - public string Host { get; set; } + public string Host { get; set; } = string.Empty; /// /// The API version (defaults to "v3"). /// - public string Version { get; set; } = "v3"; + public string? Version { get; set; } = "v3"; /// /// The path to the API endpoint. /// - public string UrlPath { get; set; } + public string UrlPath { get; set; } = string.Empty; /// /// The Auth header value. /// - public AuthenticationHeaderValue Auth { get; set; } + public AuthenticationHeaderValue? Auth { get; set; } /// /// Gets or sets a value indicating whether HTTP error responses should be raised as exceptions. Default is false. diff --git a/src/SendGrid/Helpers/Errors/ErrorHandler.cs b/src/SendGrid/Helpers/Errors/ErrorHandler.cs index bb1204681..39cd308f8 100644 --- a/src/SendGrid/Helpers/Errors/ErrorHandler.cs +++ b/src/SendGrid/Helpers/Errors/ErrorHandler.cs @@ -90,9 +90,9 @@ private static async Task GetErrorMessage(HttpResponseMessage message) var errorStatusCode = (int)message.StatusCode; var errorReasonPhrase = message.ReasonPhrase; - string errorValue = null; - string fieldValue = null; - string helpValue = null; + string? errorValue = null; + string? fieldValue = null; + string? helpValue = null; if (message.Content != null) { diff --git a/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs b/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs index 1f55189fa..922b911af 100644 --- a/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs +++ b/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs @@ -13,21 +13,21 @@ public class SendGridErrorResponse /// /// Gets or sets the error Reason Phrase /// - public string ErrorReasonPhrase { get; set; } + public string? ErrorReasonPhrase { get; set; } /// /// Gets or sets the SendGrid error message /// - public string SendGridErrorMessage { get; set; } + public string? SendGridErrorMessage { get; set; } /// /// Gets or sets the field that has the error /// - public string FieldWithError { get; set; } + public string? FieldWithError { get; set; } /// /// Gets or sets the error default help /// - public string HelpLink { get; set; } + public string? HelpLink { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/MailHelper.cs b/src/SendGrid/Helpers/Mail/MailHelper.cs index 51b2cae83..643803224 100644 --- a/src/SendGrid/Helpers/Mail/MailHelper.cs +++ b/src/SendGrid/Helpers/Mail/MailHelper.cs @@ -30,23 +30,23 @@ public class MailHelper /// The text/html content of the email body. /// A SendGridMessage object. public static SendGridMessage CreateSingleEmail( - EmailAddress from, - EmailAddress to, - string subject, - string plainTextContent, - string htmlContent) + EmailAddress from, + EmailAddress to, + string subject, + string? plainTextContent, + string? htmlContent) { var msg = new SendGridMessage(); msg.SetFrom(from); msg.SetSubject(subject); if (!string.IsNullOrEmpty(plainTextContent)) { - msg.AddContent(MimeType.Text, plainTextContent); + msg.AddContent(MimeType.Text, plainTextContent!); } if (!string.IsNullOrEmpty(htmlContent)) { - msg.AddContent(MimeType.Html, htmlContent); + msg.AddContent(MimeType.Html, htmlContent!); } msg.AddTo(to); @@ -62,10 +62,10 @@ public static SendGridMessage CreateSingleEmail( /// The data with which to populate the dynamic template. /// A SendGridMessage object. public static SendGridMessage CreateSingleTemplateEmail( - EmailAddress from, - EmailAddress to, - string templateId, - object dynamicTemplateData) + EmailAddress from, + EmailAddress to, + string templateId, + object? dynamicTemplateData) { if (string.IsNullOrWhiteSpace(templateId)) { @@ -95,23 +95,23 @@ public static SendGridMessage CreateSingleTemplateEmail( /// The text/html content of the email body. /// A SendGridMessage object. public static SendGridMessage CreateSingleEmailToMultipleRecipients( - EmailAddress from, - List tos, - string subject, - string plainTextContent, - string htmlContent) + EmailAddress from, + List tos, + string subject, + string? plainTextContent, + string? htmlContent) { var msg = new SendGridMessage(); msg.SetFrom(from); msg.SetGlobalSubject(subject); if (!string.IsNullOrEmpty(plainTextContent)) { - msg.AddContent(MimeType.Text, plainTextContent); + msg.AddContent(MimeType.Text, plainTextContent!); } if (!string.IsNullOrEmpty(htmlContent)) { - msg.AddContent(MimeType.Html, htmlContent); + msg.AddContent(MimeType.Html, htmlContent!); } for (var i = 0; i < tos.Count; i++) @@ -131,10 +131,10 @@ public static SendGridMessage CreateSingleEmailToMultipleRecipients( /// The data with which to populate the dynamic template. /// A SendGridMessage object. public static SendGridMessage CreateSingleTemplateEmailToMultipleRecipients( - EmailAddress from, - List tos, - string templateId, - object dynamicTemplateData) + EmailAddress from, + List tos, + string templateId, + object? dynamicTemplateData) { if (string.IsNullOrWhiteSpace(templateId)) { @@ -153,7 +153,7 @@ public static SendGridMessage CreateSingleTemplateEmailToMultipleRecipients( if (setDynamicTemplateDataValues) { - msg.SetTemplateData(dynamicTemplateData, i); + msg.SetTemplateData(dynamicTemplateData!, i); } } @@ -171,23 +171,23 @@ public static SendGridMessage CreateSingleTemplateEmailToMultipleRecipients( /// Substitution key/values to customize the content for each email. /// A SendGridMessage object. public static SendGridMessage CreateMultipleEmailsToMultipleRecipients( - EmailAddress from, - List tos, - List subjects, - string plainTextContent, - string htmlContent, - List> substitutions) + EmailAddress from, + List tos, + List subjects, + string? plainTextContent, + string? htmlContent, + List> substitutions) { var msg = new SendGridMessage(); msg.SetFrom(from); if (!string.IsNullOrEmpty(plainTextContent)) { - msg.AddContent(MimeType.Text, plainTextContent); + msg.AddContent(MimeType.Text, plainTextContent!); } if (!string.IsNullOrEmpty(htmlContent)) { - msg.AddContent(MimeType.Html, htmlContent); + msg.AddContent(MimeType.Html, htmlContent!); } for (var i = 0; i < tos.Count; i++) @@ -209,10 +209,10 @@ public static SendGridMessage CreateMultipleEmailsToMultipleRecipients( /// The data with which to populate the dynamic template. /// A SendGridMessage object. public static SendGridMessage CreateMultipleTemplateEmailsToMultipleRecipients( - EmailAddress from, - List tos, - string templateId, - List dynamicTemplateData) + EmailAddress from, + List tos, + string templateId, + List? dynamicTemplateData) { if (string.IsNullOrWhiteSpace(templateId)) { @@ -231,7 +231,7 @@ public static SendGridMessage CreateMultipleTemplateEmailsToMultipleRecipients( if (setDynamicTemplateDataValues) { - msg.SetTemplateData(dynamicTemplateData[i], i); + msg.SetTemplateData(dynamicTemplateData![i], i); } } @@ -267,12 +267,12 @@ public static EmailAddress StringToEmailAddress(string rfc2822Email) /// Displays all the recipients present in the "To" section of email.The default value is false. /// A SendGridMessage object. public static SendGridMessage CreateSingleEmailToMultipleRecipients( - EmailAddress from, - List tos, - string subject, - string plainTextContent, - string htmlContent, - bool showAllRecipients = false) + EmailAddress from, + List tos, + string subject, + string? plainTextContent, + string? htmlContent, + bool showAllRecipients = false) { var msg = new SendGridMessage(); if (showAllRecipients) @@ -281,12 +281,12 @@ public static SendGridMessage CreateSingleEmailToMultipleRecipients( msg.SetGlobalSubject(subject); if (!string.IsNullOrEmpty(plainTextContent)) { - msg.AddContent(MimeType.Text, plainTextContent); + msg.AddContent(MimeType.Text, plainTextContent!); } if (!string.IsNullOrEmpty(htmlContent)) { - msg.AddContent(MimeType.Html, htmlContent); + msg.AddContent(MimeType.Html, htmlContent!); } msg.AddTos(tos); diff --git a/src/SendGrid/Helpers/Mail/Model/ASM.cs b/src/SendGrid/Helpers/Mail/Model/ASM.cs index 526f8714a..37ab31d21 100644 --- a/src/SendGrid/Helpers/Mail/Model/ASM.cs +++ b/src/SendGrid/Helpers/Mail/Model/ASM.cs @@ -25,6 +25,6 @@ public class ASM /// https://sendgrid.com/docs/User_Guide/Suppressions/recipient_subscription_preferences.html. /// [JsonProperty(PropertyName = "groups_to_display", IsReference = false)] - public List GroupsToDisplay { get; set; } + public List GroupsToDisplay { get; set; } = new List(); } } diff --git a/src/SendGrid/Helpers/Mail/Model/Attachment.cs b/src/SendGrid/Helpers/Mail/Model/Attachment.cs index 92a0db625..bc456dda9 100644 --- a/src/SendGrid/Helpers/Mail/Model/Attachment.cs +++ b/src/SendGrid/Helpers/Mail/Model/Attachment.cs @@ -17,30 +17,30 @@ public class Attachment /// Gets or sets the Base64 encoded content of the attachment. /// [JsonProperty(PropertyName = "content")] - public string Content { get; set; } + public string Content { get; set; } = string.Empty; /// /// Gets or sets the mime type of the content you are attaching. For example, application/pdf or image/jpeg. /// [JsonProperty(PropertyName = "type")] - public string Type { get; set; } + public string? Type { get; set; } /// /// Gets or sets the filename of the attachment. /// [JsonProperty(PropertyName = "filename")] - public string Filename { get; set; } + public string Filename { get; set; } = string.Empty; /// /// Gets or sets the content-disposition of the attachment specifying how you would like the attachment to be displayed. For example, "inline" results in the attached file being displayed automatically within the message while "attachment" results in the attached file requiring some action to be taken before it is displayed (e.g. opening or downloading the file). Defaults to "attachment". Can be either "attachment" or "inline". /// [JsonProperty(PropertyName = "disposition")] - public string Disposition { get; set; } + public string? Disposition { get; set; } /// /// Gets or sets a unique id that you specify for the attachment. This is used when the disposition is set to "inline" and the attachment is an image, allowing the file to be displayed within the body of your email. Ex: . /// [JsonProperty(PropertyName = "content_id")] - public string ContentId { get; set; } + public string? ContentId { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/BCCSettings.cs b/src/SendGrid/Helpers/Mail/Model/BCCSettings.cs index c539adef5..de02fe56e 100644 --- a/src/SendGrid/Helpers/Mail/Model/BCCSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/BCCSettings.cs @@ -23,6 +23,6 @@ public class BCCSettings /// Gets or sets the email address that you would like to receive the BCC. /// [JsonProperty(PropertyName = "email")] - public string Email { get; set; } + public string Email { get; set; } = string.Empty; } } diff --git a/src/SendGrid/Helpers/Mail/Model/Content.cs b/src/SendGrid/Helpers/Mail/Model/Content.cs index 844fee8ab..b8f967c6a 100644 --- a/src/SendGrid/Helpers/Mail/Model/Content.cs +++ b/src/SendGrid/Helpers/Mail/Model/Content.cs @@ -4,6 +4,7 @@ // using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; namespace SendGrid.Helpers.Mail { @@ -35,12 +36,14 @@ public Content(string type, string value) /// Gets or sets the mime type of the content you are including in your email. For example, text/plain or text/html. /// [JsonProperty(PropertyName = "type")] - public string Type { get; set; } + [DisallowNull] + public string? Type { get; set; } /// /// Gets or sets the actual content of the specified mime type that you are including in your email. /// [JsonProperty(PropertyName = "value")] - public string Value { get; set; } + [DisallowNull] + public string? Value { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs b/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs index cbf7baafd..9f8cab8ce 100644 --- a/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs +++ b/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs @@ -26,7 +26,7 @@ public EmailAddress() /// /// The email address of the sender or recipient. /// The name of the sender or recipient. - public EmailAddress(string email, string name = null) + public EmailAddress(string? email, string? name = null) { this.Email = email; this.Name = name; @@ -36,13 +36,13 @@ public EmailAddress(string email, string name = null) /// Gets or sets the name of the sender or recipient. /// [JsonProperty(PropertyName = "name")] - public string Name { get; set; } + public string? Name { get; set; } /// /// Gets or sets the email address of the sender or recipient. /// [JsonProperty(PropertyName = "email")] - public string Email { get; set; } + public string? Email { get; set; } /// /// Determines whether the two specified operands are equal. @@ -50,7 +50,7 @@ public EmailAddress(string email, string name = null) /// The left hand operand in the equation. /// The right hand operand in the equation. /// True if equal, false if not. - public static bool operator ==(EmailAddress left, EmailAddress right) + public static bool operator ==(EmailAddress? left, EmailAddress? right) { if (left is null && right is null) { @@ -66,7 +66,7 @@ public EmailAddress(string email, string name = null) /// The left hand operand in the equation. /// The right hand operand in the equation. /// True if the two operands are not equal, and false if they are. - public static bool operator !=(EmailAddress left, EmailAddress right) + public static bool operator !=(EmailAddress? left, EmailAddress? right) { return !(left == right); } @@ -76,7 +76,7 @@ public EmailAddress(string email, string name = null) /// /// The comparand email address. /// true if the objects are equal, false if they're not. - public bool Equals(EmailAddress other) + public bool Equals(EmailAddress? other) { if (other is null) { @@ -96,7 +96,7 @@ public bool Equals(EmailAddress other) /// /// The comparand object. /// true if the objects are equal, false if they're not. - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is null) { diff --git a/src/SendGrid/Helpers/Mail/Model/FooterSettings.cs b/src/SendGrid/Helpers/Mail/Model/FooterSettings.cs index 92af9487c..1e8f0f2b8 100644 --- a/src/SendGrid/Helpers/Mail/Model/FooterSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/FooterSettings.cs @@ -23,12 +23,12 @@ public class FooterSettings /// Gets or sets the plain text content of your footer. /// [JsonProperty(PropertyName = "text")] - public string Text { get; set; } + public string? Text { get; set; } /// /// Gets or sets the HTML content of your footer. /// [JsonProperty(PropertyName = "html")] - public string Html { get; set; } + public string? Html { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/Ganalytics.cs b/src/SendGrid/Helpers/Mail/Model/Ganalytics.cs index c2a0413de..7d7b51697 100644 --- a/src/SendGrid/Helpers/Mail/Model/Ganalytics.cs +++ b/src/SendGrid/Helpers/Mail/Model/Ganalytics.cs @@ -23,30 +23,30 @@ public class Ganalytics /// Gets or sets the name of the referrer source (e.g. Google, SomeDomain.com, or Marketing Email). /// [JsonProperty(PropertyName = "utm_source")] - public string UtmSource { get; set; } + public string? UtmSource { get; set; } /// /// Gets or sets the name of the marketing medium (e.g. Email). /// [JsonProperty(PropertyName = "utm_medium")] - public string UtmMedium { get; set; } + public string? UtmMedium { get; set; } /// /// Gets or sets the identification of any paid keywords. /// [JsonProperty(PropertyName = "utm_term")] - public string UtmTerm { get; set; } + public string? UtmTerm { get; set; } /// /// Gets or sets the differentiation of your campaign from advertisements. /// [JsonProperty(PropertyName = "utm_content")] - public string UtmContent { get; set; } + public string? UtmContent { get; set; } /// /// Gets or sets the name of the campaign. /// [JsonProperty(PropertyName = "utm_campaign")] - public string UtmCampaign { get; set; } + public string? UtmCampaign { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/JsonConverters.cs b/src/SendGrid/Helpers/Mail/Model/JsonConverters.cs index b199af649..b8e2c0fd2 100644 --- a/src/SendGrid/Helpers/Mail/Model/JsonConverters.cs +++ b/src/SendGrid/Helpers/Mail/Model/JsonConverters.cs @@ -44,10 +44,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s /// /// Determines whether this instance can convert the specified object type. /// - public override bool CanRead - { - get { return false; } - } + public override bool CanRead => false; /// /// Reads the JSON representation of the object. diff --git a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs index 95cf3456e..d71fcdf4a 100644 --- a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs @@ -17,49 +17,49 @@ public class MailSettings /// Gets or sets the address specified in the mail_settings.bcc object will receive a blind carbon copy (BCC) of the very first personalization defined in the personalizations array. /// [JsonProperty(PropertyName = "bcc")] - public BCCSettings BccSettings { get; set; } + public BCCSettings? BccSettings { get; set; } /// /// Gets or sets the bypass of all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient. This should only be used in emergencies when it is absolutely necessary that every recipient receives your email. Ex: outage emails, or forgot password emails. /// [JsonProperty(PropertyName = "bypass_list_management")] - public BypassListManagement BypassListManagement { get; set; } + public BypassListManagement? BypassListManagement { get; set; } /// /// Gets or sets the bypass of spam report list to ensure that the email is delivered to recipients. Bounce and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. /// [JsonProperty(PropertyName = "bypass_spam_management")] - public BypassSpamManagement BypassSpamManagement { get; set; } + public BypassSpamManagement? BypassSpamManagement { get; set; } /// /// Gets or sets the bypass the bounce list to ensure that the email is delivered to recipients. Spam report and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. /// [JsonProperty(PropertyName = "bypass_bounce_management")] - public BypassBounceManagement BypassBounceManagement { get; set; } + public BypassBounceManagement? BypassBounceManagement { get; set; } /// /// Gets or sets the bypass the global unsubscribe list to ensure that the email is delivered to recipients. Bounce and spam report lists will still be checked; addresses on these other lists will not receive the message. This filter applies only to global unsubscribes and will not bypass group unsubscribes. /// [JsonProperty(PropertyName = "bypass_unsubscribe_management")] - public BypassUnsubscribeManagement BypassUnsubscribeManagement { get; set; } + public BypassUnsubscribeManagement? BypassUnsubscribeManagement { get; set; } /// /// Gets or sets the default footer that you would like appended to the bottom of every email. /// [JsonProperty(PropertyName = "footer")] - public FooterSettings FooterSettings { get; set; } + public FooterSettings? FooterSettings { get; set; } /// /// Gets or sets the ability to send a test email to ensure that your request body is valid and formatted correctly. For more information, please see our Classroom. /// https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/sandbox_mode.html. /// [JsonProperty(PropertyName = "sandbox_mode")] - public SandboxMode SandboxMode { get; set; } + public SandboxMode? SandboxMode { get; set; } /// /// Gets or sets the ability to test the content of your email for spam. /// [JsonProperty(PropertyName = "spam_check")] - public SpamCheck SpamCheck { get; set; } + public SpamCheck? SpamCheck { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/OpenTracking.cs b/src/SendGrid/Helpers/Mail/Model/OpenTracking.cs index f869686bc..05750088e 100644 --- a/src/SendGrid/Helpers/Mail/Model/OpenTracking.cs +++ b/src/SendGrid/Helpers/Mail/Model/OpenTracking.cs @@ -23,6 +23,6 @@ public class OpenTracking /// Gets or sets the ability to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel. /// [JsonProperty(PropertyName = "substitution_tag")] - public string SubstitutionTag { get; set; } + public string? SubstitutionTag { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index c00ad392e..4f4261aca 100644 --- a/src/SendGrid/Helpers/Mail/Model/Personalization.cs +++ b/src/SendGrid/Helpers/Mail/Model/Personalization.cs @@ -5,6 +5,7 @@ using Newtonsoft.Json; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace SendGrid.Helpers.Mail { @@ -20,52 +21,53 @@ public class Personalization /// [JsonProperty(PropertyName = "to", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Tos { get; set; } + public List Tos { get; set; } = new List(); /// /// Gets or sets an array of recipients who will receive a copy of your email. Each email object within this array may contain the recipient’s name, but must always contain the recipient’s email. /// [JsonProperty(PropertyName = "cc", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Ccs { get; set; } + public List? Ccs { get; set; } /// /// Gets or sets an array of recipients who will receive a blind carbon copy of your email. Each email object within this array may contain the recipient’s name, but must always contain the recipient’s email. /// [JsonProperty(PropertyName = "bcc", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Bccs { get; set; } + public List? Bccs { get; set; } /// /// Gets or sets the from email address. The domain must match the domain of the from email property specified at root level of the request body. /// [JsonProperty(PropertyName = "from")] - public EmailAddress From { get; set; } + [DisallowNull] + public EmailAddress? From { get; set; } /// /// Gets or sets the subject line of your email. /// [JsonProperty(PropertyName = "subject")] - public string Subject { get; set; } + public string? Subject { get; set; } /// /// Gets or sets the object allowing you to specify specific handling instructions for your email. /// [JsonProperty(PropertyName = "headers", IsReference = false)] - public Dictionary Headers { get; set; } + public Dictionary? Headers { get; set; } /// /// Gets or sets an object following the pattern "substitution_tag":"value to substitute". All are assumed to be strings. These substitutions will apply to the content of your email, in addition to the subject and reply-to parameters. /// You may not include more than 100 substitutions per personalization object, and the total collective size of your substitutions may not exceed 10,000 bytes per personalization object. /// [JsonProperty(PropertyName = "substitutions", IsReference = false)] - public Dictionary Substitutions { get; set; } + public Dictionary? Substitutions { get; set; } /// /// Gets or sets the values that are specific to this personalization that will be carried along with the email, activity data, and links. Substitutions will not be made on custom arguments. personalizations[x].custom_args will be merged with message level custom_args, overriding any conflicting keys. The combined total size of the resulting custom arguments, after merging, for each personalization may not exceed 10,000 bytes. /// [JsonProperty(PropertyName = "custom_args", IsReference = false)] - public Dictionary CustomArgs { get; set; } + public Dictionary? CustomArgs { get; set; } /// /// Gets or sets a unix timestamp allowing you to specify when you want your email to be sent from Twilio SendGrid. This is not necessary if you want the email to be sent at the time of your API request. @@ -77,6 +79,6 @@ public class Personalization /// Gets or sets the template data object following the pattern "template data key":"template data value". All are assumed to be strings. These key value pairs will apply to the content of your template email, in addition to the subject and reply-to parameters. /// [JsonProperty(PropertyName = "dynamic_template_data", IsReference = false)] - public object TemplateData { get; set; } + public object? TemplateData { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/SpamCheck.cs b/src/SendGrid/Helpers/Mail/Model/SpamCheck.cs index 0f54f57f7..0de1f89f3 100644 --- a/src/SendGrid/Helpers/Mail/Model/SpamCheck.cs +++ b/src/SendGrid/Helpers/Mail/Model/SpamCheck.cs @@ -29,6 +29,6 @@ public class SpamCheck /// Gets or sets an Inbound Parse URL that you would like a copy of your email along with the spam report to be sent to. The post_to_url parameter must start with http:// or https://. /// [JsonProperty(PropertyName = "post_to_url")] - public string PostToUrl { get; set; } + public string? PostToUrl { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/SubscriptionTracking.cs b/src/SendGrid/Helpers/Mail/Model/SubscriptionTracking.cs index af70ea973..e957a1ee3 100644 --- a/src/SendGrid/Helpers/Mail/Model/SubscriptionTracking.cs +++ b/src/SendGrid/Helpers/Mail/Model/SubscriptionTracking.cs @@ -23,18 +23,18 @@ public class SubscriptionTracking /// Gets or sets the text to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag (percent symbol) (percent symbol). /// [JsonProperty(PropertyName = "text")] - public string Text { get; set; } + public string? Text { get; set; } /// /// Gets or sets the HTML to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag (percent symbol) (percent symbol). /// [JsonProperty(PropertyName = "html")] - public string Html { get; set; } + public string? Html { get; set; } /// /// Gets or sets a tag that will be replaced with the unsubscribe URL. for example: [unsubscribe_url]. If this parameter is used, it will override both the textand html parameters. The URL of the link will be placed at the substitution tag’s location, with no additional formatting. /// [JsonProperty(PropertyName = "substitution_tag")] - public string SubstitutionTag { get; set; } + public string? SubstitutionTag { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/Model/TrackingSettings.cs b/src/SendGrid/Helpers/Mail/Model/TrackingSettings.cs index b0dc22fac..82c6f502a 100644 --- a/src/SendGrid/Helpers/Mail/Model/TrackingSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/TrackingSettings.cs @@ -17,24 +17,24 @@ public class TrackingSettings /// Gets or sets tracking whether a recipient clicked a link in your email. /// [JsonProperty(PropertyName = "click_tracking")] - public ClickTracking ClickTracking { get; set; } + public ClickTracking? ClickTracking { get; set; } /// /// Gets or sets tracking whether the email was opened or not, but including a single pixel image in the body of the content. When the pixel is loaded, we can log that the email was opened. /// [JsonProperty(PropertyName = "open_tracking")] - public OpenTracking OpenTracking { get; set; } + public OpenTracking? OpenTracking { get; set; } /// /// Gets or sets a subscription management link at the bottom of the text and html bodies of your email. If you would like to specify the location of the link within your email, you may use the substitution_tag. /// [JsonProperty(PropertyName = "subscription_tracking")] - public SubscriptionTracking SubscriptionTracking { get; set; } + public SubscriptionTracking? SubscriptionTracking { get; set; } /// /// Gets or sets tracking provided by Google Analytics. /// [JsonProperty(PropertyName = "ganalytics")] - public Ganalytics Ganalytics { get; set; } + public Ganalytics? Ganalytics { get; set; } } } diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 4c62a01f3..13f3bc871 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -7,6 +7,7 @@ using SendGrid.Helpers.Mail.Model; using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; @@ -26,74 +27,75 @@ public class SendGridMessage /// Gets or sets an email object containing the email address and name of the sender. Unicode encoding is not supported for the from field. /// [JsonProperty(PropertyName = "from")] - public EmailAddress From { get; set; } + [DisallowNull] + public EmailAddress? From { get; set; } /// /// Gets or sets the subject of your email. This may be overridden by personalizations[x].subject. /// [JsonProperty(PropertyName = "subject")] - public string Subject { get; set; } + public string? Subject { get; set; } /// /// Gets or sets a list of messages and their metadata. Each object within personalizations can be thought of as an envelope - it defines who should receive an individual message and how that message should be handled. For more information, please see our documentation on Personalizations. Parameters in personalizations will override the parameters of the same name from the message level. /// https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html. /// [JsonProperty(PropertyName = "personalizations", IsReference = false)] - public List Personalizations { get; set; } + public List? Personalizations { get; set; } /// /// Gets or sets a list in which you may specify the content of your email. You can include multiple mime types of content, but you must specify at least one. To include more than one mime type, simply add another object to the array containing the type and value parameters. If included, text/plain and text/html must be the first indices of the array in this order. If you choose to include the text/plain or text/html mime types, they must be the first indices of the content array in the order text/plain, text/html.*Content is NOT mandatory if you using a transactional template and have defined the template_id in the Request. /// [JsonProperty(PropertyName = "content", IsReference = false)] - public List Contents { get; set; } + public List? Contents { get; set; } /// /// Gets or sets a Content object with a Mime Type of text/plain. /// [JsonIgnore] - public string PlainTextContent { get; set; } + public string? PlainTextContent { get; set; } /// /// Gets or sets a Content object with a Mime Type of text/html. /// [JsonIgnore] - public string HtmlContent { get; set; } + public string? HtmlContent { get; set; } /// /// Gets or sets a list of objects in which you can specify any attachments you want to include. /// [JsonProperty(PropertyName = "attachments", IsReference = false)] - public List Attachments { get; set; } + public List? Attachments { get; set; } /// /// Gets or sets the id of a template that you would like to use. If you use a template that contains content and a subject (either text or html), you do not need to specify those in the respective personalizations or message level parameters. /// [JsonProperty(PropertyName = "template_id")] - public string TemplateId { get; set; } + public string? TemplateId { get; set; } /// /// Gets or sets an object containing key/value pairs of header names and the value to substitute for them. You must ensure these are properly encoded if they contain unicode characters. Must not be any of the following reserved headers: x-sg-id, x-sg-eid, received, dkim-signature, Content-Type, Content-Transfer-Encoding, To, From, Subject, Reply-To, CC, BCC. /// [JsonProperty(PropertyName = "headers", IsReference = false)] - public Dictionary Headers { get; set; } + public Dictionary? Headers { get; set; } /// /// Gets or sets an object of key/value pairs that define large blocks of content that can be inserted into your emails using substitution tags. /// [JsonProperty(PropertyName = "sections", IsReference = false)] - public Dictionary Sections { get; set; } + public Dictionary? Sections { get; set; } /// /// Gets or sets a list of category names for this message. Each category name may not exceed 255 characters. You cannot have more than 10 categories per request. /// [JsonProperty(PropertyName = "categories", IsReference = false)] - public List Categories { get; set; } + public List? Categories { get; set; } /// /// Gets or sets values that are specific to the entire send that will be carried along with the email and its activity data. Substitutions will not be made on custom arguments, so any string that is entered into this parameter will be assumed to be the custom argument that you would like to be used. This parameter is overridden by any conflicting personalizations[x].custom_args if that parameter has been defined. If personalizations[x].custom_args has been defined but does not conflict with the values defined within this parameter, the two will be merged. The combined total size of these custom arguments may not exceed 10,000 bytes. /// [JsonProperty(PropertyName = "custom_args", IsReference = false)] - public Dictionary CustomArgs { get; set; } + public Dictionary? CustomArgs { get; set; } /// /// Gets or sets a unix timestamp allowing you to specify when you want your email to be sent from SendGrid. This is not necessary if you want the email to be sent at the time of your API request. @@ -105,54 +107,54 @@ public class SendGridMessage /// Gets or sets an object allowing you to specify how to handle unsubscribes. /// [JsonProperty(PropertyName = "asm")] - public ASM Asm { get; set; } + public ASM? Asm { get; set; } /// /// Gets or sets an ID that represents a batch of emails (AKA multiple sends of the same email) to be associated to each other for scheduling. Including a batch_id in your request allows you to include this email in that batch, and also enables you to cancel or pause the delivery of that entire batch. For more information, please read about Cancel Scheduled Sends. /// https://sendgrid.com/docs/API_Reference/Web_API_v3/cancel_schedule_send.html. /// [JsonProperty(PropertyName = "batch_id")] - public string BatchId { get; set; } + public string? BatchId { get; set; } /// /// Gets or sets the IP Pool that you would like to send this email from. /// [JsonProperty(PropertyName = "ip_pool_name")] - public string IpPoolName { get; set; } + public string? IpPoolName { get; set; } /// /// Gets or sets a collection of different mail settings that you can use to specify how you would like this email to be handled. /// [JsonProperty(PropertyName = "mail_settings")] - public MailSettings MailSettings { get; set; } + public MailSettings? MailSettings { get; set; } /// /// Gets or sets settings to determine how you would like to track the metrics of how your recipients interact with your email. /// [JsonProperty(PropertyName = "tracking_settings")] - public TrackingSettings TrackingSettings { get; set; } + public TrackingSettings? TrackingSettings { get; set; } /// /// Gets or sets an email object containing the email address and name of the individual who should receive responses to your email. /// [JsonProperty(PropertyName = "reply_to")] - public EmailAddress ReplyTo { get; set; } + public EmailAddress? ReplyTo { get; set; } /// /// Gets or sets a list of objects of email objects containing the email address and name of the individuals who should receive responses to your email. /// [JsonProperty(PropertyName = "reply_to_list", IsReference = false)] - public List ReplyTos { get; set; } + public List? ReplyTos { get; set; } /// /// Add a recipient email. /// /// Specify the recipient's email. /// Specify the recipient's name. - public void AddTo(string email, string name = null) + public void AddTo(string email, string? name = null) { if (string.IsNullOrWhiteSpace(email)) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); this.AddTo(new EmailAddress(email, name)); } @@ -163,10 +165,10 @@ public void AddTo(string email, string name = null) /// An email recipient that may contain the recipient’s name, but must always contain the recipient’s email. /// Specify the index of the Personalization object where you want to add the recipient email. /// A personalization object to append to the message. - public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalization personalization = null) + public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email == null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddTos(new List { email }, personalizationIndex, personalization); } @@ -177,15 +179,14 @@ public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalizat /// A list of recipients. Each email object within this array may contain the recipient’s name, but must always contain the recipient’s email. /// Specify the index of the Personalization object where you want to add the recipient emails. /// A personalization object to append to the message. - public void AddTos(List emails, int personalizationIndex = 0, Personalization personalization = null) + public void AddTos(List emails, int personalizationIndex = 0, Personalization? personalization = null) { if (emails == null) - throw new ArgumentNullException("emails"); + throw new ArgumentNullException(nameof(emails)); if (emails.Count == 0) throw new InvalidOperationException("Sequence contains no elements"); personalization = GetPersonalization(personalizationIndex, personalization); - personalization.Tos = personalization.Tos ?? new List(); personalization.Tos.AddRange(emails); } @@ -195,10 +196,10 @@ public void AddTos(List emails, int personalizationIndex = 0, Pers /// Specify the recipient's email. /// Specify the recipient's name. /// Thrown when the email parameter is null or whitespace - public void AddCc(string email, string name = null) + public void AddCc(string email, string? name = null) { if (string.IsNullOrWhiteSpace(email)) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); this.AddCc(new EmailAddress(email, name)); } @@ -210,10 +211,10 @@ public void AddCc(string email, string name = null) /// Specify the index of the Personalization object where you want to add the cc email. /// A personalization object to append to the message. /// Thrown when the email parameter is null - public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalization personalization = null) + public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email == null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddCcs(new List { email }, personalizationIndex, personalization); } @@ -226,15 +227,15 @@ public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalizat /// A personalization object to append to the message. /// Thrown when the emails parameter is null /// Thrown when the emails parameter is empty - public void AddCcs(List emails, int personalizationIndex = 0, Personalization personalization = null) + public void AddCcs(List emails, int personalizationIndex = 0, Personalization? personalization = null) { if (emails == null) - throw new ArgumentNullException("emails"); + throw new ArgumentNullException(nameof(emails)); if (emails.Count == 0) throw new InvalidOperationException("Sequence contains no elements"); personalization = GetPersonalization(personalizationIndex, personalization); - personalization.Ccs = personalization.Ccs ?? new List(); + personalization.Ccs ??= new List(); personalization.Ccs.AddRange(emails); } @@ -244,10 +245,10 @@ public void AddCcs(List emails, int personalizationIndex = 0, Pers /// Specify the recipient's email. /// Specify the recipient's name. /// Thrown when the email parameter is null or whitespace - public void AddBcc(string email, string name = null) + public void AddBcc(string email, string? name = null) { if (string.IsNullOrWhiteSpace(email)) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); this.AddBcc(new EmailAddress(email, name)); } @@ -259,10 +260,10 @@ public void AddBcc(string email, string name = null) /// Specify the index of the Personalization object where you want to add the bcc email. /// A personalization object to append to the message. /// Thrown when the email parameter is null - public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personalization personalization = null) + public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email == null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddBccs(new List { email }, personalizationIndex, personalization); } @@ -275,15 +276,15 @@ public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personaliza /// A personalization object to append to the message. /// Thrown when the emails parameter is null /// Thrown when the emails parameter is empty - public void AddBccs(List emails, int personalizationIndex = 0, Personalization personalization = null) + public void AddBccs(List emails, int personalizationIndex = 0, Personalization? personalization = null) { if (emails == null) - throw new ArgumentNullException("emails"); + throw new ArgumentNullException(nameof(emails)); if (emails.Count == 0) throw new InvalidOperationException("Sequence contains no elements"); personalization = GetPersonalization(personalizationIndex, personalization); - personalization.Bccs = personalization.Bccs ?? new List(); + personalization.Bccs ??= new List(); personalization.Bccs.AddRange(emails); } @@ -293,7 +294,7 @@ public void AddBccs(List emails, int personalizationIndex = 0, Per /// The subject line of your email. /// Specify the index of the Personalization object where you want to add the subject. /// A personalization object to append to the message. - public void SetSubject(string subject, int personalizationIndex = 0, Personalization personalization = null) + public void SetSubject(string subject, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.Subject = subject; @@ -306,7 +307,7 @@ public void SetSubject(string subject, int personalizationIndex = 0, Personaliza /// Header value. /// Specify the index of the Personalization object where you want to add the header. /// A personalization object to append to the message. - public void AddHeader(string headerKey, string headerValue, int personalizationIndex = 0, Personalization personalization = null) + public void AddHeader(string headerKey, string headerValue, int personalizationIndex = 0, Personalization? personalization = null) { AddHeaders(new Dictionary { { headerKey, headerValue } }, personalizationIndex, personalization); } @@ -317,7 +318,7 @@ public void AddHeader(string headerKey, string headerValue, int personalizationI /// A list of Headers. /// Specify the index of the Personalization object where you want to add the headers. /// A personalization object to append to the message. - public void AddHeaders(Dictionary headers, int personalizationIndex = 0, Personalization personalization = null) + public void AddHeaders(Dictionary headers, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.Headers = personalization.Headers == null ? headers : @@ -330,7 +331,7 @@ public void AddHeaders(Dictionary headers, int personalizationIn /// Specify the recipient's email. /// Specify the recipient's name. /// Thrown when the email parameter is null or whitespace - public void AddReplyTo(string email, string name = null) + public void AddReplyTo(string email, string? name = null) { if (string.IsNullOrWhiteSpace(email)) throw new ArgumentNullException("email"); @@ -376,7 +377,7 @@ public void AddReplyTos(List emails) /// The substitution value. /// Specify the index of the Personalization object where you want to add the substitution. /// A personalization object to append to the message. - public void AddSubstitution(string substitutionKey, string substitutionValue, int personalizationIndex = 0, Personalization personalization = null) + public void AddSubstitution(string substitutionKey, string substitutionValue, int personalizationIndex = 0, Personalization? personalization = null) { AddSubstitutions(new Dictionary { { substitutionKey, substitutionValue } }, personalizationIndex, personalization); } @@ -387,7 +388,7 @@ public void AddSubstitution(string substitutionKey, string substitutionValue, in /// A list of Substitutions. /// Specify the index of the Personalization object where you want to add the substitutions. /// A personalization object to append to the message. - public void AddSubstitutions(Dictionary substitutions, int personalizationIndex = 0, Personalization personalization = null) + public void AddSubstitutions(Dictionary substitutions, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.Substitutions = personalization.Substitutions == null ? substitutions : @@ -400,7 +401,7 @@ public void AddSubstitutions(Dictionary substitutions, int perso /// A Template Data object. /// Specify the index of the Personalization object where you want to add the substitutions. /// A personalization object to append to the message. - public void SetTemplateData(object dynamicTemplateData, int personalizationIndex = 0, Personalization personalization = null) + public void SetTemplateData(object dynamicTemplateData, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.TemplateData = dynamicTemplateData; @@ -413,7 +414,7 @@ public void SetTemplateData(object dynamicTemplateData, int personalizationIndex /// The custom argument value. /// Specify the index of the Personalization object where you want to add the custom arg. /// A personalization object to append to the message. - public void AddCustomArg(string customArgKey, string customArgValue, int personalizationIndex = 0, Personalization personalization = null) + public void AddCustomArg(string customArgKey, string customArgValue, int personalizationIndex = 0, Personalization? personalization = null) { AddCustomArgs(new Dictionary { { customArgKey, customArgValue } }, personalizationIndex, personalization); } @@ -424,7 +425,7 @@ public void AddCustomArg(string customArgKey, string customArgValue, int persona /// A list of CustomArgs. /// Specify the index of the Personalization object where you want to add the custom args. /// A personalization object to append to the message. - public void AddCustomArgs(Dictionary customArgs, int personalizationIndex = 0, Personalization personalization = null) + public void AddCustomArgs(Dictionary customArgs, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.CustomArgs = personalization.CustomArgs == null ? customArgs : @@ -437,7 +438,7 @@ public void AddCustomArgs(Dictionary customArgs, int personaliza /// Specify the unix timestamp for when you want the email to be sent from Twilio SendGrid. /// Specify the index of the Personalization object where you want to add the send at timestamp. /// A personalization object to append to the message. - public void SetSendAt(long sendAt, int personalizationIndex = 0, Personalization personalization = null) + public void SetSendAt(long sendAt, int personalizationIndex = 0, Personalization? personalization = null) { personalization = GetPersonalization(personalizationIndex, personalization); personalization.SendAt = sendAt; @@ -449,7 +450,7 @@ public void SetSendAt(long sendAt, int personalizationIndex = 0, Personalization /// Specify the index of the Personalization object where you want to add the send at timestamp. /// A personalization object to append to the message. /// The Personalization. - private Personalization GetPersonalization(int personalizationIndex = 0, Personalization personalization = null) + private Personalization GetPersonalization(int personalizationIndex = 0, Personalization? personalization = null) { if (personalization != null) { @@ -481,11 +482,11 @@ private Personalization GetPersonalization(int personalizationIndex = 0, Persona /// /// Specify the recipient's email. /// Specify the recipient's name. - public void SetFrom(string email, string name = null) + public void SetFrom(string email, string? name = null) { if (string.IsNullOrWhiteSpace(email)) { - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); } this.SetFrom(new EmailAddress(email, name)); @@ -575,7 +576,7 @@ public void AddContents(List contents) /// A unique id that you specify for the attachment. This is used when the disposition is set to "inline" and the attachment is an image, allowing the file to be displayed within the body of your email. Ex: ]]>. /// A cancellation token which can notify if the task should be canceled. /// A representing the asynchronous operation. - public async Task AddAttachmentAsync(string filename, Stream contentStream, string type = null, string disposition = null, string content_id = null, CancellationToken cancellationToken = default(CancellationToken)) + public async Task AddAttachmentAsync(string filename, Stream contentStream, string? type = null, string? disposition = null, string? content_id = null, CancellationToken cancellationToken = default) { // Stream doesn't want us to read it, can't do anything else here if (contentStream == null || !contentStream.CanRead) @@ -601,7 +602,7 @@ public void AddContents(List contents) /// The mime type of the content you are attaching. For example, application/pdf or image/jpeg. /// The content-disposition of the attachment specifying how you would like the attachment to be displayed. For example, "inline" results in the attached file being displayed automatically within the message while "attachment" results in the attached file requiring some action to be taken before it is displayed (e.g. opening or downloading the file). Defaults to "attachment". Can be either "attachment" or "inline". /// A unique id that you specify for the attachment. This is used when the disposition is set to "inline" and the attachment is an image, allowing the file to be displayed within the body of your email. Ex: ]]>. - public void AddAttachment(string filename, string base64Content, string type = null, string disposition = null, string content_id = null) + public void AddAttachment(string filename, string base64Content, string? type = null, string? disposition = null, string? content_id = null) { if (string.IsNullOrWhiteSpace(filename) || string.IsNullOrWhiteSpace(base64Content)) { @@ -626,11 +627,7 @@ public void AddAttachment(string filename, string base64Content, string type = n /// An Attachment. public void AddAttachment(Attachment attachment) { - if (this.Attachments == null) - { - this.Attachments = new List(); - } - + this.Attachments ??= new List(); this.Attachments.Add(attachment); } @@ -640,11 +637,7 @@ public void AddAttachment(Attachment attachment) /// A list of Attachments. public void AddAttachments(IEnumerable attachments) { - if (this.Attachments == null) - { - this.Attachments = new List(); - } - + this.Attachments ??= new List(); this.Attachments.AddRange(attachments); } @@ -849,10 +842,12 @@ public void SetBatchId(string batchId) /// An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page. /// https://sendgrid.com/docs/User_Guide/Suppressions/recipient_subscription_preferences.html. /// - public void SetAsm(int groupID, List groupsToDisplay = null) + public void SetAsm(int groupID, List? groupsToDisplay = null) { - this.Asm = new ASM(); - this.Asm.GroupId = groupID; + this.Asm = new ASM + { + GroupId = groupID + }; if (groupsToDisplay != null) { this.Asm.GroupsToDisplay = groupsToDisplay; @@ -878,12 +873,8 @@ public void SetIpPoolName(string ipPoolName) /// The email address that you would like to receive the BCC. public void SetBccSetting(bool enable, string email) { - if (this.MailSettings == null) - { - this.MailSettings = new MailSettings(); - } - - this.MailSettings.BccSettings = new BCCSettings() + this.MailSettings ??= new MailSettings(); + this.MailSettings.BccSettings = new BCCSettings { Enable = enable, Email = email, @@ -898,12 +889,8 @@ public void SetBccSetting(bool enable, string email) /// Gets or sets a value indicating whether this setting is enabled. public void SetBypassListManagement(bool enable) { - if (this.MailSettings == null) - { - this.MailSettings = new MailSettings(); - } - - this.MailSettings.BypassListManagement = new BypassListManagement() + this.MailSettings ??= new MailSettings(); + this.MailSettings.BypassListManagement = new BypassListManagement { Enable = enable, }; @@ -974,14 +961,10 @@ public void SetBypassUnsubscribeManagement(bool enable) /// Gets or sets a value indicating whether this setting is enabled. /// The HTML content of your footer. /// The plain text content of your footer. - public void SetFooterSetting(bool enable, string html = null, string text = null) + public void SetFooterSetting(bool enable, string? html = null, string? text = null) { - if (this.MailSettings == null) - { - this.MailSettings = new MailSettings(); - } - - this.MailSettings.FooterSettings = new FooterSettings() + this.MailSettings ??= new MailSettings(); + this.MailSettings.FooterSettings = new FooterSettings { Enable = enable, Html = html, @@ -997,12 +980,8 @@ public void SetFooterSetting(bool enable, string html = null, string text = null /// Gets or sets a value indicating whether this setting is enabled. public void SetSandBoxMode(bool enable) { - if (this.MailSettings == null) - { - this.MailSettings = new MailSettings(); - } - - this.MailSettings.SandboxMode = new SandboxMode() + this.MailSettings ??= new MailSettings(); + this.MailSettings.SandboxMode = new SandboxMode { Enable = enable, }; @@ -1016,14 +995,10 @@ public void SetSandBoxMode(bool enable) /// Gets or sets a value indicating whether this setting is enabled. /// The threshold used to determine if your content qualifies as spam on a scale from 1 to 10, with 10 being most strict, or most likely to be considered as spam. /// An Inbound Parse URL that you would like a copy of your email along with the spam report to be sent to. The post_to_url parameter must start with http:// or https://. - public void SetSpamCheck(bool enable, int threshold = 1, string postToUrl = null) + public void SetSpamCheck(bool enable, int threshold = 1, string? postToUrl = null) { - if (this.MailSettings == null) - { - this.MailSettings = new MailSettings(); - } - - this.MailSettings.SpamCheck = new SpamCheck() + this.MailSettings ??= new MailSettings(); + this.MailSettings.SpamCheck = new SpamCheck { Enable = enable, Threshold = threshold, @@ -1040,12 +1015,8 @@ public void SetSpamCheck(bool enable, int threshold = 1, string postToUrl = null /// Indicates if this setting should be included in the text/plain portion of your email. public void SetClickTracking(bool enable, bool enableText) { - if (this.TrackingSettings == null) - { - this.TrackingSettings = new TrackingSettings(); - } - - this.TrackingSettings.ClickTracking = new ClickTracking() + this.TrackingSettings ??= new TrackingSettings(); + this.TrackingSettings.ClickTracking = new ClickTracking { Enable = enable, EnableText = enableText, @@ -1059,14 +1030,10 @@ public void SetClickTracking(bool enable, bool enableText) /// /// Gets or sets a value indicating whether this setting is enabled. /// Allows you to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel. - public void SetOpenTracking(bool enable, string substitutionTag = null) + public void SetOpenTracking(bool enable, string? substitutionTag = null) { - if (this.TrackingSettings == null) - { - this.TrackingSettings = new TrackingSettings(); - } - - this.TrackingSettings.OpenTracking = new OpenTracking() + this.TrackingSettings ??= new TrackingSettings(); + this.TrackingSettings.OpenTracking = new OpenTracking { Enable = enable, SubstitutionTag = substitutionTag, @@ -1082,14 +1049,10 @@ public void SetOpenTracking(bool enable, string substitutionTag = null) /// HTML to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag ]]>. /// Text to be appended to the email, with the subscription tracking link. You may control where the link is by using the tag ]]>. /// A tag that will be replaced with the unsubscribe URL. for example: [unsubscribe_url]. If this parameter is used, it will override both the textand html parameters. The URL of the link will be placed at the substitution tag’s location, with no additional formatting. - public void SetSubscriptionTracking(bool enable, string html = null, string text = null, string substitutionTag = null) + public void SetSubscriptionTracking(bool enable, string? html = null, string? text = null, string? substitutionTag = null) { - if (this.TrackingSettings == null) - { - this.TrackingSettings = new TrackingSettings(); - } - - this.TrackingSettings.SubscriptionTracking = new SubscriptionTracking() + this.TrackingSettings ??= new TrackingSettings(); + this.TrackingSettings.SubscriptionTracking = new SubscriptionTracking { Enable = enable, SubstitutionTag = substitutionTag, @@ -1109,14 +1072,10 @@ public void SetSubscriptionTracking(bool enable, string html = null, string text /// Name of the marketing medium (e.g. Email). /// Name of the referrer source (e.g. Google, SomeDomain.com, or Marketing Email). /// Used to identify any paid keywords. - public void SetGoogleAnalytics(bool enable, string utmCampaign = null, string utmContent = null, string utmMedium = null, string utmSource = null, string utmTerm = null) + public void SetGoogleAnalytics(bool enable, string? utmCampaign = null, string? utmContent = null, string? utmMedium = null, string? utmSource = null, string? utmTerm = null) { - if (this.TrackingSettings == null) - { - this.TrackingSettings = new TrackingSettings(); - } - - this.TrackingSettings.Ganalytics = new Ganalytics() + this.TrackingSettings ??= new TrackingSettings(); + this.TrackingSettings.Ganalytics = new Ganalytics { Enable = enable, UtmCampaign = utmCampaign, @@ -1168,16 +1127,14 @@ public string Serialize(bool useDefaultSerialization = true) if (this.Contents[i].Type == MimeType.Html) { - var tempContent = new Content(); - tempContent = this.Contents[i]; + var tempContent = this.Contents[i]; this.Contents.RemoveAt(i); this.Contents.Insert(0, tempContent); } if (this.Contents[i].Type == MimeType.Text) { - var tempContent = new Content(); - tempContent = this.Contents[i]; + var tempContent = this.Contents[i]; this.Contents.RemoveAt(i); this.Contents.Insert(0, tempContent); } diff --git a/src/SendGrid/ISendGridClient.cs b/src/SendGrid/ISendGridClient.cs index f00d7b01d..57c985a68 100644 --- a/src/SendGrid/ISendGridClient.cs +++ b/src/SendGrid/ISendGridClient.cs @@ -25,7 +25,7 @@ public interface ISendGridClient /// /// Gets or sets the API version. /// - string Version { get; set; } + string? Version { get; set; } /// /// Gets or sets the request media type. @@ -45,20 +45,20 @@ public interface ISendGridClient /// The parameters for the API call. /// Cancel the asynchronous call. /// Response object. - Task MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default(CancellationToken)); + Task MakeRequest(HttpRequestMessage request, CancellationToken cancellationToken = default); /// /// Prepare for async call to the API server. /// /// HTTP verb. /// JSON formatted string. - /// JSON formatted query paramaters. + /// JSON formatted query parameters. /// The path to the API endpoint. /// Cancel the asynchronous call. /// Response object. /// The method will NOT catch and swallow exceptions generated by sending a request through the internal http client. Any underlying exception will pass right through. /// In particular, this means that you may expect a TimeoutException if you are not connected to the internet. - Task RequestAsync(SendGridClient.Method method, string requestBody = null, string queryParams = null, string urlPath = null, CancellationToken cancellationToken = default(CancellationToken)); + Task RequestAsync(SendGridClient.Method method, string? requestBody = null, string? queryParams = null, string? urlPath = null, CancellationToken cancellationToken = default); /// /// Make a request to send an email through Twilio SendGrid asynchronously. @@ -66,6 +66,6 @@ public interface ISendGridClient /// A SendGridMessage object with the details for the request. /// Cancel the asynchronous call. /// A Response object. - Task SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default(CancellationToken)); + Task SendEmailAsync(SendGridMessage msg, CancellationToken cancellationToken = default); } } diff --git a/src/SendGrid/Permissions/SendGridClientExtensions.cs b/src/SendGrid/Permissions/SendGridClientExtensions.cs index d86c361ba..e4e0f7fb9 100644 --- a/src/SendGrid/Permissions/SendGridClientExtensions.cs +++ b/src/SendGrid/Permissions/SendGridClientExtensions.cs @@ -21,7 +21,7 @@ public static async Task CreateMaskedPermissionsBuil var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "scopes"); var body = await response.DeserializeResponseBodyAsync(); var userScopesJArray = (body["scopes"] as JArray); - var includedScopes = userScopesJArray.Values().ToArray(); + var includedScopes = userScopesJArray!.Values().ToArray(); var builder = new SendGridPermissionsBuilder(); builder.Exclude(scope => !includedScopes.Contains(scope)); return builder; diff --git a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs index 62d8588e6..61a7e664c 100644 --- a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs +++ b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace SendGrid.Permissions { diff --git a/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs index 4e807920f..abc32beb8 100644 --- a/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs +++ b/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs @@ -9,9 +9,9 @@ /// public sealed partial class SendGridPermissionsBuilder { - private readonly List> excludeFilters; + private readonly List> excludeFilters = new List>(); - private readonly List addedScopes; + private readonly List addedScopes = new List(); private readonly HashSet allScopes; @@ -20,8 +20,6 @@ public sealed partial class SendGridPermissionsBuilder /// public SendGridPermissionsBuilder() { - this.excludeFilters = new List>(); - this.addedScopes = new List(); this.allScopes = new HashSet(this.allPermissions.SelectMany(x => x.Value)); } @@ -82,7 +80,7 @@ public SendGridPermissionsBuilder Include(IEnumerable scopes) /// /// The list of scopes to include. /// The builder instance with the scopes included. - public SendGridPermissionsBuilder Include(params string[] scopes) + public SendGridPermissionsBuilder Include(params string[]? scopes) { if (scopes is null || !scopes.Any()) { @@ -140,6 +138,6 @@ private void ThrowIfViolatesMutualExclusivity(IEnumerable scopes) private bool IsValidScope(string scope) => this.allScopes.Contains(scope); - private bool IsMutualyExclusive(string scope) => scope?.StartsWith("billing") ?? false; + private bool IsMutualyExclusive(string? scope) => scope?.StartsWith("billing") ?? false; } } diff --git a/src/SendGrid/Reliability/ReliabilitySettings.cs b/src/SendGrid/Reliability/ReliabilitySettings.cs index 7a71cbc9c..335783670 100644 --- a/src/SendGrid/Reliability/ReliabilitySettings.cs +++ b/src/SendGrid/Reliability/ReliabilitySettings.cs @@ -26,8 +26,8 @@ public ReliabilitySettings() /// Initializes a new instance of the class. /// /// The maximum number of retries to execute against when sending an HTTP Request before throwing an exception. Max value of 5. Default value of 0. - /// The minimum amount of time to wait between between HTTP retries. Default value of 0 seconds. - /// the maximum amount of time to wait between between HTTP retries. Max value of 30 seconds. Default value of 0 seconds. + /// The minimum amount of time to wait between HTTP retries. Default value of 0 seconds. + /// the maximum amount of time to wait between HTTP retries. Max value of 30 seconds. Default value of 0 seconds. /// the value that will be used to calculate a random delta in the exponential delay between retries. Default value of 0 seconds. public ReliabilitySettings(int maximumNumberOfRetries, TimeSpan minimumBackoff, TimeSpan maximumBackOff, TimeSpan deltaBackOff) { @@ -78,12 +78,12 @@ public ReliabilitySettings(int maximumNumberOfRetries, TimeSpan minimumBackoff, public int MaximumNumberOfRetries { get; } /// - /// Gets the minimum amount of time to wait between between HTTP retries. Defaults to 1 second. + /// Gets the minimum amount of time to wait between HTTP retries. Defaults to 1 second. /// public TimeSpan MinimumBackOff { get; } /// - /// Gets the maximum amount of time to wait between between HTTP retries. Defaults to 10 seconds. + /// Gets the maximum amount of time to wait between HTTP retries. Defaults to 10 seconds. /// public TimeSpan MaximumBackOff { get; } diff --git a/src/SendGrid/Reliability/RetryDelegatingHandler.cs b/src/SendGrid/Reliability/RetryDelegatingHandler.cs index 617663d84..1a412e879 100644 --- a/src/SendGrid/Reliability/RetryDelegatingHandler.cs +++ b/src/SendGrid/Reliability/RetryDelegatingHandler.cs @@ -46,12 +46,12 @@ protected override async Task SendAsync(HttpRequestMessage return await base.SendAsync(request, cancellationToken).ConfigureAwait(false); } - HttpResponseMessage responseMessage = null; + HttpResponseMessage? responseMessage = null; var numberOfAttempts = 0; var sent = false; - while (!sent) + do { var waitFor = this.GetNextWaitInterval(numberOfAttempts); @@ -86,9 +86,9 @@ protected override async Task SendAsync(HttpRequestMessage await TaskUtilities.Delay(waitFor).ConfigureAwait(false); } - } + } while (!sent); - return responseMessage; + return responseMessage!; } private void ThrowHttpRequestExceptionIfResponseCodeCanBeRetried(HttpResponseMessage responseMessage) diff --git a/src/SendGrid/Response.cs b/src/SendGrid/Response.cs index 0eb8255df..1a8807586 100644 --- a/src/SendGrid/Response.cs +++ b/src/SendGrid/Response.cs @@ -18,28 +18,13 @@ namespace SendGrid /// public class Response { - /// - /// The status code returned from Twilio SendGrid. - /// - private HttpStatusCode _statusCode; - - /// - /// The response body returned from Twilio SendGrid. - /// - private HttpContent _body; - - /// - /// The response headers returned from Twilio SendGrid. - /// - private HttpResponseHeaders _headers; - /// /// Initializes a new instance of the class. /// /// https://docs.microsoft.com/dotnet/api/system.net.httpstatuscode. /// https://docs.microsoft.com/dotnet/api/system.net.http.httpcontent. /// https://docs.microsoft.com/dotnet/api/system.net.http.headers.httpresponseheaders. - public Response(HttpStatusCode statusCode, HttpContent responseBody, HttpResponseHeaders responseHeaders) + public Response(HttpStatusCode statusCode, HttpContent? responseBody, HttpResponseHeaders responseHeaders) { this.StatusCode = statusCode; this.Body = responseBody; @@ -49,69 +34,33 @@ public Response(HttpStatusCode statusCode, HttpContent responseBody, HttpRespons /// /// Gets or sets the status code returned from Twilio SendGrid. /// - public HttpStatusCode StatusCode - { - get - { - return this._statusCode; - } - - set - { - this._statusCode = value; - } - } + public HttpStatusCode StatusCode { get; set; } /// /// Gets a value indicating whether Status Code of this response indicates success. /// - public bool IsSuccessStatusCode - { - get { return ((int)StatusCode >= 200) && ((int)StatusCode <= 299); } - } + public bool IsSuccessStatusCode => ((int)StatusCode >= 200) && ((int)StatusCode <= 299); /// /// Gets or sets the response body returned from Twilio SendGrid. /// /// - public HttpContent Body - { - get - { - return this._body; - } - - set - { - this._body = value; - } - } + public HttpContent? Body { get; set; } /// /// Gets or sets the response headers returned from Twilio SendGrid. /// /// - public HttpResponseHeaders Headers - { - get - { - return this._headers; - } - - set - { - this._headers = value; - } - } + public HttpResponseHeaders Headers { get; set; } /// /// Converts string formatted response body to a Dictionary. /// /// https://docs.microsoft.com/dotnet/api/system.net.http.httpcontent. /// Dictionary object representation of HttpContent. - public virtual async Task> DeserializeResponseBodyAsync(HttpContent content = null) + public virtual async Task> DeserializeResponseBodyAsync(HttpContent? content = null) { - content = content ?? this._body; + content ??= Body; if (content is null) { return new Dictionary(); @@ -127,11 +76,11 @@ public virtual async Task> DeserializeResponseBodyAs /// /// https://docs.microsoft.com/dotnet/api/system.net.http.headers.httpresponseheaders. /// Dictionary object representation of HttpResponseHeaders. - public virtual Dictionary DeserializeResponseHeaders(HttpResponseHeaders headers = null) + public virtual Dictionary DeserializeResponseHeaders(HttpResponseHeaders? headers = null) { var dsContent = new Dictionary(); - headers = headers ?? this._headers; + headers ??= Headers; if (headers == null) { return dsContent; diff --git a/src/SendGrid/SendGrid.csproj b/src/SendGrid/SendGrid.csproj index 8157dd52b..9a305c60d 100644 --- a/src/SendGrid/SendGrid.csproj +++ b/src/SendGrid/SendGrid.csproj @@ -11,6 +11,9 @@ true full $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb;.xml + enable + nullable + 8 @@ -45,6 +48,7 @@ + diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index 71d656791..792d4eafe 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -21,7 +21,7 @@ public class SendGridClient : BaseClient /// API version, override AddVersion to customize. /// Path to endpoint (e.g. /path/to/endpoint). /// Interface to the Twilio SendGrid REST API. - public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dictionary requestHeaders = null, string version = null, string urlPath = null, bool httpErrorAsException = false) + public SendGridClient(IWebProxy webProxy, string apiKey, string? host = null, Dictionary? requestHeaders = null, string? version = null, string? urlPath = null, bool httpErrorAsException = false) : base(webProxy, buildOptions(apiKey, host, requestHeaders, version, urlPath)) { } @@ -36,7 +36,7 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string host = null, Dic /// API version, override AddVersion to customize. /// Path to endpoint (e.g. /path/to/endpoint). /// Interface to the Twilio SendGrid REST API. - public SendGridClient(HttpClient httpClient, string apiKey, string host = null, Dictionary requestHeaders = null, string version = null, string urlPath = null, bool httpErrorAsException = false) + public SendGridClient(HttpClient httpClient, string apiKey, string? host = null, Dictionary? requestHeaders = null, string? version = null, string? urlPath = null, bool httpErrorAsException = false) : base(httpClient, buildOptions(apiKey, host, requestHeaders, version, urlPath)) { } @@ -50,7 +50,7 @@ public SendGridClient(HttpClient httpClient, string apiKey, string host = null, /// API version, override AddVersion to customize. /// Path to endpoint (e.g. /path/to/endpoint). /// Interface to the Twilio SendGrid REST API. - public SendGridClient(string apiKey, string host = null, Dictionary requestHeaders = null, string version = null, string urlPath = null) + public SendGridClient(string apiKey, string? host = null, Dictionary? requestHeaders = null, string? version = null, string? urlPath = null) : base(buildOptions(apiKey, host, requestHeaders, version, urlPath)) { } @@ -76,7 +76,7 @@ public SendGridClient(HttpClient httpClient, SendGridClientOptions options) { } - private static SendGridClientOptions buildOptions(string apiKey, string host, Dictionary requestHeaders, string version, string urlPath) + private static SendGridClientOptions buildOptions(string apiKey, string? host, Dictionary? requestHeaders, string? version, string? urlPath) { return new SendGridClientOptions { @@ -84,7 +84,7 @@ private static SendGridClientOptions buildOptions(string apiKey, string host, Di Host = host ?? DefaultOptions.Host, RequestHeaders = requestHeaders ?? DefaultOptions.RequestHeaders, Version = version ?? DefaultOptions.Version, - UrlPath = urlPath ?? DefaultOptions.UrlPath, + UrlPath = urlPath ?? DefaultOptions.UrlPath }; } } diff --git a/src/SendGrid/SendGridClientOptions.cs b/src/SendGrid/SendGridClientOptions.cs index 290f6cfab..f901733e7 100644 --- a/src/SendGrid/SendGridClientOptions.cs +++ b/src/SendGrid/SendGridClientOptions.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Net.Http.Headers; namespace SendGrid @@ -16,12 +17,13 @@ public SendGridClientOptions() Host = "https://api.sendgrid.com"; } - private string apiKey; + private string? apiKey; /// /// The Twilio SendGrid API key. /// - public string ApiKey + [DisallowNull] + public string? ApiKey { get => apiKey; diff --git a/src/SendGrid/TwilioEmailClientOptions.cs b/src/SendGrid/TwilioEmailClientOptions.cs index 960d0f97e..b7837b0ef 100644 --- a/src/SendGrid/TwilioEmailClientOptions.cs +++ b/src/SendGrid/TwilioEmailClientOptions.cs @@ -21,8 +21,7 @@ public TwilioEmailClientOptions() /// Your Twilio Email API key SID or Account SID. /// Your Twilio Email API key secret or Account Auth Token. /// - public TwilioEmailClientOptions(string username, string password) - : this() + public TwilioEmailClientOptions(string username, string password) : this() { if (string.IsNullOrWhiteSpace(username)) { diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index 4ea870598..04475d19f 100644 --- a/tests/SendGrid.Tests/Integration.cs +++ b/tests/SendGrid.Tests/Integration.cs @@ -906,11 +906,11 @@ public void TestAddCcWithoutEmailAddressObject() { var msg = new SendGridMessage(); msg.AddCc("test001@example.com", "Example User"); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); msg = new SendGridMessage(); msg.AddCc("test001@example.com"); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -933,7 +933,7 @@ public void TestAddCc() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.AddCc(new EmailAddress("test001@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -946,7 +946,7 @@ public void TestAddCc() } }; msg.AddCc(new EmailAddress("test003@example.com", "Example User"), 0, personalization); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test002@example.com\"},{\"name\":\"Example User\",\"email\":\"test003@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test002@example.com\"},{\"name\":\"Example User\",\"email\":\"test003@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -968,7 +968,7 @@ public void TestAddCc() } }; msg.AddCc(new EmailAddress("test006@example.com", "Example User"), 1, personalization); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test004@example.com\"}]},{\"cc\":[{\"name\":\"Example User\",\"email\":\"test005@example.com\"},{\"name\":\"Example User\",\"email\":\"test006@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test004@example.com\"}]},{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test005@example.com\"},{\"name\":\"Example User\",\"email\":\"test006@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -982,7 +982,7 @@ public void TestAddCc() } }; msg.AddCc(new EmailAddress("test008@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test007@example.com\"},{\"name\":\"Example User\",\"email\":\"test008@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test007@example.com\"},{\"name\":\"Example User\",\"email\":\"test008@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalizations exists @@ -1006,7 +1006,7 @@ public void TestAddCc() }; msg.Personalizations.Add(personalization); msg.AddCc(new EmailAddress("test011@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test009@example.com\"},{\"name\":\"Example User\",\"email\":\"test011@example.com\"}]},{\"cc\":[{\"name\":\"Example User\",\"email\":\"test010@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test009@example.com\"},{\"name\":\"Example User\",\"email\":\"test011@example.com\"}]},{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test010@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -1020,7 +1020,7 @@ public void TestAddCcs() new EmailAddress("test013@example.com", "Example User") }; msg.AddCcs(emails); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test012@example.com\"},{\"name\":\"Example User\",\"email\":\"test013@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test012@example.com\"},{\"name\":\"Example User\",\"email\":\"test013@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1039,7 +1039,7 @@ public void TestAddCcs() new EmailAddress("test017@example.com", "Example User") }; msg.AddCcs(emails, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test014@example.com\"},{\"name\":\"Example User\",\"email\":\"test015@example.com\"},{\"name\":\"Example User\",\"email\":\"test016@example.com\"},{\"name\":\"Example User\",\"email\":\"test017@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test014@example.com\"},{\"name\":\"Example User\",\"email\":\"test015@example.com\"},{\"name\":\"Example User\",\"email\":\"test016@example.com\"},{\"name\":\"Example User\",\"email\":\"test017@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1068,7 +1068,7 @@ public void TestAddCcs() new EmailAddress("test023@example.com", "Example User") }; msg.AddCcs(emails, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test018@example.com\"},{\"name\":\"Example User\",\"email\":\"test019@example.com\"}]},{\"cc\":[{\"name\":\"Example User\",\"email\":\"test020@example.com\"},{\"name\":\"Example User\",\"email\":\"test021@example.com\"},{\"name\":\"Example User\",\"email\":\"test022@example.com\"},{\"name\":\"Example User\",\"email\":\"test023@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test018@example.com\"},{\"name\":\"Example User\",\"email\":\"test019@example.com\"}]},{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test020@example.com\"},{\"name\":\"Example User\",\"email\":\"test021@example.com\"},{\"name\":\"Example User\",\"email\":\"test022@example.com\"},{\"name\":\"Example User\",\"email\":\"test023@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1088,7 +1088,7 @@ public void TestAddCcs() new EmailAddress("test027@example.com", "Example User") }; msg.AddCcs(emails); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test024@example.com\"},{\"name\":\"Example User\",\"email\":\"test025@example.com\"},{\"name\":\"Example User\",\"email\":\"test026@example.com\"},{\"name\":\"Example User\",\"email\":\"test027@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test024@example.com\"},{\"name\":\"Example User\",\"email\":\"test025@example.com\"},{\"name\":\"Example User\",\"email\":\"test026@example.com\"},{\"name\":\"Example User\",\"email\":\"test027@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1118,7 +1118,7 @@ public void TestAddCcs() new EmailAddress("test033@example.com", "Example User") }; msg.AddCcs(emails); - Assert.Equal("{\"personalizations\":[{\"cc\":[{\"name\":\"Example User\",\"email\":\"test028@example.com\"},{\"name\":\"Example User\",\"email\":\"test029@example.com\"},{\"name\":\"Example User\",\"email\":\"test032@example.com\"},{\"name\":\"Example User\",\"email\":\"test033@example.com\"}]},{\"cc\":[{\"name\":\"Example User\",\"email\":\"test030@example.com\"},{\"name\":\"Example User\",\"email\":\"test031@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test028@example.com\"},{\"name\":\"Example User\",\"email\":\"test029@example.com\"},{\"name\":\"Example User\",\"email\":\"test032@example.com\"},{\"name\":\"Example User\",\"email\":\"test033@example.com\"}]},{\"to\":[],\"cc\":[{\"name\":\"Example User\",\"email\":\"test030@example.com\"},{\"name\":\"Example User\",\"email\":\"test031@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -1127,7 +1127,7 @@ public void TestAddBcc() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.AddBcc(new EmailAddress("test001@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1140,7 +1140,7 @@ public void TestAddBcc() } }; msg.AddBcc(new EmailAddress("test003@example.com", "Example User"), 0, personalization); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test002@example.com\"},{\"name\":\"Example User\",\"email\":\"test003@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test002@example.com\"},{\"name\":\"Example User\",\"email\":\"test003@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1162,7 +1162,7 @@ public void TestAddBcc() } }; msg.AddBcc(new EmailAddress("test006@example.com", "Example User"), 1, personalization); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test004@example.com\"}]},{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test005@example.com\"},{\"name\":\"Example User\",\"email\":\"test006@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test004@example.com\"}]},{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test005@example.com\"},{\"name\":\"Example User\",\"email\":\"test006@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1176,7 +1176,7 @@ public void TestAddBcc() } }; msg.AddBcc(new EmailAddress("test008@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test007@example.com\"},{\"name\":\"Example User\",\"email\":\"test008@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test007@example.com\"},{\"name\":\"Example User\",\"email\":\"test008@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalizations exists @@ -1200,7 +1200,7 @@ public void TestAddBcc() }; msg.Personalizations.Add(personalization); msg.AddBcc(new EmailAddress("test011@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test009@example.com\"},{\"name\":\"Example User\",\"email\":\"test011@example.com\"}]},{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test010@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test009@example.com\"},{\"name\":\"Example User\",\"email\":\"test011@example.com\"}]},{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test010@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -1208,11 +1208,11 @@ public void TestAddBccWithOutEmailAddressObject() { var msg = new SendGridMessage(); msg.AddBcc("test001@example.com", "Example User"); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); msg = new SendGridMessage(); msg.AddBcc("test001@example.com"); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"email\":\"test001@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -1240,7 +1240,7 @@ public void TestAddBccs() new EmailAddress("test013@example.com", "Example User") }; msg.AddBccs(emails); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test012@example.com\"},{\"name\":\"Example User\",\"email\":\"test013@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test012@example.com\"},{\"name\":\"Example User\",\"email\":\"test013@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1259,7 +1259,7 @@ public void TestAddBccs() new EmailAddress("test017@example.com", "Example User") }; msg.AddBccs(emails, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test014@example.com\"},{\"name\":\"Example User\",\"email\":\"test015@example.com\"},{\"name\":\"Example User\",\"email\":\"test016@example.com\"},{\"name\":\"Example User\",\"email\":\"test017@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test014@example.com\"},{\"name\":\"Example User\",\"email\":\"test015@example.com\"},{\"name\":\"Example User\",\"email\":\"test016@example.com\"},{\"name\":\"Example User\",\"email\":\"test017@example.com\"}]}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1288,7 +1288,7 @@ public void TestAddBccs() new EmailAddress("test023@example.com", "Example User") }; msg.AddBccs(emails, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test018@example.com\"},{\"name\":\"Example User\",\"email\":\"test019@example.com\"}]},{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test020@example.com\"},{\"name\":\"Example User\",\"email\":\"test021@example.com\"},{\"name\":\"Example User\",\"email\":\"test022@example.com\"},{\"name\":\"Example User\",\"email\":\"test023@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test018@example.com\"},{\"name\":\"Example User\",\"email\":\"test019@example.com\"}]},{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test020@example.com\"},{\"name\":\"Example User\",\"email\":\"test021@example.com\"},{\"name\":\"Example User\",\"email\":\"test022@example.com\"},{\"name\":\"Example User\",\"email\":\"test023@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1308,7 +1308,7 @@ public void TestAddBccs() new EmailAddress("test027@example.com", "Example User") }; msg.AddBccs(emails); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test024@example.com\"},{\"name\":\"Example User\",\"email\":\"test025@example.com\"},{\"name\":\"Example User\",\"email\":\"test026@example.com\"},{\"name\":\"Example User\",\"email\":\"test027@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test024@example.com\"},{\"name\":\"Example User\",\"email\":\"test025@example.com\"},{\"name\":\"Example User\",\"email\":\"test026@example.com\"},{\"name\":\"Example User\",\"email\":\"test027@example.com\"}]}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1338,7 +1338,7 @@ public void TestAddBccs() new EmailAddress("test033@example.com", "Example User") }; msg.AddBccs(emails); - Assert.Equal("{\"personalizations\":[{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test028@example.com\"},{\"name\":\"Example User\",\"email\":\"test029@example.com\"},{\"name\":\"Example User\",\"email\":\"test032@example.com\"},{\"name\":\"Example User\",\"email\":\"test033@example.com\"}]},{\"bcc\":[{\"name\":\"Example User\",\"email\":\"test030@example.com\"},{\"name\":\"Example User\",\"email\":\"test031@example.com\"}]}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test028@example.com\"},{\"name\":\"Example User\",\"email\":\"test029@example.com\"},{\"name\":\"Example User\",\"email\":\"test032@example.com\"},{\"name\":\"Example User\",\"email\":\"test033@example.com\"}]},{\"to\":[],\"bcc\":[{\"name\":\"Example User\",\"email\":\"test030@example.com\"},{\"name\":\"Example User\",\"email\":\"test031@example.com\"}]}]}", msg.Serialize()); } [Fact] @@ -1362,7 +1362,7 @@ public void TestSetSubject() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.SetSubject("subject1"); - Assert.Equal("{\"personalizations\":[{\"subject\":\"subject1\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject1\"}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1372,7 +1372,7 @@ public void TestSetSubject() Subject = subject }; msg.SetSubject("subject3", 0, personalization); - Assert.Equal("{\"personalizations\":[{\"subject\":\"subject3\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject3\"}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1388,7 +1388,7 @@ public void TestSetSubject() Subject = subject }; msg.SetSubject("subject6", 1, personalization); - Assert.Equal("{\"personalizations\":[{\"subject\":\"subject4\"},{\"subject\":\"subject6\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject4\"},{\"to\":[],\"subject\":\"subject6\"}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1399,7 +1399,7 @@ public void TestSetSubject() } }; msg.SetSubject("subject8"); - Assert.Equal("{\"personalizations\":[{\"subject\":\"subject8\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject8\"}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1416,7 +1416,7 @@ public void TestSetSubject() }; msg.Personalizations.Add(personalization); msg.SetSubject("subject11"); - Assert.Equal("{\"personalizations\":[{\"subject\":\"subject11\"},{\"subject\":\"subject10\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject11\"},{\"to\":[],\"subject\":\"subject10\"}]}", msg.Serialize()); } [Fact] @@ -1425,7 +1425,7 @@ public void TestAddHeader() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.AddHeader("X-Test", "Test Value"); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test\":\"Test Value\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test\":\"Test Value\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1437,7 +1437,7 @@ public void TestAddHeader() } }; msg.AddHeader("X-Test2", "Test Value 2", 0, personalization); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test\":\"Test Value\",\"X-Test2\":\"Test Value 2\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test\":\"Test Value\",\"X-Test2\":\"Test Value 2\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage @@ -1461,7 +1461,7 @@ public void TestAddHeader() } }; msg.AddHeader("X-Test5", "Test Value 5", 1, personalization); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test3\":\"Test Value 3\"}},{\"headers\":{\"X-Test4\":\"Test Value 4\",\"X-Test5\":\"Test Value 5\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test3\":\"Test Value 3\"}},{\"to\":[],\"headers\":{\"X-Test4\":\"Test Value 4\",\"X-Test5\":\"Test Value 5\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage @@ -1478,7 +1478,7 @@ public void TestAddHeader() } }; msg.AddHeader("X-Test7", "Test Value 7"); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test6\":\"Test Value 6\",\"X-Test7\":\"Test Value 7\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test6\":\"Test Value 6\",\"X-Test7\":\"Test Value 7\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage @@ -1503,7 +1503,7 @@ public void TestAddHeader() }; msg.Personalizations.Add(personalization); msg.AddHeader("X-Test10", "Test Value 10"); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test8\":\"Test Value 8\",\"X-Test10\":\"Test Value 10\"}},{\"headers\":{\"X-Test9\":\"Test Value 9\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test8\":\"Test Value 8\",\"X-Test10\":\"Test Value 10\"}},{\"to\":[],\"headers\":{\"X-Test9\":\"Test Value 9\"}}]}", msg.Serialize()); } [Fact] @@ -1513,7 +1513,7 @@ public void TestAddHeaders() var msg = new SendGridMessage(); var headers = new Dictionary { { "X-Test1", "Test Value 1" }, { "X-Test2", "Test Value 2" } }; msg.AddHeaders(headers); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test1\":\"Test Value 1\",\"X-Test2\":\"Test Value 2\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test1\":\"Test Value 1\",\"X-Test2\":\"Test Value 2\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1524,7 +1524,7 @@ public void TestAddHeaders() }; headers = new Dictionary { { "X-Test5", "Test Value 5" }, { "X-Test6", "Test Value 6" } }; msg.AddHeaders(headers, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test3\":\"Test Value 3\",\"X-Test4\":\"Test Value 4\",\"X-Test5\":\"Test Value 5\",\"X-Test6\":\"Test Value 6\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test3\":\"Test Value 3\",\"X-Test4\":\"Test Value 4\",\"X-Test5\":\"Test Value 5\",\"X-Test6\":\"Test Value 6\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1541,7 +1541,7 @@ public void TestAddHeaders() }; headers = new Dictionary { { "X-Test11", "Test Value 11" }, { "X-Test12", "Test Value 12" } }; msg.AddHeaders(headers, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test7\":\"Test Value 7\",\"X-Test8\":\"Test Value 8\"}},{\"headers\":{\"X-Test9\":\"Test Value 9\",\"X-Test10\":\"Test Value 10\",\"X-Test11\":\"Test Value 11\",\"X-Test12\":\"Test Value 12\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test7\":\"Test Value 7\",\"X-Test8\":\"Test Value 8\"}},{\"to\":[],\"headers\":{\"X-Test9\":\"Test Value 9\",\"X-Test10\":\"Test Value 10\",\"X-Test11\":\"Test Value 11\",\"X-Test12\":\"Test Value 12\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1553,7 +1553,7 @@ public void TestAddHeaders() }; headers = new Dictionary { { "X-Test15", "Test Value 15" }, { "X-Test16", "Test Value 16" } }; msg.AddHeaders(headers); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test13\":\"Test Value 13\",\"X-Test14\":\"Test Value 14\",\"X-Test15\":\"Test Value 15\",\"X-Test16\":\"Test Value 16\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test13\":\"Test Value 13\",\"X-Test14\":\"Test Value 14\",\"X-Test15\":\"Test Value 15\",\"X-Test16\":\"Test Value 16\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1571,7 +1571,7 @@ public void TestAddHeaders() msg.Personalizations.Add(personalization); headers = new Dictionary { { "X-Test21", "Test Value 21" }, { "X-Test22", "Test Value 22" } }; msg.AddHeaders(headers); - Assert.Equal("{\"personalizations\":[{\"headers\":{\"X-Test17\":\"Test Value 17\",\"X-Test18\":\"Test Value 18\",\"X-Test21\":\"Test Value 21\",\"X-Test22\":\"Test Value 22\"}},{\"headers\":{\"X-Test19\":\"Test Value 19\",\"X-Test20\":\"Test Value 20\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"headers\":{\"X-Test17\":\"Test Value 17\",\"X-Test18\":\"Test Value 18\",\"X-Test21\":\"Test Value 21\",\"X-Test22\":\"Test Value 22\"}},{\"to\":[],\"headers\":{\"X-Test19\":\"Test Value 19\",\"X-Test20\":\"Test Value 20\"}}]}", msg.Serialize()); } [Fact] @@ -1580,7 +1580,7 @@ public void TestAddSubstitution() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.AddSubstitution("-sub1-", "Substituted Value 1"); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub1-\":\"Substituted Value 1\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub1-\":\"Substituted Value 1\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1592,7 +1592,7 @@ public void TestAddSubstitution() } }; msg.AddSubstitution("-sub3-", "Substituted Value 3", 0, personalization); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub2-\":\"Substituted Value 2\",\"-sub3-\":\"Substituted Value 3\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub2-\":\"Substituted Value 2\",\"-sub3-\":\"Substituted Value 3\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage @@ -1616,7 +1616,7 @@ public void TestAddSubstitution() } }; msg.AddSubstitution("-sub6-", "Substituted Value 6", 1, personalization); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub4-\":\"Substituted Value 4\"}},{\"substitutions\":{\"-sub5-\":\"Substituted Value 5\",\"-sub6-\":\"Substituted Value 6\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub4-\":\"Substituted Value 4\"}},{\"to\":[],\"substitutions\":{\"-sub5-\":\"Substituted Value 5\",\"-sub6-\":\"Substituted Value 6\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage @@ -1633,7 +1633,7 @@ public void TestAddSubstitution() } }; msg.AddSubstitution("-sub8-", "Substituted Value 8"); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub7-\":\"Substituted Value 7\",\"-sub8-\":\"Substituted Value 8\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub7-\":\"Substituted Value 7\",\"-sub8-\":\"Substituted Value 8\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage @@ -1658,7 +1658,7 @@ public void TestAddSubstitution() }; msg.Personalizations.Add(personalization); msg.AddSubstitution("-sub11-", "Substituted Value 11"); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub9-\":\"Substituted Value 9\",\"-sub11-\":\"Substituted Value 11\"}},{\"substitutions\":{\"-sub10-\":\"Substituted Value 10\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub9-\":\"Substituted Value 9\",\"-sub11-\":\"Substituted Value 11\"}},{\"to\":[],\"substitutions\":{\"-sub10-\":\"Substituted Value 10\"}}]}", msg.Serialize()); } [Fact] @@ -1672,7 +1672,7 @@ public void TestAddSubstitutions() {"-sub13-", "Substituted Value 13"} }; msg.AddSubstitutions(substitutions); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub12-\":\"Substituted Value 12\",\"-sub13-\":\"Substituted Value 13\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub12-\":\"Substituted Value 12\",\"-sub13-\":\"Substituted Value 13\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1691,7 +1691,7 @@ public void TestAddSubstitutions() {"-sub17-", "Substituted Value 17"} }; msg.AddSubstitutions(substitutions, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub14-\":\"Substituted Value 14\",\"-sub15-\":\"Substituted Value 15\",\"-sub16-\":\"Substituted Value 16\",\"-sub17-\":\"Substituted Value 17\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub14-\":\"Substituted Value 14\",\"-sub15-\":\"Substituted Value 15\",\"-sub16-\":\"Substituted Value 16\",\"-sub17-\":\"Substituted Value 17\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1720,7 +1720,7 @@ public void TestAddSubstitutions() {"-sub23-", "Substituted Value 23"} }; msg.AddSubstitutions(substitutions, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub18-\":\"Substituted Value 18\",\"-sub19-\":\"Substituted Value 19\"}},{\"substitutions\":{\"-sub20-\":\"Substituted Value 20\",\"-sub21-\":\"Substituted Value 21\",\"-sub22-\":\"Substituted Value 22\",\"-sub23-\":\"Substituted Value 23\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub18-\":\"Substituted Value 18\",\"-sub19-\":\"Substituted Value 19\"}},{\"to\":[],\"substitutions\":{\"-sub20-\":\"Substituted Value 20\",\"-sub21-\":\"Substituted Value 21\",\"-sub22-\":\"Substituted Value 22\",\"-sub23-\":\"Substituted Value 23\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1740,7 +1740,7 @@ public void TestAddSubstitutions() {"-sub27-", "Substituted Value 27"} }; msg.AddSubstitutions(substitutions); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub24-\":\"Substituted Value 24\",\"-sub25-\":\"Substituted Value 25\",\"-sub26-\":\"Substituted Value 26\",\"-sub27-\":\"Substituted Value 27\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub24-\":\"Substituted Value 24\",\"-sub25-\":\"Substituted Value 25\",\"-sub26-\":\"Substituted Value 26\",\"-sub27-\":\"Substituted Value 27\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1770,7 +1770,7 @@ public void TestAddSubstitutions() {"-sub33-", "Substituted Value 33"} }; msg.AddSubstitutions(substitutions); - Assert.Equal("{\"personalizations\":[{\"substitutions\":{\"-sub28-\":\"Substituted Value 28\",\"-sub29-\":\"Substituted Value 29\",\"-sub32-\":\"Substituted Value 32\",\"-sub33-\":\"Substituted Value 33\"}},{\"substitutions\":{\"-sub30-\":\"Substituted Value 30\",\"-sub31-\":\"Substituted Value 31\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"substitutions\":{\"-sub28-\":\"Substituted Value 28\",\"-sub29-\":\"Substituted Value 29\",\"-sub32-\":\"Substituted Value 32\",\"-sub33-\":\"Substituted Value 33\"}},{\"to\":[],\"substitutions\":{\"-sub30-\":\"Substituted Value 30\",\"-sub31-\":\"Substituted Value 31\"}}]}", msg.Serialize()); } [Fact] @@ -1784,7 +1784,7 @@ public void TestSetTemplateData() key13 = "Dynamic Template Data Value 13" }; msg.SetTemplateData(dynamicTemplateData1); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"key12\":\"Dynamic Template Data Value 12\",\"key13\":\"Dynamic Template Data Value 13\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"key12\":\"Dynamic Template Data Value 12\",\"key13\":\"Dynamic Template Data Value 13\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1803,7 +1803,7 @@ public void TestSetTemplateData() key17 = "Dynamic Template Data Value 17" }; msg.SetTemplateData(dynamicTemplateData3, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"key16\":\"Dynamic Template Data Value 16\",\"key17\":\"Dynamic Template Data Value 17\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"key16\":\"Dynamic Template Data Value 16\",\"key17\":\"Dynamic Template Data Value 17\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -1832,7 +1832,7 @@ public void TestSetTemplateData() key23 = "Dynamic Template Data Value 23" }; msg.SetTemplateData(dynamicTemplateData6, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"key18\":\"Dynamic Template Data Value 18\",\"key19\":\"Dynamic Template Data Value 19\"}},{\"dynamic_template_data\":{\"key22\":\"Dynamic Template Data Value 22\",\"key23\":\"Dynamic Template Data Value 23\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"key18\":\"Dynamic Template Data Value 18\",\"key19\":\"Dynamic Template Data Value 19\"}},{\"to\":[],\"dynamic_template_data\":{\"key22\":\"Dynamic Template Data Value 22\",\"key23\":\"Dynamic Template Data Value 23\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -1852,7 +1852,7 @@ public void TestSetTemplateData() key27 = "Dynamic Template Data Value 27" }; msg.SetTemplateData(dynamicTemplateData8); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"key26\":\"Dynamic Template Data Value 26\",\"key27\":\"Dynamic Template Data Value 27\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"key26\":\"Dynamic Template Data Value 26\",\"key27\":\"Dynamic Template Data Value 27\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -1882,7 +1882,7 @@ public void TestSetTemplateData() key33 = "Dynamic Template Data Value 33" }; msg.SetTemplateData(dynamicTemplateData11); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"key32\":\"Dynamic Template Data Value 32\",\"key33\":\"Dynamic Template Data Value 33\"}},{\"dynamic_template_data\":{\"key30\":\"Dynamic Template Data Value 30\",\"key31\":\"Dynamic Template Data Value 31\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"key32\":\"Dynamic Template Data Value 32\",\"key33\":\"Dynamic Template Data Value 33\"}},{\"to\":[],\"dynamic_template_data\":{\"key30\":\"Dynamic Template Data Value 30\",\"key31\":\"Dynamic Template Data Value 31\"}}]}", msg.Serialize()); // Complex dynamic template data msg = new SendGridMessage(); @@ -1899,7 +1899,7 @@ public void TestSetTemplateData() } }; msg.SetTemplateData(dynamicTemplateData12); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"array\":[\"Dynamic Template Data Array Value 1\",\"Dynamic Template Data Array Value 2\"],\"innerObject\":{\"innerObjectKey1\":\"Dynamic Template Data Deep Object Value 1\"}}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"array\":[\"Dynamic Template Data Array Value 1\",\"Dynamic Template Data Array Value 2\"],\"innerObject\":{\"innerObjectKey1\":\"Dynamic Template Data Deep Object Value 1\"}}}]}", msg.Serialize()); } [Fact] @@ -1908,7 +1908,7 @@ public void TestAddCustomArg() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.AddCustomArg("arg1", "Arguement Value 1"); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg1\":\"Arguement Value 1\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg1\":\"Arguement Value 1\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -1920,7 +1920,7 @@ public void TestAddCustomArg() } }; msg.AddCustomArg("arg3", "Arguement Value 3", 0, personalization); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg2\":\"Arguement Value 2\",\"arg3\":\"Arguement Value 3\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg2\":\"Arguement Value 2\",\"arg3\":\"Arguement Value 3\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage @@ -1944,7 +1944,7 @@ public void TestAddCustomArg() } }; msg.AddCustomArg("arg6", "Arguement Value 6", 1, personalization); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg4\":\"Arguement Value 4\"}},{\"custom_args\":{\"arg5\":\"Arguement Value 5\",\"arg6\":\"Arguement Value 6\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg4\":\"Arguement Value 4\"}},{\"to\":[],\"custom_args\":{\"arg5\":\"Arguement Value 5\",\"arg6\":\"Arguement Value 6\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage @@ -1961,7 +1961,7 @@ public void TestAddCustomArg() } }; msg.AddCustomArg("arg8", "Arguement Value 8"); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg7\":\"Arguement Value 7\",\"arg8\":\"Arguement Value 8\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg7\":\"Arguement Value 7\",\"arg8\":\"Arguement Value 8\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage @@ -1986,7 +1986,7 @@ public void TestAddCustomArg() }; msg.Personalizations.Add(personalization); msg.AddCustomArg("arg11", "Arguement Value 11"); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg9\":\"Arguement Value 9\",\"arg11\":\"Arguement Value 11\"}},{\"custom_args\":{\"arg10\":\"Arguement Value 10\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg9\":\"Arguement Value 9\",\"arg11\":\"Arguement Value 11\"}},{\"to\":[],\"custom_args\":{\"arg10\":\"Arguement Value 10\"}}]}", msg.Serialize()); } [Fact] @@ -2000,7 +2000,7 @@ public void TestAddCustomArgs() {"arg13", "Arguement Value 13"} }; msg.AddCustomArgs(customArgs); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg12\":\"Arguement Value 12\",\"arg13\":\"Arguement Value 13\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg12\":\"Arguement Value 12\",\"arg13\":\"Arguement Value 13\"}}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -2019,7 +2019,7 @@ public void TestAddCustomArgs() {"arg17", "Arguement Value 17"} }; msg.AddCustomArgs(customArgs, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg14\":\"Arguement Value 14\",\"arg15\":\"Arguement Value 15\",\"arg16\":\"Arguement Value 16\",\"arg17\":\"Arguement Value 17\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg14\":\"Arguement Value 14\",\"arg15\":\"Arguement Value 15\",\"arg16\":\"Arguement Value 16\",\"arg17\":\"Arguement Value 17\"}}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -2048,7 +2048,7 @@ public void TestAddCustomArgs() {"arg23", "Arguement Value 23"} }; msg.AddCustomArgs(customArgs, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg18\":\"Arguement Value 18\",\"arg19\":\"Arguement Value 19\"}},{\"custom_args\":{\"arg20\":\"Arguement Value 20\",\"arg21\":\"Arguement Value 21\",\"arg22\":\"Arguement Value 22\",\"arg23\":\"Arguement Value 23\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg18\":\"Arguement Value 18\",\"arg19\":\"Arguement Value 19\"}},{\"to\":[],\"custom_args\":{\"arg20\":\"Arguement Value 20\",\"arg21\":\"Arguement Value 21\",\"arg22\":\"Arguement Value 22\",\"arg23\":\"Arguement Value 23\"}}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -2068,7 +2068,7 @@ public void TestAddCustomArgs() {"arg27", "Arguement Value 27"} }; msg.AddCustomArgs(customArgs); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg24\":\"Arguement Value 24\",\"arg25\":\"Arguement Value 25\",\"arg26\":\"Arguement Value 26\",\"arg27\":\"Arguement Value 27\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg24\":\"Arguement Value 24\",\"arg25\":\"Arguement Value 25\",\"arg26\":\"Arguement Value 26\",\"arg27\":\"Arguement Value 27\"}}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -2098,7 +2098,7 @@ public void TestAddCustomArgs() {"arg33", "Arguement Value 33"} }; msg.AddCustomArgs(customArgs); - Assert.Equal("{\"personalizations\":[{\"custom_args\":{\"arg28\":\"Arguement Value 28\",\"arg29\":\"Arguement Value 29\",\"arg32\":\"Arguement Value 32\",\"arg33\":\"Arguement Value 33\"}},{\"custom_args\":{\"arg30\":\"Arguement Value 30\",\"arg31\":\"Arguement Value 31\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"custom_args\":{\"arg28\":\"Arguement Value 28\",\"arg29\":\"Arguement Value 29\",\"arg32\":\"Arguement Value 32\",\"arg33\":\"Arguement Value 33\"}},{\"to\":[],\"custom_args\":{\"arg30\":\"Arguement Value 30\",\"arg31\":\"Arguement Value 31\"}}]}", msg.Serialize()); } [Fact] @@ -2107,7 +2107,7 @@ public void TestSendAt() // Personalization not passed in, Personalization does not exist var msg = new SendGridMessage(); msg.SetSendAt(1409348513); - Assert.Equal("{\"personalizations\":[{\"send_at\":1409348513}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"send_at\":1409348513}]}", msg.Serialize()); // Personalization passed in, no Personalizations msg = new SendGridMessage(); @@ -2117,7 +2117,7 @@ public void TestSendAt() SendAt = sendAt }; msg.SetSendAt(1409348513, 0, personalization); - Assert.Equal("{\"personalizations\":[{\"send_at\":1409348513}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"send_at\":1409348513}]}", msg.Serialize()); // Personalization passed in, Personalization exists msg = new SendGridMessage(); @@ -2133,7 +2133,7 @@ public void TestSendAt() SendAt = sendAt }; msg.SetSendAt(1409348513, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"send_at\":1409348513},{\"send_at\":1409348513}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"send_at\":1409348513},{\"to\":[],\"send_at\":1409348513}]}", msg.Serialize()); // Personalization not passed in Personalization exists msg = new SendGridMessage(); @@ -2144,7 +2144,7 @@ public void TestSendAt() } }; msg.SetSendAt(1409348513); - Assert.Equal("{\"personalizations\":[{\"send_at\":1409348513}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"send_at\":1409348513}]}", msg.Serialize()); // Personalization not passed in Personalizations exists msg = new SendGridMessage(); @@ -2161,7 +2161,7 @@ public void TestSendAt() }; msg.Personalizations.Add(personalization); msg.SetSendAt(1409348513); - Assert.Equal("{\"personalizations\":[{\"send_at\":1409348513},{\"send_at\":1409348513}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"send_at\":1409348513},{\"to\":[],\"send_at\":1409348513}]}", msg.Serialize()); } [Fact] diff --git a/tests/SendGrid.Tests/TemplateDataSerialisationTests.cs b/tests/SendGrid.Tests/TemplateDataSerialisationTests.cs index 83137c4d1..4684dd2a3 100644 --- a/tests/SendGrid.Tests/TemplateDataSerialisationTests.cs +++ b/tests/SendGrid.Tests/TemplateDataSerialisationTests.cs @@ -20,7 +20,7 @@ public void TestSetTemplateDataWorksWithSpecifiedJsonPropertyNames() }; msg.SetTemplateData(dynamicTemplateData); - Assert.Equal("{\"personalizations\":[{\"dynamic_template_data\":{\"myCamelCaseProperty\":\"camelCase\",\"my-kebab-case-property\":\"kebab-case\",\"MyPascalCaseProperty\":\"PascalCase\",\"my_snake_case_property\":\"snake_case\"}}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"dynamic_template_data\":{\"myCamelCaseProperty\":\"camelCase\",\"my-kebab-case-property\":\"kebab-case\",\"MyPascalCaseProperty\":\"PascalCase\",\"my_snake_case_property\":\"snake_case\"}}]}", msg.Serialize()); } private class TestTemplateData