From 4d898f651e4ece08434bdc002eaa9adbaf825aba Mon Sep 17 00:00:00 2001 From: Jericho Date: Sat, 15 May 2021 11:10:57 -0400 Subject: [PATCH 1/2] Refresh resource files --- Source/StrongGrid.IntegrationTests/TestsRunner.cs | 2 +- build.cake | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/StrongGrid.IntegrationTests/TestsRunner.cs b/Source/StrongGrid.IntegrationTests/TestsRunner.cs index 1ef41950..13b3e67c 100644 --- a/Source/StrongGrid.IntegrationTests/TestsRunner.cs +++ b/Source/StrongGrid.IntegrationTests/TestsRunner.cs @@ -65,7 +65,7 @@ public async Task RunAsync() }; // Ensure the Console is tall enough and centered on the screen - Console.WindowHeight = Math.Min(60, Console.LargestWindowHeight); + if (OperatingSystem.IsWindows()) Console.WindowHeight = Math.Min(60, Console.LargestWindowHeight); Utils.CenterConsole(); // These are the integration tests that we will execute diff --git a/build.cake b/build.cake index 08f0c6a6..fae9bf71 100644 --- a/build.cake +++ b/build.cake @@ -1,7 +1,7 @@ // Install tools. #tool dotnet:?package=GitVersion.Tool&version=5.6.6 #tool nuget:?package=GitReleaseManager&version=0.11.0 -#tool nuget:?package=OpenCover&version=4.7.922 +#tool nuget:?package=OpenCover&version=4.7.1189 #tool nuget:?package=ReportGenerator&version=4.8.8 #tool nuget:?package=coveralls.io&version=1.4.2 #tool nuget:?package=xunit.runner.console&version=2.4.1 @@ -126,7 +126,7 @@ Setup(context => // Integration tests are intended to be used for debugging purposes and not intended to be executed in CI environment. // Also, the runner for these tests contains windows-specific code (such as resizing window, moving window to center of screen, etc.) // which can cause problems when attempting to run unit tests on an Ubuntu image on AppVeyor. - if (IsRunningOnUnix()) + if (!isLocalBuild) { Information(""); Information("Removing integration tests"); @@ -136,7 +136,7 @@ Setup(context => Teardown(context => { - if (IsRunningOnUnix()) + if (!isLocalBuild) { Information("Restoring integration tests"); GitCheckout(".", new FilePath[] { solutionFile }); From 27b3637569994a7e3e0c05f2b79827fa9c4a88b0 Mon Sep 17 00:00:00 2001 From: Jericho Date: Sat, 22 May 2021 10:00:34 -0400 Subject: [PATCH 2/2] Only include bypass_xxx_management mail settings when their boolean value is true Resolves #395 --- .../StrongGrid.IntegrationTests/Tests/Mail.cs | 4 +- .../Utilities/MailSettingsConverter.cs | 44 +++++++------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Source/StrongGrid.IntegrationTests/Tests/Mail.cs b/Source/StrongGrid.IntegrationTests/Tests/Mail.cs index ce625aeb..0ebf1cc7 100644 --- a/Source/StrongGrid.IntegrationTests/Tests/Mail.cs +++ b/Source/StrongGrid.IntegrationTests/Tests/Mail.cs @@ -65,7 +65,9 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken Enabled = true, HtmlContent = "

This email was sent with the help of the StrongGrid library

", TextContent = "This email was sent with the help of the StrongGrid library" - } + }, + BypassSpamManagement = true, + BypassListManagement = false }; var trackingSettings = new TrackingSettings { diff --git a/Source/StrongGrid/Utilities/MailSettingsConverter.cs b/Source/StrongGrid/Utilities/MailSettingsConverter.cs index 441e8b67..9edb6a70 100644 --- a/Source/StrongGrid/Utilities/MailSettingsConverter.cs +++ b/Source/StrongGrid/Utilities/MailSettingsConverter.cs @@ -62,29 +62,12 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s var mailSettings = (MailSettings)value; - writer.WritePropertyName("bypass_list_management"); - writer.WriteStartObject(); - writer.WritePropertyName("enable"); - serializer.Serialize(writer, mailSettings.BypassListManagement); - writer.WriteEndObject(); - - writer.WritePropertyName("bypass_spam_management"); - writer.WriteStartObject(); - writer.WritePropertyName("enable"); - serializer.Serialize(writer, mailSettings.BypassSpamManagement); - writer.WriteEndObject(); - - writer.WritePropertyName("bypass_bounce_management"); - writer.WriteStartObject(); - writer.WritePropertyName("enable"); - serializer.Serialize(writer, mailSettings.BypassBounceManagement); - writer.WriteEndObject(); - - writer.WritePropertyName("bypass_unsubscribe_management"); - writer.WriteStartObject(); - writer.WritePropertyName("enable"); - serializer.Serialize(writer, mailSettings.BypassUnsubscribeManagement); - writer.WriteEndObject(); + // bypass_xxx_management should be omited when the value is 'false'. + // See https://github.com/Jericho/StrongGrid/issues/395 for details. + if (mailSettings.BypassListManagement) WriteEnabledProperty(writer, "bypass_list_management", true, serializer); + if (mailSettings.BypassSpamManagement) WriteEnabledProperty(writer, "bypass_spam_management", true, serializer); + if (mailSettings.BypassBounceManagement) WriteEnabledProperty(writer, "bypass_bounce_management", true, serializer); + if (mailSettings.BypassUnsubscribeManagement) WriteEnabledProperty(writer, "bypass_unsubscribe_management", true, serializer); if (mailSettings.Footer != null) { @@ -92,11 +75,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s serializer.Serialize(writer, mailSettings.Footer); } - writer.WritePropertyName("sandbox_mode"); - writer.WriteStartObject(); - writer.WritePropertyName("enable"); - serializer.Serialize(writer, mailSettings.SandboxModeEnabled); - writer.WriteEndObject(); + WriteEnabledProperty(writer, "sandbox_mode", mailSettings.SandboxModeEnabled, serializer); // End of JSON serialization writer.WriteEndObject(); @@ -116,5 +95,14 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist { throw new NotSupportedException("The MailSettingsConverter can only be used to write JSON"); } + + private static void WriteEnabledProperty(JsonWriter writer, string propertyName, bool value, JsonSerializer serializer) + { + writer.WritePropertyName(propertyName); + writer.WriteStartObject(); + writer.WritePropertyName("enable"); + serializer.Serialize(writer, value); + writer.WriteEndObject(); + } } }