Skip to content

Commit

Permalink
Merge branch 'release/0.106.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jericho committed Feb 16, 2024
2 parents ae876c3 + 4672984 commit 4019ab6
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 155 deletions.
67 changes: 67 additions & 0 deletions Source/StrongGrid.UnitTests/Models/SingleSendTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Shouldly;
using StrongGrid.Json;
using StrongGrid.Models;
using System;
using System.Text.Json;
using Xunit;

namespace StrongGrid.UnitTests.Models
{
public class SingleSendTests
{
private const string SINGLE_SEND_JSON = @"{
""id"":""5e0555c5-cb50-11ee-a09e-6aa2ee6dcd4d"",
""name"":""StrongGrid Unit Testing: single send"",
""status"":""draft"",
""categories"":[""category1"",""category2""],
""send_at"":null,
""send_to"":{
""list_ids"":[""a21d5383-1f7c-4e7a-bf2e-511467f58e7d""],
""segment_ids"":[],
""all"":false
},
""updated_at"":""2024-02-14T15:47:34Z"",
""created_at"":""2024-02-14T15:47:33Z"",
""email_config"":{
""subject"":""This is the subject"",
""html_content"":""<html><body><b>This is the HTML conytent</b></body></html>"",
""plain_content"":""This is the text content"",
""generate_plain_content"":false,
""editor"":""code"",
""suppression_group_id"":54321,
""custom_unsubscribe_url"":null,
""sender_id"":12345,
""ip_pool"":null
}
}";

[Fact]
public void Parse_processed_JSON()
{
// Arrange

// Act
var result = JsonSerializer.Deserialize<SingleSend>(SINGLE_SEND_JSON, JsonFormatter.DeserializerOptions);

// Assert
result.Categories.ShouldBe(new[] { "category1", "category2" });
result.EmailConfig.HtmlContent.ShouldBe("<html><body><b>This is the HTML conytent</b></body></html>");
result.EmailConfig.IpPool.ShouldBeNull();
result.EmailConfig.Subject.ShouldBe("This is the subject");
result.EmailConfig.TextContent.ShouldBe("This is the text content");
result.EmailConfig.CustomUnsubscribeUrl.ShouldBeNull();
result.EmailConfig.EditorType.ShouldBe(EditorType.Code);
result.EmailConfig.GeneratePlainContent.ShouldBeFalse();
result.EmailConfig.SenderId.ShouldBe(12345);
result.EmailConfig.SuppressionGroupId.ShouldBe(54321);
result.CreatedOn.ShouldBe(new DateTime(2024, 2, 14, 15, 47, 33, DateTimeKind.Utc));
result.Id.ShouldBe("5e0555c5-cb50-11ee-a09e-6aa2ee6dcd4d");
result.Recipients.Lists.ShouldBe(new[] { "a21d5383-1f7c-4e7a-bf2e-511467f58e7d" });
result.Recipients.Segments.ShouldBe(Array.Empty<string>());
result.Name.ShouldBe("StrongGrid Unit Testing: single send");
result.SendOn.ShouldBeNull();
result.Status.ShouldBe(SingleSendStatus.Draft);
result.UpdatedOn.ShouldBe(new DateTime(2024, 2, 14, 15, 47, 34, DateTimeKind.Utc));
}
}
}
10 changes: 8 additions & 2 deletions Source/StrongGrid/Json/EpochConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ internal class EpochConverter : BaseJsonConverter<DateTime>
{
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var secondsSinceEpoch = reader.GetInt64();
return secondsSinceEpoch.FromUnixTime();
switch (reader.TokenType)
{
case JsonTokenType.Number:
var secondsSinceEpoch = reader.GetInt64();
return secondsSinceEpoch.FromUnixTime();
default:
throw new Exception($"Unable to convert {reader.TokenType.ToEnumString()} to DateTime");
}
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
Expand Down
4 changes: 2 additions & 2 deletions Source/StrongGrid/Json/StrongGridJsonSerializerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace StrongGrid.Json
[JsonSerializable(typeof(StrongGrid.Models.SenderReputation))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSend))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendEmailConfig))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendSendTo))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendRecipients))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendStatus))]
[JsonSerializable(typeof(StrongGrid.Models.SpamCheckingSettings))]
[JsonSerializable(typeof(StrongGrid.Models.SpamCheckSettings))]
Expand Down Expand Up @@ -378,7 +378,7 @@ namespace StrongGrid.Json
[JsonSerializable(typeof(StrongGrid.Models.SenderReputation[]))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSend[]))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendEmailConfig[]))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendSendTo[]))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendRecipients[]))]
[JsonSerializable(typeof(StrongGrid.Models.SingleSendStatus[]))]
[JsonSerializable(typeof(StrongGrid.Models.SpamCheckingSettings[]))]
[JsonSerializable(typeof(StrongGrid.Models.SpamCheckSettings[]))]
Expand Down
147 changes: 5 additions & 142 deletions Source/StrongGrid/Models/SingleSend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,152 +72,15 @@ public class SingleSend
public DateTime? CreatedOn { get; set; }

/// <summary>
/// Gets or sets the subject.
/// Gets or sets the configuration about the email that will be sent to the recipients.
/// </summary>
/// <value>
/// The subject.
/// </value>
[JsonIgnore]
public string Subject
{
get => EmailConfig.Subject;
set => EmailConfig.Subject = value;
}

