From a4590a3194c72ed79b12a3c3a0af9d47763a9b32 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 29 Nov 2021 14:52:00 +0200 Subject: [PATCH 01/22] First batch of fixes --- .../InjectableSendGridClient.cs | 2 +- ...Grid.Extensions.DependencyInjection.csproj | 3 + src/SendGrid/BaseClient.cs | 27 ++- src/SendGrid/BaseClientOptions.cs | 4 +- src/SendGrid/Helpers/Errors/ErrorHandler.cs | 8 +- .../Errors/Model/SendGridErrorResponse.cs | 8 +- src/SendGrid/Helpers/Mail/MailHelper.cs | 84 ++++----- src/SendGrid/Helpers/Mail/Model/Attachment.cs | 6 +- .../Helpers/Mail/Model/EmailAddress.cs | 8 +- .../Helpers/Mail/Model/FooterSettings.cs | 4 +- src/SendGrid/Helpers/Mail/Model/Ganalytics.cs | 10 +- .../Helpers/Mail/Model/OpenTracking.cs | 2 +- src/SendGrid/Helpers/Mail/Model/SpamCheck.cs | 2 +- .../Mail/Model/SubscriptionTracking.cs | 6 +- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 161 +++++++----------- src/SendGrid/ISendGridClient.cs | 4 +- .../Permissions/SendGridClientExtensions.cs | 4 +- .../Reliability/RetryDelegatingHandler.cs | 23 ++- src/SendGrid/Response.cs | 61 +------ src/SendGrid/SendGrid.csproj | 4 + src/SendGrid/SendGridClient.cs | 15 +- src/SendGrid/SendGridClientOptions.cs | 6 +- 22 files changed, 183 insertions(+), 269 deletions(-) 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..6cb1babb2 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 + latest diff --git a/src/SendGrid/BaseClient.cs b/src/SendGrid/BaseClient.cs index 3e2a351d6..9a0a1a071 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)); @@ -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 @@ -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..43e29077f 100644 --- a/src/SendGrid/BaseClientOptions.cs +++ b/src/SendGrid/BaseClientOptions.cs @@ -10,7 +10,7 @@ namespace SendGrid /// public class BaseClientOptions { - private ReliabilitySettings reliabilitySettings = new ReliabilitySettings(); + private ReliabilitySettings reliabilitySettings = new(); /// /// The reliability settings to use on HTTP Requests. @@ -24,7 +24,7 @@ public ReliabilitySettings ReliabilitySettings /// /// The request headers to use on HTTP Requests. /// - public Dictionary RequestHeaders { get; set; } = new Dictionary(); + public Dictionary RequestHeaders { get; set; } = new(); /// /// The base URL. diff --git a/src/SendGrid/Helpers/Errors/ErrorHandler.cs b/src/SendGrid/Helpers/Errors/ErrorHandler.cs index bb1204681..dfde4f7af 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) { @@ -139,7 +139,7 @@ private static async Task GetErrorMessage(HttpResponseMessage message) } } - SendGridErrorResponse errorResponse = new SendGridErrorResponse + SendGridErrorResponse errorResponse = new() { ErrorHttpStatusCode = errorStatusCode, ErrorReasonPhrase = errorReasonPhrase, 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..375f43b3e 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,12 +171,12 @@ 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); @@ -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/Attachment.cs b/src/SendGrid/Helpers/Mail/Model/Attachment.cs index 92a0db625..40c20aec4 100644 --- a/src/SendGrid/Helpers/Mail/Model/Attachment.cs +++ b/src/SendGrid/Helpers/Mail/Model/Attachment.cs @@ -23,7 +23,7 @@ public class Attachment /// 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. @@ -35,12 +35,12 @@ public class Attachment /// 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/EmailAddress.cs b/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs index cbf7baafd..ef13aeed7 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,7 +36,7 @@ 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. @@ -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/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/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/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 2fda64f46..78d885f2b 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -51,13 +51,13 @@ public class SendGridMessage /// 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. @@ -130,20 +130,20 @@ public class SendGridMessage /// 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; } /// /// 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"); @@ -157,9 +157,9 @@ 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) + if (email is null) throw new ArgumentNullException("email"); AddTos(new List { email }, personalizationIndex, personalization); @@ -171,7 +171,7 @@ 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"); @@ -179,7 +179,7 @@ public void AddTos(List emails, int personalizationIndex = 0, Pers throw new InvalidOperationException("Sequence contains no elements"); personalization = GetPersonalization(personalizationIndex, personalization); - personalization.Tos = personalization.Tos ?? new List(); + personalization.Tos ??= new List(); personalization.Tos.AddRange(emails); } @@ -189,7 +189,7 @@ 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"); @@ -204,9 +204,9 @@ 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) + if (email is null) throw new ArgumentNullException("email"); AddCcs(new List { email }, personalizationIndex, personalization); @@ -220,7 +220,7 @@ 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"); @@ -228,7 +228,7 @@ public void AddCcs(List emails, int personalizationIndex = 0, Pers 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); } @@ -238,7 +238,7 @@ 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"); @@ -253,9 +253,9 @@ 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) + if (email is null) throw new ArgumentNullException("email"); AddBccs(new List { email }, personalizationIndex, personalization); @@ -269,7 +269,7 @@ 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"); @@ -277,7 +277,7 @@ public void AddBccs(List emails, int personalizationIndex = 0, Per 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); } @@ -287,7 +287,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; @@ -300,7 +300,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); } @@ -311,7 +311,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 : @@ -326,7 +326,7 @@ public void AddHeaders(Dictionary headers, int personalizationIn /// 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); } @@ -337,7 +337,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 : @@ -350,7 +350,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; @@ -363,7 +363,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); } @@ -374,7 +374,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 : @@ -387,7 +387,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; @@ -399,7 +399,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) { @@ -431,7 +431,7 @@ 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)) { @@ -525,7 +525,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) @@ -551,10 +551,11 @@ 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)) { + // Shouldn't this throw? return; } @@ -576,11 +577,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(); this.Attachments.Add(attachment); } @@ -590,11 +587,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(); this.Attachments.AddRange(attachments); } @@ -799,7 +792,7 @@ 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; @@ -828,12 +821,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, @@ -848,12 +837,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, }; @@ -867,14 +852,10 @@ public void SetBypassListManagement(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, @@ -890,12 +871,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, }; @@ -909,14 +886,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, @@ -933,12 +906,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, @@ -952,14 +921,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, @@ -975,14 +940,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, @@ -1002,14 +963,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, diff --git a/src/SendGrid/ISendGridClient.cs b/src/SendGrid/ISendGridClient.cs index f00d7b01d..508350dbb 100644 --- a/src/SendGrid/ISendGridClient.cs +++ b/src/SendGrid/ISendGridClient.cs @@ -52,13 +52,13 @@ public interface ISendGridClient /// /// 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. diff --git a/src/SendGrid/Permissions/SendGridClientExtensions.cs b/src/SendGrid/Permissions/SendGridClientExtensions.cs index 8468ef1d9..6c847bfd8 100644 --- a/src/SendGrid/Permissions/SendGridClientExtensions.cs +++ b/src/SendGrid/Permissions/SendGridClientExtensions.cs @@ -19,8 +19,8 @@ public static class SendGridClientExtensions public static async Task CreateMaskedPermissionsBuilderForClient(this ISendGridClient client) { var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "scopes"); - var body = await response.DeserializeResponseBodyAsync(response.Body); - var userScopesJArray = (body["scopes"] as JArray); + var body = await response.DeserializeResponseBodyAsync(response.Body!); + var userScopesJArray = (JArray)body["scopes"]; var includedScopes = userScopesJArray.Values().ToArray(); var builder = new SendGridPermissionsBuilder(); builder.Exclude(scope => !includedScopes.Contains(scope)); diff --git a/src/SendGrid/Reliability/RetryDelegatingHandler.cs b/src/SendGrid/Reliability/RetryDelegatingHandler.cs index c212513de..2d06afc54 100644 --- a/src/SendGrid/Reliability/RetryDelegatingHandler.cs +++ b/src/SendGrid/Reliability/RetryDelegatingHandler.cs @@ -17,14 +17,13 @@ namespace SendGrid.Helpers.Reliability /// public class RetryDelegatingHandler : DelegatingHandler { - private static readonly List RetriableServerErrorStatusCodes = - new List() - { - HttpStatusCode.InternalServerError, - HttpStatusCode.BadGateway, - HttpStatusCode.ServiceUnavailable, - HttpStatusCode.GatewayTimeout, - }; + private static readonly List RetriableServerErrorStatusCodes = new() + { + HttpStatusCode.InternalServerError, + HttpStatusCode.BadGateway, + HttpStatusCode.ServiceUnavailable, + HttpStatusCode.GatewayTimeout, + }; private readonly ReliabilitySettings settings; @@ -56,12 +55,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); @@ -96,9 +95,9 @@ protected override async Task SendAsync(HttpRequestMessage await TaskUtilities.Delay(waitFor).ConfigureAwait(false); } - } + } while (!sent); - return responseMessage; + return responseMessage!; } private static void ThrowHttpRequestExceptionIfResponseCodeCanBeRetried(HttpResponseMessage responseMessage) diff --git a/src/SendGrid/Response.cs b/src/SendGrid/Response.cs index 0caf6900b..247664350 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,58 +34,22 @@ 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. diff --git a/src/SendGrid/SendGrid.csproj b/src/SendGrid/SendGrid.csproj index 0f09800bd..f8c020c50 100644 --- a/src/SendGrid/SendGrid.csproj +++ b/src/SendGrid/SendGrid.csproj @@ -11,6 +11,9 @@ true full $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb;.xml + enable + nullable + latest @@ -45,6 +48,7 @@ + diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index 71d656791..692fcbe15 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -21,8 +21,8 @@ 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) - : base(webProxy, buildOptions(apiKey, host, requestHeaders, version, urlPath)) + 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, httpErrorAsException)) { } @@ -36,8 +36,8 @@ 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) - : base(httpClient, buildOptions(apiKey, host, requestHeaders, version, urlPath)) + 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, httpErrorAsException)) { } @@ -50,8 +50,8 @@ 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) - : base(buildOptions(apiKey, host, requestHeaders, version, urlPath)) + public SendGridClient(string apiKey, string? host = null, Dictionary? requestHeaders = null, string? version = null, string? urlPath = null, bool httpErrorAsException = false) + : base(buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException)) { } @@ -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, bool httpErrorAsException) { return new SendGridClientOptions { @@ -85,6 +85,7 @@ private static SendGridClientOptions buildOptions(string apiKey, string host, Di RequestHeaders = requestHeaders ?? DefaultOptions.RequestHeaders, Version = version ?? DefaultOptions.Version, UrlPath = urlPath ?? DefaultOptions.UrlPath, + HttpErrorAsException = httpErrorAsException, }; } } 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; From ed33ac0caa136667593ccf8683f719c32bc9e1c7 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 29 Nov 2021 16:21:15 +0200 Subject: [PATCH 02/22] Initialize collections --- src/SendGrid/BaseClientOptions.cs | 4 ++-- src/SendGrid/Helpers/Mail/Model/ASM.cs | 2 +- src/SendGrid/Helpers/Mail/Model/Attachment.cs | 4 ++-- src/SendGrid/Helpers/Mail/Model/BCCSettings.cs | 2 +- .../Helpers/Mail/Model/Personalization.cs | 12 ++++++------ src/SendGrid/Helpers/Mail/SendGridMessage.cs | 16 ++++++++-------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/SendGrid/BaseClientOptions.cs b/src/SendGrid/BaseClientOptions.cs index 43e29077f..15505568c 100644 --- a/src/SendGrid/BaseClientOptions.cs +++ b/src/SendGrid/BaseClientOptions.cs @@ -29,7 +29,7 @@ public ReliabilitySettings ReliabilitySettings /// /// The base URL. /// - public string Host { get; set; } + public string Host { get; set; } = string.Empty; /// /// The API version (defaults to "v3"). @@ -39,7 +39,7 @@ public ReliabilitySettings ReliabilitySettings /// /// The path to the API endpoint. /// - public string UrlPath { get; set; } + public string UrlPath { get; set; } = string.Empty; /// /// The Auth header value. diff --git a/src/SendGrid/Helpers/Mail/Model/ASM.cs b/src/SendGrid/Helpers/Mail/Model/ASM.cs index 526f8714a..e9a21100b 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(); } } diff --git a/src/SendGrid/Helpers/Mail/Model/Attachment.cs b/src/SendGrid/Helpers/Mail/Model/Attachment.cs index 40c20aec4..bc456dda9 100644 --- a/src/SendGrid/Helpers/Mail/Model/Attachment.cs +++ b/src/SendGrid/Helpers/Mail/Model/Attachment.cs @@ -17,7 +17,7 @@ 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. @@ -29,7 +29,7 @@ public class Attachment /// 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". 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/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index c00ad392e..18bd4ca7b 100644 --- a/src/SendGrid/Helpers/Mail/Model/Personalization.cs +++ b/src/SendGrid/Helpers/Mail/Model/Personalization.cs @@ -20,21 +20,21 @@ public class Personalization /// [JsonProperty(PropertyName = "to", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Tos { get; set; } + public List Tos { get; set; } = new(); /// /// 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; } = new(); /// /// 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; } = new(); /// /// 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. @@ -52,20 +52,20 @@ public class Personalization /// 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; } = new(); /// /// 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; } = new(); /// /// 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; } = new(); /// /// 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. diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 78d885f2b..e4bfeee63 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -32,20 +32,20 @@ public class SendGridMessage /// 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; } = string.Empty; /// /// 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; } = new(); /// /// 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; } = new(); /// /// Gets or sets a Content object with a Mime Type of text/plain. @@ -63,7 +63,7 @@ public class SendGridMessage /// 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; } = new(); /// /// 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. @@ -75,25 +75,25 @@ public class SendGridMessage /// 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; } = new(); /// /// 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; } = new(); /// /// 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; } = new(); /// /// 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; } = new(); /// /// 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. From 015808aa1288a03b72d38f2c3a8a713e73b3ef3a Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 29 Nov 2021 16:22:14 +0200 Subject: [PATCH 03/22] Style fixes --- src/SendGrid/BaseClient.cs | 4 +-- src/SendGrid/Helpers/Mail/MailHelper.cs | 2 +- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 26 +++++++++---------- src/SendGrid/ISendGridClient.cs | 4 +-- .../Permissions/SendGridClientExtensions.cs | 4 +-- .../SendGridPermissionsBuilder.Scopes.cs | 6 ++--- src/SendGrid/SendGridClient.cs | 2 +- 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/SendGrid/BaseClient.cs b/src/SendGrid/BaseClient.cs index 9a0a1a071..5827c737a 100644 --- a/src/SendGrid/BaseClient.cs +++ b/src/SendGrid/BaseClient.cs @@ -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); @@ -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, diff --git a/src/SendGrid/Helpers/Mail/MailHelper.cs b/src/SendGrid/Helpers/Mail/MailHelper.cs index 375f43b3e..f7a8cf74a 100644 --- a/src/SendGrid/Helpers/Mail/MailHelper.cs +++ b/src/SendGrid/Helpers/Mail/MailHelper.cs @@ -16,7 +16,7 @@ public class MailHelper { private const string NameGroup = "name"; private const string EmailGroup = "email"; - private static readonly Regex Rfc2822Regex = new Regex( + private static readonly Regex Rfc2822Regex = new( $@"(?:(?<{NameGroup}>[^\<]*)\<(?<{EmailGroup}>.*@.*)\>|(?<{NameGroup}>)(?<{EmailGroup}>[^\<]*@.*[^\>]))", RegexOptions.ECMAScript); diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index e4bfeee63..0dffc9fe0 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -146,7 +146,7 @@ public class SendGridMessage 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)); } @@ -160,7 +160,7 @@ public void AddTo(string email, string? name = null) public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email is null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddTos(new List { email }, personalizationIndex, personalization); } @@ -174,7 +174,7 @@ public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalizat 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"); @@ -192,7 +192,7 @@ public void AddTos(List emails, int personalizationIndex = 0, Pers 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)); } @@ -207,7 +207,7 @@ public void AddCc(string email, string? name = null) public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email is null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddCcs(new List { email }, personalizationIndex, personalization); } @@ -223,7 +223,7 @@ public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalizat 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"); @@ -241,7 +241,7 @@ public void AddCcs(List emails, int personalizationIndex = 0, Pers 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)); } @@ -256,7 +256,7 @@ public void AddBcc(string email, string? name = null) public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { if (email is null) - throw new ArgumentNullException("email"); + throw new ArgumentNullException(nameof(email)); AddBccs(new List { email }, personalizationIndex, personalization); } @@ -272,7 +272,7 @@ public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personaliza 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"); @@ -435,7 +435,7 @@ 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)); @@ -1018,16 +1018,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 508350dbb..12af3cf97 100644 --- a/src/SendGrid/ISendGridClient.cs +++ b/src/SendGrid/ISendGridClient.cs @@ -45,7 +45,7 @@ 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. @@ -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 6c847bfd8..7dbce75f8 100644 --- a/src/SendGrid/Permissions/SendGridClientExtensions.cs +++ b/src/SendGrid/Permissions/SendGridClientExtensions.cs @@ -20,8 +20,8 @@ public static async Task CreateMaskedPermissionsBuil { var response = await client.RequestAsync(method: SendGridClient.Method.GET, urlPath: "scopes"); var body = await response.DeserializeResponseBodyAsync(response.Body!); - var userScopesJArray = (JArray)body["scopes"]; - var includedScopes = userScopesJArray.Values().ToArray(); + var userScopesJArray = body["scopes"] as JArray; + 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..f86b394e8 100644 --- a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs +++ b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs @@ -1,12 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Generic; namespace SendGrid.Permissions { partial class SendGridPermissionsBuilder { - private readonly Dictionary allPermissions = new Dictionary + private readonly Dictionary allPermissions = new() { #region Admin { SendGridPermission.Admin, new [] diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index 692fcbe15..14f16da6b 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -9,7 +9,7 @@ namespace SendGrid /// public class SendGridClient : BaseClient { - private static readonly SendGridClientOptions DefaultOptions = new SendGridClientOptions(); + private static readonly SendGridClientOptions DefaultOptions = new(); /// /// Initializes a new instance of the class. From a0a274953e801f82f29da244c6a3540cb4170099 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 29 Nov 2021 16:22:38 +0200 Subject: [PATCH 04/22] Nullable batch 2 --- src/SendGrid/BaseClient.cs | 2 +- src/SendGrid/BaseClientOptions.cs | 4 ++-- src/SendGrid/Helpers/Mail/Model/Content.cs | 7 +++++-- src/SendGrid/Helpers/Mail/Model/EmailAddress.cs | 4 ++-- src/SendGrid/Helpers/Mail/Model/MailSettings.cs | 10 +++++----- src/SendGrid/Helpers/Mail/Model/Personalization.cs | 8 +++++--- .../Helpers/Mail/Model/TrackingSettings.cs | 8 ++++---- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 14 ++++++++------ src/SendGrid/ISendGridClient.cs | 2 +- 9 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/SendGrid/BaseClient.cs b/src/SendGrid/BaseClient.cs index 5827c737a..7ff36ed24 100644 --- a/src/SendGrid/BaseClient.cs +++ b/src/SendGrid/BaseClient.cs @@ -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; diff --git a/src/SendGrid/BaseClientOptions.cs b/src/SendGrid/BaseClientOptions.cs index 15505568c..e901d458a 100644 --- a/src/SendGrid/BaseClientOptions.cs +++ b/src/SendGrid/BaseClientOptions.cs @@ -34,7 +34,7 @@ public ReliabilitySettings ReliabilitySettings /// /// The API version (defaults to "v3"). /// - public string Version { get; set; } = "v3"; + public string? Version { get; set; } = "v3"; /// /// The path to the API endpoint. @@ -44,7 +44,7 @@ public ReliabilitySettings ReliabilitySettings /// /// 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/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 ef13aeed7..2b920d185 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; @@ -42,7 +42,7 @@ public EmailAddress(string email, string? name = null) /// 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. diff --git a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs index 3a3917a05..230e07a8c 100644 --- a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs @@ -17,31 +17,31 @@ 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 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/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index 18bd4ca7b..15d25b4cc 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 { @@ -40,13 +41,14 @@ public class Personalization /// 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. @@ -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/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 0dffc9fe0..85e745162 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,7 +27,8 @@ 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. @@ -69,7 +71,7 @@ public class SendGridMessage /// 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. @@ -105,26 +107,26 @@ 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. diff --git a/src/SendGrid/ISendGridClient.cs b/src/SendGrid/ISendGridClient.cs index 12af3cf97..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. From b5ce64810cf283b4e838f99957ee1fea68a65c8b Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 2 Dec 2021 17:35:56 +0200 Subject: [PATCH 05/22] Added missed annotations --- src/SendGrid/Helpers/Mail/MailHelper.cs | 8 ++++---- src/SendGrid/Helpers/Mail/Model/JsonConverters.cs | 5 +---- src/SendGrid/Permissions/SendGridPermissionsBuilder.cs | 10 ++++------ src/SendGrid/TwilioEmailClientOptions.cs | 3 +-- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/MailHelper.cs b/src/SendGrid/Helpers/Mail/MailHelper.cs index f7a8cf74a..9c9f77322 100644 --- a/src/SendGrid/Helpers/Mail/MailHelper.cs +++ b/src/SendGrid/Helpers/Mail/MailHelper.cs @@ -174,20 +174,20 @@ public static SendGridMessage CreateMultipleEmailsToMultipleRecipients( EmailAddress from, List tos, List subjects, - string plainTextContent, - string htmlContent, + 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++) 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/Permissions/SendGridPermissionsBuilder.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs index 4e807920f..6e25c4984 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(); - private readonly List addedScopes; + private readonly List addedScopes = new(); 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/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)) { From 43f28e773689f55929d5b06e9d0dc948765e6fab Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 2 Dec 2021 17:41:56 +0200 Subject: [PATCH 06/22] Update .Net SDK in pipeline --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 619bee295..7e3741789 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,9 +14,9 @@ jobs: uses: actions/checkout@v2 - name: Setup .NET Core SDK - uses: actions/setup-dotnet@v1.8.2 + uses: actions/setup-dotnet@v1 with: - dotnet-version: '3.1.x' + dotnet-version: 6.0.x - name: Publish package to NuGet run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b087d945..0ffb5d655 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,9 +21,9 @@ jobs: fetch-depth: 0 - name: Setup .NET Core SDK - uses: actions/setup-dotnet@v1.8.2 + uses: actions/setup-dotnet@v1 with: - dotnet-version: '3.1.x' + dotnet-version: 6.0.x - run: dotnet build -c Release - name: Build & Test From dde679852f0f896de3974ed5be0f0503c99bd8e5 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Fri, 3 Dec 2021 16:18:53 +0200 Subject: [PATCH 07/22] Remove duplicated word --- src/SendGrid/Reliability/ReliabilitySettings.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SendGrid/Reliability/ReliabilitySettings.cs b/src/SendGrid/Reliability/ReliabilitySettings.cs index bc202fcd8..97589484f 100644 --- a/src/SendGrid/Reliability/ReliabilitySettings.cs +++ b/src/SendGrid/Reliability/ReliabilitySettings.cs @@ -24,8 +24,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) { @@ -76,12 +76,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; } From 422be176992db172c1b1fcd1ebc7175e88e9e9c6 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Wed, 23 Mar 2022 23:52:35 +0200 Subject: [PATCH 08/22] Revert pipeline changes --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7e3741789..65190a0fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: '3.1.x' - name: Publish package to NuGet run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0ffb5d655..ac7ea0aca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Setup .NET Core SDK uses: actions/setup-dotnet@v1 with: - dotnet-version: 6.0.x + dotnet-version: '3.1.x' - run: dotnet build -c Release - name: Build & Test From 255b68d0a84db59f565c30cd6fc1e0648c00c043 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Wed, 23 Mar 2022 23:58:13 +0200 Subject: [PATCH 09/22] Revert C#9 changes --- src/SendGrid/BaseClientOptions.cs | 4 ++-- src/SendGrid/Helpers/Errors/ErrorHandler.cs | 2 +- src/SendGrid/Helpers/Mail/MailHelper.cs | 2 +- src/SendGrid/Helpers/Mail/Model/ASM.cs | 2 +- .../Helpers/Mail/Model/Personalization.cs | 12 ++++++------ src/SendGrid/Helpers/Mail/SendGridMessage.cs | 18 +++++++++--------- .../SendGridPermissionsBuilder.Scopes.cs | 2 +- .../Permissions/SendGridPermissionsBuilder.cs | 4 ++-- .../Reliability/RetryDelegatingHandler.cs | 2 +- src/SendGrid/SendGrid.csproj | 2 +- src/SendGrid/SendGridClient.cs | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/SendGrid/BaseClientOptions.cs b/src/SendGrid/BaseClientOptions.cs index e901d458a..406ee98da 100644 --- a/src/SendGrid/BaseClientOptions.cs +++ b/src/SendGrid/BaseClientOptions.cs @@ -10,7 +10,7 @@ namespace SendGrid /// public class BaseClientOptions { - private ReliabilitySettings reliabilitySettings = new(); + private ReliabilitySettings reliabilitySettings = new ReliabilitySettings(); /// /// The reliability settings to use on HTTP Requests. @@ -24,7 +24,7 @@ public ReliabilitySettings ReliabilitySettings /// /// The request headers to use on HTTP Requests. /// - public Dictionary RequestHeaders { get; set; } = new(); + public Dictionary RequestHeaders { get; set; } = new Dictionary(); /// /// The base URL. diff --git a/src/SendGrid/Helpers/Errors/ErrorHandler.cs b/src/SendGrid/Helpers/Errors/ErrorHandler.cs index dfde4f7af..749db4b79 100644 --- a/src/SendGrid/Helpers/Errors/ErrorHandler.cs +++ b/src/SendGrid/Helpers/Errors/ErrorHandler.cs @@ -139,7 +139,7 @@ private static async Task GetErrorMessage(HttpResponseMessage message) } } - SendGridErrorResponse errorResponse = new() + SendGridErrorResponse errorResponse = new SendGridErrorResponse() { ErrorHttpStatusCode = errorStatusCode, ErrorReasonPhrase = errorReasonPhrase, diff --git a/src/SendGrid/Helpers/Mail/MailHelper.cs b/src/SendGrid/Helpers/Mail/MailHelper.cs index 9c9f77322..643803224 100644 --- a/src/SendGrid/Helpers/Mail/MailHelper.cs +++ b/src/SendGrid/Helpers/Mail/MailHelper.cs @@ -16,7 +16,7 @@ public class MailHelper { private const string NameGroup = "name"; private const string EmailGroup = "email"; - private static readonly Regex Rfc2822Regex = new( + private static readonly Regex Rfc2822Regex = new Regex( $@"(?:(?<{NameGroup}>[^\<]*)\<(?<{EmailGroup}>.*@.*)\>|(?<{NameGroup}>)(?<{EmailGroup}>[^\<]*@.*[^\>]))", RegexOptions.ECMAScript); diff --git a/src/SendGrid/Helpers/Mail/Model/ASM.cs b/src/SendGrid/Helpers/Mail/Model/ASM.cs index e9a21100b..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; } = new(); + public List GroupsToDisplay { get; set; } = new List(); } } diff --git a/src/SendGrid/Helpers/Mail/Model/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index 15d25b4cc..dfbb70ba3 100644 --- a/src/SendGrid/Helpers/Mail/Model/Personalization.cs +++ b/src/SendGrid/Helpers/Mail/Model/Personalization.cs @@ -21,21 +21,21 @@ public class Personalization /// [JsonProperty(PropertyName = "to", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Tos { get; set; } = new(); + 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; } = new(); + public List Ccs { get; set; } = new List(); /// /// 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; } = new(); + public List Bccs { get; set; } = new List(); /// /// 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. @@ -54,20 +54,20 @@ public class Personalization /// 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; } = new(); + public Dictionary Headers { get; set; } = new Dictionary(); /// /// 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; } = new(); + public Dictionary Substitutions { get; set; } = new Dictionary(); /// /// 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; } = new(); + public Dictionary CustomArgs { get; set; } = new Dictionary(); /// /// 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. diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 85e745162..593b2fb23 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -41,13 +41,13 @@ public class SendGridMessage /// https://sendgrid.com/docs/Classroom/Send/v3_Mail_Send/personalizations.html. /// [JsonProperty(PropertyName = "personalizations", IsReference = false)] - public List Personalizations { get; set; } = new(); + public List Personalizations { get; set; } = new List(); /// /// 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; } = new(); + public List Contents { get; set; } = new List(); /// /// Gets or sets a Content object with a Mime Type of text/plain. @@ -65,7 +65,7 @@ public class SendGridMessage /// 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; } = new(); + public List Attachments { get; set; } = new List(); /// /// 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. @@ -77,25 +77,25 @@ public class SendGridMessage /// 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; } = new(); + public Dictionary Headers { get; set; } = new Dictionary(); /// /// 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; } = new(); + public Dictionary Sections { get; set; } = new Dictionary(); /// /// 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; } = new(); + public List Categories { get; set; } = new List(); /// /// 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; } = new(); + public Dictionary CustomArgs { get; set; } = new Dictionary(); /// /// 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. @@ -579,7 +579,7 @@ public void AddAttachment(string filename, string base64Content, string? type = /// An Attachment. public void AddAttachment(Attachment attachment) { - this.Attachments ??= new(); + this.Attachments ??= new List(); this.Attachments.Add(attachment); } @@ -589,7 +589,7 @@ public void AddAttachment(Attachment attachment) /// A list of Attachments. public void AddAttachments(IEnumerable attachments) { - this.Attachments ??= new(); + this.Attachments ??= new List(); this.Attachments.AddRange(attachments); } diff --git a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs index f86b394e8..dcf38d150 100644 --- a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs +++ b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs @@ -4,7 +4,7 @@ namespace SendGrid.Permissions { partial class SendGridPermissionsBuilder { - private readonly Dictionary allPermissions = new() + private readonly Dictionary allPermissions = new Dictionary() { #region Admin { SendGridPermission.Admin, new [] diff --git a/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.cs index 6e25c4984..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 = new(); + private readonly List> excludeFilters = new List>(); - private readonly List addedScopes = new(); + private readonly List addedScopes = new List(); private readonly HashSet allScopes; diff --git a/src/SendGrid/Reliability/RetryDelegatingHandler.cs b/src/SendGrid/Reliability/RetryDelegatingHandler.cs index 2d06afc54..3de03f8f9 100644 --- a/src/SendGrid/Reliability/RetryDelegatingHandler.cs +++ b/src/SendGrid/Reliability/RetryDelegatingHandler.cs @@ -17,7 +17,7 @@ namespace SendGrid.Helpers.Reliability /// public class RetryDelegatingHandler : DelegatingHandler { - private static readonly List RetriableServerErrorStatusCodes = new() + private static readonly List RetriableServerErrorStatusCodes = new List() { HttpStatusCode.InternalServerError, HttpStatusCode.BadGateway, diff --git a/src/SendGrid/SendGrid.csproj b/src/SendGrid/SendGrid.csproj index 9ff6edea1..9dfc869b6 100644 --- a/src/SendGrid/SendGrid.csproj +++ b/src/SendGrid/SendGrid.csproj @@ -13,7 +13,7 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb;.xml enable nullable - latest + 8 diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index 14f16da6b..692fcbe15 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -9,7 +9,7 @@ namespace SendGrid /// public class SendGridClient : BaseClient { - private static readonly SendGridClientOptions DefaultOptions = new(); + private static readonly SendGridClientOptions DefaultOptions = new SendGridClientOptions(); /// /// Initializes a new instance of the class. From ccee4702234192f01bbb7e54d2d6880a97951c44 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 24 Mar 2022 00:08:54 +0200 Subject: [PATCH 10/22] Merge --- .../Helpers/Mail/Model/MailSettings.cs | 6 +- src/SendGrid/Response.cs | 62 +++---------------- 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs index 1100e3505..d71fcdf4a 100644 --- a/src/SendGrid/Helpers/Mail/Model/MailSettings.cs +++ b/src/SendGrid/Helpers/Mail/Model/MailSettings.cs @@ -29,19 +29,19 @@ public class MailSettings /// 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. diff --git a/src/SendGrid/Response.cs b/src/SendGrid/Response.cs index ccb376fb9..1a8807586 100644 --- a/src/SendGrid/Response.cs +++ b/src/SendGrid/Response.cs @@ -18,21 +18,6 @@ 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. /// @@ -49,18 +34,7 @@ public Response(HttpStatusCode statusCode, HttpContent? responseBody, HttpRespon /// /// 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. @@ -71,44 +45,22 @@ public HttpStatusCode StatusCode /// 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(); @@ -124,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; From 8f4e1edabbcbfb93cd0fff8b8d57937b61f01871 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 24 Mar 2022 00:15:41 +0200 Subject: [PATCH 11/22] Update SendGrid.Extensions.DependencyInjection.csproj --- .../SendGrid.Extensions.DependencyInjection.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj b/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj index 6cb1babb2..b8b8a932f 100644 --- a/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj +++ b/src/SendGrid.Extensions.DependencyInjection/SendGrid.Extensions.DependencyInjection.csproj @@ -9,7 +9,7 @@ ..\SendGrid\SendGrid.ruleset enable nullable - latest + 8 From 5e379a2449544c69a3656dcb4fc2c7561136a255 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 24 Mar 2022 00:35:57 +0200 Subject: [PATCH 12/22] Revert innitializing collections in `SendGridMessage` --- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 1e10082ad..4cf717f6f 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -34,20 +34,20 @@ public class SendGridMessage /// Gets or sets the subject of your email. This may be overridden by personalizations[x].subject. /// [JsonProperty(PropertyName = "subject")] - public string Subject { get; set; } = string.Empty; + 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; } = new List(); + 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; } = new List(); + public List? Contents { get; set; } /// /// Gets or sets a Content object with a Mime Type of text/plain. @@ -65,7 +65,7 @@ public class SendGridMessage /// 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; } = new List(); + 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. @@ -77,25 +77,25 @@ public class SendGridMessage /// 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; } = new Dictionary(); + 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; } = new Dictionary(); + 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; } = new List(); + 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; } = new Dictionary(); + 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. From 79ccc06ffeaf5d209328e50a1d6964e38e0da929 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 24 Mar 2022 00:49:22 +0200 Subject: [PATCH 13/22] Revert innitializing collections in `Personalization` --- src/SendGrid/Helpers/Mail/Model/Personalization.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/Model/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index dfbb70ba3..2c3107d0e 100644 --- a/src/SendGrid/Helpers/Mail/Model/Personalization.cs +++ b/src/SendGrid/Helpers/Mail/Model/Personalization.cs @@ -21,21 +21,21 @@ public class Personalization /// [JsonProperty(PropertyName = "to", IsReference = false)] [JsonConverter(typeof(RemoveDuplicatesConverter))] - public List Tos { get; set; } = new List(); + public List? Tos { get; set; } /// /// 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; } = new List(); + 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; } = new List(); + 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. @@ -54,20 +54,20 @@ public class Personalization /// 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; } = new Dictionary(); + 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; } = new Dictionary(); + 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; } = new Dictionary(); + 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. From de3e049933706d5855d1234ed747e838405ba05f Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Thu, 24 Mar 2022 00:58:24 +0200 Subject: [PATCH 14/22] Update SendGridMessage.cs --- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 4cf717f6f..56007ab59 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -796,8 +796,10 @@ public void SetBatchId(string batchId) /// 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; From 8d48348ca2bde8e991286fee39b51121f6a981c3 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sat, 26 Mar 2022 00:53:16 +0200 Subject: [PATCH 15/22] Update annotations after merge --- src/SendGrid/Helpers/Mail/Model/EmailAddress.cs | 4 ++-- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs b/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs index 2b920d185..9f8cab8ce 100644 --- a/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs +++ b/src/SendGrid/Helpers/Mail/Model/EmailAddress.cs @@ -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); } diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index f2bcf67b6..42bf2aad6 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -144,7 +144,7 @@ public class SendGridMessage /// 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. @@ -332,7 +332,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"); From 2fccfdc7efa9a9d6320512e72021ef8dec9865cf Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 28 Mar 2022 22:16:40 +0300 Subject: [PATCH 16/22] Revert some changes --- src/SendGrid/Helpers/Errors/ErrorHandler.cs | 2 +- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 7 +++---- .../Permissions/SendGridPermissionsBuilder.Scopes.cs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/SendGrid/Helpers/Errors/ErrorHandler.cs b/src/SendGrid/Helpers/Errors/ErrorHandler.cs index 749db4b79..39cd308f8 100644 --- a/src/SendGrid/Helpers/Errors/ErrorHandler.cs +++ b/src/SendGrid/Helpers/Errors/ErrorHandler.cs @@ -139,7 +139,7 @@ private static async Task GetErrorMessage(HttpResponseMessage message) } } - SendGridErrorResponse errorResponse = new SendGridErrorResponse() + SendGridErrorResponse errorResponse = new SendGridErrorResponse { ErrorHttpStatusCode = errorStatusCode, ErrorReasonPhrase = errorReasonPhrase, diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 42bf2aad6..9a70aae9a 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -167,7 +167,7 @@ public void AddTo(string email, string? name = null) /// A personalization object to append to the message. public void AddTo(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { - if (email is null) + if (email == null) throw new ArgumentNullException(nameof(email)); AddTos(new List { email }, personalizationIndex, personalization); @@ -214,7 +214,7 @@ public void AddCc(string email, string? name = null) /// Thrown when the email parameter is null public void AddCc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { - if (email is null) + if (email == null) throw new ArgumentNullException(nameof(email)); AddCcs(new List { email }, personalizationIndex, personalization); @@ -263,7 +263,7 @@ public void AddBcc(string email, string? name = null) /// Thrown when the email parameter is null public void AddBcc(EmailAddress email, int personalizationIndex = 0, Personalization? personalization = null) { - if (email is null) + if (email == null) throw new ArgumentNullException(nameof(email)); AddBccs(new List { email }, personalizationIndex, personalization); @@ -607,7 +607,6 @@ public void AddAttachment(string filename, string base64Content, string? type = { if (string.IsNullOrWhiteSpace(filename) || string.IsNullOrWhiteSpace(base64Content)) { - // Shouldn't this throw? return; } diff --git a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs index dcf38d150..61a7e664c 100644 --- a/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs +++ b/src/SendGrid/Permissions/SendGridPermissionsBuilder.Scopes.cs @@ -4,7 +4,7 @@ namespace SendGrid.Permissions { partial class SendGridPermissionsBuilder { - private readonly Dictionary allPermissions = new Dictionary() + private readonly Dictionary allPermissions = new Dictionary { #region Admin { SendGridPermission.Admin, new [] From 1733e7711972307366ed6abb99392c29952ff49c Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Mon, 28 Mar 2022 22:17:00 +0300 Subject: [PATCH 17/22] Revert `httpErrorAsException` changes --- src/SendGrid/SendGridClient.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/SendGrid/SendGridClient.cs b/src/SendGrid/SendGridClient.cs index 692fcbe15..792d4eafe 100644 --- a/src/SendGrid/SendGridClient.cs +++ b/src/SendGrid/SendGridClient.cs @@ -22,7 +22,7 @@ public class SendGridClient : BaseClient /// 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) - : base(webProxy, buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException)) + : base(webProxy, buildOptions(apiKey, host, requestHeaders, version, urlPath)) { } @@ -37,7 +37,7 @@ public SendGridClient(IWebProxy webProxy, string apiKey, string? host = null, Di /// 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) - : base(httpClient, buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException)) + : base(httpClient, buildOptions(apiKey, host, requestHeaders, version, urlPath)) { } @@ -50,8 +50,8 @@ 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, bool httpErrorAsException = false) - : base(buildOptions(apiKey, host, requestHeaders, version, urlPath, httpErrorAsException)) + 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, bool httpErrorAsException) + private static SendGridClientOptions buildOptions(string apiKey, string? host, Dictionary? requestHeaders, string? version, string? urlPath) { return new SendGridClientOptions { @@ -84,8 +84,7 @@ private static SendGridClientOptions buildOptions(string apiKey, string? host, D Host = host ?? DefaultOptions.Host, RequestHeaders = requestHeaders ?? DefaultOptions.RequestHeaders, Version = version ?? DefaultOptions.Version, - UrlPath = urlPath ?? DefaultOptions.UrlPath, - HttpErrorAsException = httpErrorAsException, + UrlPath = urlPath ?? DefaultOptions.UrlPath }; } } From 2f34479c28a75196bf660f3e90bea4999b2d91e4 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sat, 2 Apr 2022 23:19:59 +0300 Subject: [PATCH 18/22] Tos are non-nullable --- src/SendGrid/Helpers/Mail/Model/Personalization.cs | 2 +- src/SendGrid/Helpers/Mail/SendGridMessage.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SendGrid/Helpers/Mail/Model/Personalization.cs b/src/SendGrid/Helpers/Mail/Model/Personalization.cs index 2c3107d0e..4f4261aca 100644 --- a/src/SendGrid/Helpers/Mail/Model/Personalization.cs +++ b/src/SendGrid/Helpers/Mail/Model/Personalization.cs @@ -21,7 +21,7 @@ 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. diff --git a/src/SendGrid/Helpers/Mail/SendGridMessage.cs b/src/SendGrid/Helpers/Mail/SendGridMessage.cs index 9a70aae9a..13f3bc871 100644 --- a/src/SendGrid/Helpers/Mail/SendGridMessage.cs +++ b/src/SendGrid/Helpers/Mail/SendGridMessage.cs @@ -187,7 +187,6 @@ public void AddTos(List emails, int personalizationIndex = 0, Pers throw new InvalidOperationException("Sequence contains no elements"); personalization = GetPersonalization(personalizationIndex, personalization); - personalization.Tos ??= new List(); personalization.Tos.AddRange(emails); } From fd2b40d8b8233b2ac5e8a1d33a211bd892c59614 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sat, 2 Apr 2022 23:52:15 +0300 Subject: [PATCH 19/22] Fix tests --- tests/SendGrid.Tests/Integration.cs | 140 +++++++++--------- .../TemplateDataSerialisationTests.cs | 2 +- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index 4ea870598..36c1605f9 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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"}]},{\"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\"},{\"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\"}},{\"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\"}},{\"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\"}},{\"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\"}},{\"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\"}},{\"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\"}},{\"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\"}},{\"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\"}},{\"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 From 7956860c94a034cc2d499a3677915fe11411b6dd Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sun, 3 Apr 2022 00:08:00 +0300 Subject: [PATCH 20/22] Fix tests --- tests/SendGrid.Tests/Integration.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index 36c1605f9..52ddfb3c3 100644 --- a/tests/SendGrid.Tests/Integration.cs +++ b/tests/SendGrid.Tests/Integration.cs @@ -968,7 +968,7 @@ public void TestAddCc() } }; msg.AddCc(new EmailAddress("test006@example.com", "Example User"), 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1068,7 +1068,7 @@ public void TestAddCcs() new EmailAddress("test023@example.com", "Example User") }; msg.AddCcs(emails, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1118,7 +1118,7 @@ public void TestAddCcs() new EmailAddress("test033@example.com", "Example User") }; msg.AddCcs(emails); - 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\"}]},{\"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] @@ -1162,7 +1162,7 @@ public void TestAddBcc() } }; msg.AddBcc(new EmailAddress("test006@example.com", "Example User"), 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1200,7 +1200,7 @@ public void TestAddBcc() }; msg.Personalizations.Add(personalization); msg.AddBcc(new EmailAddress("test011@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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] @@ -1288,7 +1288,7 @@ public void TestAddBccs() new EmailAddress("test023@example.com", "Example User") }; msg.AddBccs(emails, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1416,7 +1416,7 @@ public void TestSetSubject() }; msg.Personalizations.Add(personalization); msg.SetSubject("subject11"); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject11\"},{\"subject\":\"subject10\"}]}", msg.Serialize()); + Assert.Equal("{\"personalizations\":[{\"to\":[],\"subject\":\"subject11\"},{\"to\":[],\"subject\":\"subject10\"}]}", msg.Serialize()); } [Fact] @@ -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\":[{\"to\":[],\"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(); @@ -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\":[{\"to\":[],\"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] @@ -1616,7 +1616,7 @@ public void TestAddSubstitution() } }; msg.AddSubstitution("-sub6-", "Substituted Value 6", 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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 @@ -1720,7 +1720,7 @@ public void TestAddSubstitutions() {"-sub23-", "Substituted Value 23"} }; msg.AddSubstitutions(substitutions, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1770,7 +1770,7 @@ public void TestAddSubstitutions() {"-sub33-", "Substituted Value 33"} }; msg.AddSubstitutions(substitutions); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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] @@ -1832,7 +1832,7 @@ public void TestSetTemplateData() key23 = "Dynamic Template Data Value 23" }; msg.SetTemplateData(dynamicTemplateData6, 1, personalization); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); @@ -1882,7 +1882,7 @@ public void TestSetTemplateData() key33 = "Dynamic Template Data Value 33" }; msg.SetTemplateData(dynamicTemplateData11); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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(); From 63875bc56e94f472ba41f89820665ee1d00998be Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sun, 3 Apr 2022 00:16:18 +0300 Subject: [PATCH 21/22] Fix tests --- tests/SendGrid.Tests/Integration.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index 52ddfb3c3..0f3b38eb7 100644 --- a/tests/SendGrid.Tests/Integration.cs +++ b/tests/SendGrid.Tests/Integration.cs @@ -1338,7 +1338,7 @@ public void TestAddBccs() new EmailAddress("test033@example.com", "Example User") }; msg.AddBccs(emails); - 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\"}]},{\"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] @@ -1658,7 +1658,7 @@ public void TestAddSubstitution() }; msg.Personalizations.Add(personalization); msg.AddSubstitution("-sub11-", "Substituted Value 11"); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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] From a2a84dbfe12fdb22f8e428227da3267045f682d7 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sun, 3 Apr 2022 00:21:22 +0300 Subject: [PATCH 22/22] Fix tests --- tests/SendGrid.Tests/Integration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index 0f3b38eb7..04475d19f 100644 --- a/tests/SendGrid.Tests/Integration.cs +++ b/tests/SendGrid.Tests/Integration.cs @@ -1006,7 +1006,7 @@ public void TestAddCc() }; msg.Personalizations.Add(personalization); msg.AddCc(new EmailAddress("test011@example.com", "Example User")); - Assert.Equal("{\"personalizations\":[{\"to\":[],\"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]