/// <summary>
/// Gets or sets the HTML content.
/// </summary>
/// <value>
/// The HTML content.
/// </value>
[JsonIgnore]
public string HtmlContent
{
get => EmailConfig.HtmlContent;
set => EmailConfig.HtmlContent = value;
}

/// <summary>
/// Gets or sets the plain text content.
/// </summary>
/// <value>
/// The plain text content.
/// </value>
[JsonIgnore]
public string TextContent
{
get => EmailConfig.TextContent;
set => EmailConfig.TextContent = value;
}

/// <summary>
/// Gets or sets a value indicating whether the plain content should be generated.
/// </summary>
/// <value>
/// The generate_plain_content.
/// </value>
[JsonIgnore]
public bool GeneratePlainContent
{
get => EmailConfig.GeneratePlainContent;
set => EmailConfig.GeneratePlainContent = value;
}

/// <summary>
/// Gets or sets the type of editor used in the UI.
/// </summary>
/// <value>
/// The type of editor.
/// </value>
[JsonIgnore]
public EditorType EditorType
{
get => EmailConfig.EditorType;
set => EmailConfig.EditorType = value;
}

/// <summary>
/// Gets or sets the sender identifier.
/// </summary>
/// <value>
/// The sender identifier.
/// </value>
[JsonIgnore]
public long SenderId
{
get => EmailConfig.SenderId;
set => EmailConfig.SenderId = value;
}

/// <summary>
/// Gets or sets the custom unsubscribe URL.
/// </summary>
/// <value>
/// The custom unsubscribe URL.
/// </value>
[JsonIgnore]
public string CustomUnsubscribeUrl
{
get => EmailConfig.CustomUnsubscribeUrl;
set => EmailConfig.CustomUnsubscribeUrl = value;
}

/// <summary>
/// Gets or sets the suppression group identifier.
/// </summary>
/// <value>
/// The suppression group identifier.
/// </value>
[JsonIgnore]
public long? SuppressionGroupId
{
get => EmailConfig.SuppressionGroupId;
set => EmailConfig.SuppressionGroupId = value;
}

/// <summary>
/// Gets or sets the ip pool.
/// </summary>
/// <value>
/// The ip pool.
/// </value>
[JsonIgnore]
public string IpPool
{
get => EmailConfig.IpPool;
set => EmailConfig.IpPool = value;
}

/// <summary>
/// Gets or sets the lists.
/// </summary>
/// <value>
/// The lists.
/// </value>
[JsonIgnore]
public string[] Lists
{
get => SendTo.Lists;
set => SendTo.Lists = value;
}
[JsonPropertyName("email_config")]
public SingleSendEmailConfig EmailConfig { get; set; }

/// <summary>
/// Gets or sets the segments.
/// Gets or sets the information about who will receive this Single Send.
/// </summary>
/// <value>
/// The segments.
/// </value>
[JsonIgnore]
public string[] Segments
{
get => SendTo.Segments;
set => SendTo.Segments = value;
}

[JsonPropertyName("email_config")]
private SingleSendEmailConfig EmailConfig { get; set; }

[JsonPropertyName("send_to")]
private SingleSendSendTo SendTo { get; set; }
public SingleSendRecipients Recipients { get; set; }
}
}
2 changes: 1 addition & 1 deletion Source/StrongGrid/Models/SingleSendEmailConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace StrongGrid.Models
/// <summary>
/// Single Send email config.
/// </summary>
internal class SingleSendEmailConfig
public class SingleSendEmailConfig
{
/// <summary>
/// Gets or sets the subject.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace StrongGrid.Models
{
/// <summary>
/// Single Send send to.
/// The recipients of a Single Send.
/// </summary>
internal class SingleSendSendTo
public class SingleSendRecipients
{
/// <summary>
/// Gets or sets the lists.
Expand Down
6 changes: 3 additions & 3 deletions Source/StrongGrid/Resources/Mail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public async Task<string> SendAsync(
foreach (var personalization in personalizationsCopy)
{
// Make sure the arrays are not null otherwise Linq's 'Except' method will throw a ArgumentNull exception (See GH-286).
if (personalization.To == null) personalization.To = Array.Empty<MailAddress>();
if (personalization.Cc == null) personalization.Cc = Array.Empty<MailAddress>();
if (personalization.Bcc == null) personalization.Bcc = Array.Empty<MailAddress>();
personalization.To ??= Array.Empty<MailAddress>();
personalization.Cc ??= Array.Empty<MailAddress>();
personalization.Bcc ??= Array.Empty<MailAddress>();

// Avoid duplicate addresses. This is important because SendGrid does not throw any
// exception when a recipient is duplicated (which gives you the impression the email
Expand Down
4 changes: 2 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#tool dotnet:?package=GitVersion.Tool&version=5.12.0
#tool dotnet:?package=coveralls.net&version=4.0.1
#tool nuget:https://f.feedz.io/jericho/jericho/nuget/?package=GitReleaseManager&version=0.17.0-collaborators0003
#tool nuget:?package=ReportGenerator&version=5.2.0
#tool nuget:?package=xunit.runner.console&version=2.6.6
#tool nuget:?package=ReportGenerator&version=5.2.1
#tool nuget:?package=xunit.runner.console&version=2.7.0
#tool nuget:?package=CodecovUploader&version=0.7.1

// Install addins.
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.101",
"version": "8.0.201",
"rollForward": "patch",
"allowPrerelease": false
}
Expand Down

0 comments on commit 4019ab6

Please sign in to comment.