diff --git a/GitReleaseManager.yaml b/GitReleaseManager.yaml index e8749cf3..b2ed72e4 100644 --- a/GitReleaseManager.yaml +++ b/GitReleaseManager.yaml @@ -26,6 +26,7 @@ issue-labels-include: - Bug - New Feature - Improvement + - Enhancement - Documentation - Security issue-labels-exclude: diff --git a/Source/StrongGrid.Benchmark/JsonParsingBenchmark.cs b/Source/StrongGrid.Benchmark/JsonParsingBenchmark.cs new file mode 100644 index 00000000..2a0acaad --- /dev/null +++ b/Source/StrongGrid.Benchmark/JsonParsingBenchmark.cs @@ -0,0 +1,105 @@ +using BenchmarkDotNet.Attributes; +using RichardSzalay.MockHttp; +using StrongGrid.Models; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; + +namespace StrongGrid.Benchmark +{ + [MemoryDiagnoser] + [HtmlExporter] + [MarkdownExporterAttribute.GitHub] + public class JsonParsingBenchmark + { + private const int limit = 100; + private const int offset = 0; + private const int recordsPerPage = 25; + private const int page = 1; + + private static Client _client; + private static LegacyClient _legacyClient; + + public JsonParsingBenchmark() + { + var mockHttp = GetMockHttpMessageHandler(); + _client = new Client("my API key", mockHttp, null, null); + _legacyClient = new LegacyClient("my API key", mockHttp, null, null); + } + + [Benchmark] + public async Task SystemTextJson6() + { + var whitelistedIpAddresses = await _client.AccessManagement.GetWhitelistedIpAddressesAsync(null, CancellationToken.None).ConfigureAwait(false); + var accessHistory = await _client.AccessManagement.GetAccessHistoryAsync(20, null, CancellationToken.None).ConfigureAwait(false); + var alerts = await _client.Alerts.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var apiKeys = await _client.ApiKeys.GetAllAsync(limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var batches = await _client.Batches.GetAllAsync().ConfigureAwait(false); + var blocks = await _client.Blocks.GetAllAsync(null, null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var bounces = await _client.Bounces.GetAsync("test@test.com", null, CancellationToken.None).ConfigureAwait(false); + var legacyCampaigns = await _legacyClient.Campaigns.GetAllAsync(limit, offset, CancellationToken.None).ConfigureAwait(false); + var designs = await _client.Designs.GetAllAsync(recordsPerPage, null, CancellationToken.None).ConfigureAwait(false); + var emailActivities = await _client.EmailActivities.SearchAsync(null, limit, CancellationToken.None).ConfigureAwait(false); + var validationResult = await _client.EmailValidation.ValidateAsync("john.doe@gmial.com", "Signup Form", CancellationToken.None).ConfigureAwait(false); + var globalSuppressions = await _client.GlobalSuppressions.GetAllAsync(null, null, null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var invalidEmails = await _client.InvalidEmails.GetAllAsync(null, null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var ipAddresses = await _client.IpAddresses.GetAllAsync(false, null, limit, offset, CancellationToken.None).ConfigureAwait(false); + var ipPool = await _client.IpPools.GetAsync("marketing", CancellationToken.None).ConfigureAwait(false); + var legacyCategories = await _legacyClient.Categories.GetAsync(null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var legacyContacts = await _legacyClient.Contacts.GetAsync(recordsPerPage, page, null, CancellationToken.None).ConfigureAwait(false); + var legacyCustomFields = await _legacyClient.CustomFields.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var legacyLists = await _legacyClient.Lists.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var legacySegments = await _legacyClient.Segments.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var legacySenderIdentities = await _legacyClient.SenderIdentities.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + var authenticationDomains = await _client.SenderAuthentication.GetAllDomainsAsync(limit, offset, false, null, null, null, CancellationToken.None).ConfigureAwait(false); + var reverseDns = await _client.SenderAuthentication.GetAllReverseDnsAsync(null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var links = await _client.SenderAuthentication.GetAllLinksAsync(null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var spamReports = await _client.SpamReports.GetAllAsync(null, null, limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var subusers = await _client.Subusers.GetAllAsync(limit, offset, CancellationToken.None).ConfigureAwait(false); + var suppressions = await _client.Suppressions.GetAllAsync(limit, offset, null, CancellationToken.None).ConfigureAwait(false); + var accessRequests = await _client.Teammates.GetAccessRequestsAsync(limit, offset, CancellationToken.None).ConfigureAwait(false); + var invitations = await _client.Teammates.GetAllPendingInvitationsAsync(limit, offset, CancellationToken.None).ConfigureAwait(false); + var teammates = await _client.Teammates.GetAllTeammatesAsync(limit, offset, CancellationToken.None).ConfigureAwait(false); + var templates = await _client.Templates.GetAllAsync(TemplateType.Legacy, null, CancellationToken.None).ConfigureAwait(false); + var unsubscribeGroups = await _client.UnsubscribeGroups.GetAllAsync(null, CancellationToken.None).ConfigureAwait(false); + } + + private static MockHttpMessageHandler GetMockHttpMessageHandler() + { + var mockHttp = new MockHttpMessageHandler(); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("access_settings/whitelist")).Respond("application/json", UnitTests.Resources.AccessManagementTests.MULTIPLE_WHITELISTED_IPS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("access_settings/activity")).Respond("application/json", UnitTests.Resources.AccessManagementTests.MULTIPLE_ACCESS_ENTRIES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("alerts")).Respond("application/json", UnitTests.Resources.AlertsTests.MULTIPLE_ALERTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("api_keys")).Respond("application/json", UnitTests.Resources.ApiKeysTests.MULTIPLE_API_KEY_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("user/scheduled_sends")).Respond("application/json", UnitTests.Resources.BatchesTests.MULTIPLE_BATCHES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("suppression/blocks") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.BlocksTests.MULTIPLE_BLOCKS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("suppression/bounces", "test@test.com")).Respond("application/json", UnitTests.Resources.BouncesTests.MULTIPLE_BOUNCES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("campaigns") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.CampaignsTests.MULTIPLE_CAMPAIGNS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("designs")).Respond("application/json", UnitTests.Resources.DesignsTests.MULTIPLE_DESIGNS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("messages") + $"?limit={limit}&query=").Respond("application/json", UnitTests.Resources.EmailActivitiesTests.MULTIPLE_MESSAGES_FOUND); + mockHttp.When(HttpMethod.Post, UnitTests.Utils.GetSendGridApiUri("validations/email")).Respond("application/json", "{\"result\":" + UnitTests.Resources.EmailValidationTests.VALID_EMAIL_JSON + "}"); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("suppression/unsubscribes")).Respond("application/json", UnitTests.Resources.GlobalSuppressionTests.GLOBALLY_UNSUBSCRIBED); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("suppression/invalid_emails") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.InvalidEmailsTests.MULTIPLE_INVALID_EMAILS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("ips")).Respond("application/json", UnitTests.Resources.IpAddressesTests.MULTIPLE_IPADDRESSES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("ips/pools", "marketing")).Respond("application/json", UnitTests.Resources.IpPoolsTests.SINGLE_IPPOOL_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("categories") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.LegacyCategoriesTests.MULTIPLE_CATEGORIES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("contactdb/recipients") + $"?page_size={recordsPerPage}&page={page}").Respond("application/json", UnitTests.Resources.LegacyContactsTests.MULTIPLE_RECIPIENTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("contactdb/custom_fields")).Respond("application/json", UnitTests.Resources.LegacyCustomFieldsTests.MULTIPLE_CUSTOM_FIELDS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("contactdb/lists")).Respond("application/json", UnitTests.Resources.LegacyListsTests.MULTIPLE_LISTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("contactdb/segments")).Respond("application/json", UnitTests.Resources.LegacySegmentsTests.MULTIPLE_SEGMENTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("senders")).Respond("application/json", UnitTests.Resources.LegacySenderIdentitiesTests.MULTIPLE_SENDER_IDENTITIES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("whitelabel/domains") + $"?exclude_subusers=false&limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.SenderAuthenticationTests.MULTIPLE_DOMAINS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("whitelabel/ips") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.SenderAuthenticationTests.MULTIPLE_IPS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("whitelabel/links") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.SenderAuthenticationTests.MULTIPLE_LINKS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("suppression/spam_reports") + $"?limit={limit}&offset={offset}").Respond("application/json", UnitTests.Resources.SpamReportsTests.MULTIPLE_SPAM_REPORTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("subusers")).Respond("application/json", UnitTests.Resources.SubusersTests.MULTIPLE_SUBUSER_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("asm", "suppressions")).Respond("application/json", UnitTests.Resources.SuppresionsTests.ALL_SUPPRESSIONS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("scopes/requests")).Respond("application/json", UnitTests.Resources.TeammatesTests.MULTIPLE_ACCESS_REQUESTS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("teammates", "pending")).Respond("application/json", UnitTests.Resources.TeammatesTests.MULTIPLE_INVITATIONS_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("teammates")).Respond("application/json", UnitTests.Resources.TeammatesTests.MULTIPLE_TEAMMATES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("templates")).Respond("application/json", UnitTests.Resources.TemplatesTests.MULTIPLE_TEMPLATES_JSON); + mockHttp.When(HttpMethod.Get, UnitTests.Utils.GetSendGridApiUri("asm/groups")).Respond("application/json", UnitTests.Resources.UnsubscribeGroupsTests.MULTIPLE_SUPPRESSION_GROUPS_JSON); + return mockHttp; + } + } +} diff --git a/Source/StrongGrid.Benchmark/Program.cs b/Source/StrongGrid.Benchmark/Program.cs new file mode 100644 index 00000000..88862b3b --- /dev/null +++ b/Source/StrongGrid.Benchmark/Program.cs @@ -0,0 +1,37 @@ +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Running; + +namespace StrongGrid.Benchmark +{ + class Program + { + static void Main(string[] args) + { + //var baseNamespace = "StrongGrid.Models"; + //var allTypes = Assembly + // .GetAssembly(typeof(BaseClient)) + // .GetTypes() + // .Where(t => t.IsClass) + // .Where(t => !string.IsNullOrEmpty(t.Namespace)) + // .Where(t => t.Namespace.StartsWith(baseNamespace)) + // .Where(t => !t.Namespace.StartsWith(baseNamespace + ".Webhooks.InboundEmail")); // Exclude inbound email classes which are deserialized by our WebhookParser + + //var typesInBaseNamespace = allTypes + // .Where(t => t.Namespace.Equals(baseNamespace)) + // .Select(t => new { Type = t, JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}))]" }); + + //var typesInSubNamespace = allTypes + // .Where(t => !t.Namespace.Equals(baseNamespace)) + // .Select(t => new { Type = t, JsonSerializeAttribute = $"[JsonSerializable(typeof({t.FullName}), TypeInfoPropertyName = \"{t.FullName.Remove(0, baseNamespace.Length + 1).Replace(".", "")}\")]" }); + + //var result = string.Join("\r\n", typesInBaseNamespace.Union(typesInSubNamespace).OrderBy(t => t.Type.FullName).Select(t => t.JsonSerializeAttribute)); + + IConfig config = null; + + // To debug + //config = new DebugInProcessConfig(); + + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); + } + } +} diff --git a/Source/StrongGrid.Benchmark/StrongGrid.Benchmark.csproj b/Source/StrongGrid.Benchmark/StrongGrid.Benchmark.csproj new file mode 100644 index 00000000..4a15701f --- /dev/null +++ b/Source/StrongGrid.Benchmark/StrongGrid.Benchmark.csproj @@ -0,0 +1,18 @@ + + + + Exe + net6.0 + + + + + + + + + + + + + diff --git a/Source/StrongGrid.IntegrationTests/Tests/Settings.cs b/Source/StrongGrid.IntegrationTests/Tests/Settings.cs index 75f518fd..a28e0e43 100644 --- a/Source/StrongGrid.IntegrationTests/Tests/Settings.cs +++ b/Source/StrongGrid.IntegrationTests/Tests/Settings.cs @@ -33,28 +33,6 @@ public async Task RunAsync(IBaseClient client, TextWriter log, CancellationToken await log.WriteLineAsync($" - {mailSetting.Title}: {(mailSetting.Enabled ? "Enabled" : "Not enabled")}").ConfigureAwait(false); } - var spamCheckSettings = await client.Settings.GetSpamCheckMailSettingsAsync(null, cancellationToken).ConfigureAwait(false); - await log.WriteLineAsync("SPAM Check settings retrieved:").ConfigureAwait(false); - await log.WriteLineAsync($" - Enabled: {spamCheckSettings.Enabled}").ConfigureAwait(false); - await log.WriteLineAsync($" - Threshold: {spamCheckSettings.Threshold}").ConfigureAwait(false); - await log.WriteLineAsync($" - URL: {spamCheckSettings.Url}").ConfigureAwait(false); - - var updatedSpamCheckSettings = await client.Settings.UpdateSpamCheckMailSettingsAsync(false, null, 1, null, cancellationToken).ConfigureAwait(false); - await log.WriteLineAsync("SPAM Check settings updated:").ConfigureAwait(false); - await log.WriteLineAsync($" - Enabled: {updatedSpamCheckSettings.Enabled}").ConfigureAwait(false); - await log.WriteLineAsync($" - Threshold: {updatedSpamCheckSettings.Threshold}").ConfigureAwait(false); - await log.WriteLineAsync($" - URL: {updatedSpamCheckSettings.Url}").ConfigureAwait(false); - - var bccSettings = await client.Settings.GetBccMailSettingsAsync(null, cancellationToken).ConfigureAwait(false); - await log.WriteLineAsync("BCC settings retrieved:").ConfigureAwait(false); - await log.WriteLineAsync($" - Enabled: {bccSettings.Enabled}").ConfigureAwait(false); - await log.WriteLineAsync($" - Address: {bccSettings.EmailAddress}").ConfigureAwait(false); - - var updatedBccSettings = await client.Settings.UpdateBccMailSettingsAsync(false, null, null, cancellationToken).ConfigureAwait(false); - await log.WriteLineAsync("BCC settings updated:").ConfigureAwait(false); - await log.WriteLineAsync($" - Enabled: {updatedBccSettings.Enabled}").ConfigureAwait(false); - await log.WriteLineAsync($" - Address: {updatedBccSettings.EmailAddress}").ConfigureAwait(false); - var clickTrackingSettings = await client.Settings.GetClickTrackingSettingsAsync(null, cancellationToken).ConfigureAwait(false); await log.WriteLineAsync("Click tracking settings retrieved:").ConfigureAwait(false); await log.WriteLineAsync($" - Enabled in text content: {clickTrackingSettings.EnabledInTextContent}").ConfigureAwait(false); diff --git a/Source/StrongGrid.UnitTests/Models/PaginationMetadataTests.cs b/Source/StrongGrid.UnitTests/Models/PaginationMetadataTests.cs index 6f73e959..6671d124 100644 --- a/Source/StrongGrid.UnitTests/Models/PaginationMetadataTests.cs +++ b/Source/StrongGrid.UnitTests/Models/PaginationMetadataTests.cs @@ -1,6 +1,6 @@ -using Newtonsoft.Json; using Shouldly; using StrongGrid.Models; +using System.Text.Json; using Xunit; namespace StrongGrid.UnitTests.Models @@ -8,22 +8,22 @@ namespace StrongGrid.UnitTests.Models public class PaginationMetadataTests { private const string FIRST_PAGE_JSON = @"{ - 'self':'https://api.sendgrid.com/v3/designs?page_token=self_token', - 'next':'https://api.sendgrid.com/v3/designs?page_token=next_token', - 'count':5 + ""self"":""https://api.sendgrid.com/v3/designs?page_token=self_token"", + ""next"":""https://api.sendgrid.com/v3/designs?page_token=next_token"", + ""count"":5 }"; private const string MIDDLE_PAGE_JSON = @"{ - 'prev':'https://api.sendgrid.com/v3/designs?page_token=prev_token', - 'self':'https://api.sendgrid.com/v3/designs?page_token=self_token', - 'next':'https://api.sendgrid.com/v3/designs?page_token=next_token', - 'count':5 + ""prev"":""https://api.sendgrid.com/v3/designs?page_token=prev_token"", + ""self"":""https://api.sendgrid.com/v3/designs?page_token=self_token"", + ""next"":""https://api.sendgrid.com/v3/designs?page_token=next_token"", + ""count"":5 }"; private const string LAST_PAGE_JSON = @"{ - 'prev':'https://api.sendgrid.com/v3/designs?page_token=prev_token', - 'self':'https://api.sendgrid.com/v3/designs?page_token=self_token', - 'count':5 + ""prev"":""https://api.sendgrid.com/v3/designs?page_token=prev_token"", + ""self"":""https://api.sendgrid.com/v3/designs?page_token=self_token"", + ""count"":5 }"; [Fact] @@ -32,7 +32,7 @@ public void Parse_json_first_page() // Arrange // Act - var result = JsonConvert.DeserializeObject(FIRST_PAGE_JSON); + var result = JsonSerializer.Deserialize(FIRST_PAGE_JSON); // Assert result.ShouldNotBeNull(); @@ -51,7 +51,7 @@ public void Parse_json_middle_page() // Arrange // Act - var result = JsonConvert.DeserializeObject(MIDDLE_PAGE_JSON); + var result = JsonSerializer.Deserialize(MIDDLE_PAGE_JSON); // Assert result.ShouldNotBeNull(); @@ -70,7 +70,7 @@ public void Parse_json_last_page() // Arrange // Act - var result = JsonConvert.DeserializeObject(LAST_PAGE_JSON); + var result = JsonSerializer.Deserialize(LAST_PAGE_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Properties/AssemblyInfo.cs b/Source/StrongGrid.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e4a62eb6 --- /dev/null +++ b/Source/StrongGrid.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("StrongGrid.Benchmark")] + diff --git a/Source/StrongGrid.UnitTests/Resources/AccessManagementTests.cs b/Source/StrongGrid.UnitTests/Resources/AccessManagementTests.cs index b74a8730..afc1c2ca 100644 --- a/Source/StrongGrid.UnitTests/Resources/AccessManagementTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/AccessManagementTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,62 +16,62 @@ public class AccessManagementTests { #region FIELDS - private const string ENDPOINT = "access_settings"; + internal const string ENDPOINT = "access_settings"; - private const string SINGLE_ACCESS_ENTRY_JSON = @"{ - 'allowed': false, - 'auth_method': 'basic', - 'first_at': 1444087966, - 'ip': '1.1.1.1', - 'last_at': 1444406672, - 'location': 'Australia' + internal const string SINGLE_ACCESS_ENTRY_JSON = @"{ + ""allowed"": false, + ""auth_method"": ""basic"", + ""first_at"": 1444087966, + ""ip"": ""1.1.1.1"", + ""last_at"": 1444406672, + ""location"": ""Australia"" }"; - private const string MULTIPLE_ACCESS_ENTRIES_JSON = @"{ - 'result': [ + internal const string MULTIPLE_ACCESS_ENTRIES_JSON = @"{ + ""result"": [ { - 'allowed': false, - 'auth_method': 'basic', - 'first_at': 1444087966, - 'ip': '1.1.1.1', - 'last_at': 1444406672, - 'location': 'Australia' + ""allowed"": false, + ""auth_method"": ""basic"", + ""first_at"": 1444087966, + ""ip"": ""1.1.1.1"", + ""last_at"": 1444406672, + ""location"": ""Australia"" }, { - 'allowed': false, - 'auth_method': 'basic', - 'first_at': 1444087505, - 'ip': '1.2.3.48', - 'last_at': 1444087505, - 'location': 'Mukilteo, Washington' + ""allowed"": false, + ""auth_method"": ""basic"", + ""first_at"": 1444087505, + ""ip"": ""1.2.3.48"", + ""last_at"": 1444087505, + ""location"": ""Mukilteo, Washington"" } ] }"; - private const string SINGLE_WHITELISTED_IP_JSON = @"{ - 'id': 1, - 'ip': '192.168.1.1/32', - 'created_at': 1441824715, - 'updated_at': 1441824715 + internal const string SINGLE_WHITELISTED_IP_JSON = @"{ + ""id"": 1, + ""ip"": ""192.168.1.1/32"", + ""created_at"": 1441824715, + ""updated_at"": 1441824715 }"; - private const string MULTIPLE_WHITELISTED_IPS_JSON = @"{ - 'result': [ + internal const string MULTIPLE_WHITELISTED_IPS_JSON = @"{ + ""result"": [ { - 'id': 1, - 'ip': '192.168.1.1/32', - 'created_at': 1441824715, - 'updated_at': 1441824715 + ""id"": 1, + ""ip"": ""192.168.1.1/32"", + ""created_at"": 1441824715, + ""updated_at"": 1441824715 }, { - 'id': 2, - 'ip': '192.168.1.2/32', - 'created_at': 1441824715, - 'updated_at': 1441824715 + ""id"": 2, + ""ip"": ""192.168.1.2/32"", + ""created_at"": 1441824715, + ""updated_at"": 1441824715 }, { - 'id': 3, - 'ip': '192.168.1.3/32', - 'created_at': 1441824715, - 'updated_at': 1441824715 + ""id"": 3, + ""ip"": ""192.168.1.3/32"", + ""created_at"": 1441824715, + ""updated_at"": 1441824715 } ] }"; @@ -84,7 +84,7 @@ public void Parse_AccessEntry_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_ACCESS_ENTRY_JSON); + var result = JsonSerializer.Deserialize(SINGLE_ACCESS_ENTRY_JSON); // Assert result.ShouldNotBeNull(); @@ -102,7 +102,7 @@ public void Parse_WhitelistedIp_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_WHITELISTED_IP_JSON); + var result = JsonSerializer.Deserialize(SINGLE_WHITELISTED_IP_JSON); // Assert result.ShouldNotBeNull(); @@ -241,7 +241,7 @@ public async Task GetWhitelistedIpAddressAsync() // Arrange var id = 1111; - var apiResponse = "{'result':" + SINGLE_WHITELISTED_IP_JSON + "}"; + var apiResponse = "{\"result\":" + SINGLE_WHITELISTED_IP_JSON + "}"; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri(ENDPOINT, "whitelist", id)).Respond("application/json", apiResponse); diff --git a/Source/StrongGrid.UnitTests/Resources/AlertsTests.cs b/Source/StrongGrid.UnitTests/Resources/AlertsTests.cs index 00361e4a..da2ea951 100644 --- a/Source/StrongGrid.UnitTests/Resources/AlertsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/AlertsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,40 +16,40 @@ public class AlertsTests { #region FIELDS - private const string ENDPOINT = "alerts"; + internal const string ENDPOINT = "alerts"; - private const string SINGLE_ALERT_JSON = @"{ - 'created_at': 1451520930, - 'email_to': 'test@example.com', - 'frequency': 'daily', - 'id': 48, - 'type': 'stats_notification', - 'updated_at': 1451520930 + internal const string SINGLE_ALERT_JSON = @"{ + ""created_at"": 1451520930, + ""email_to"": ""test@example.com"", + ""frequency"": ""daily"", + ""id"": 48, + ""type"": ""stats_notification"", + ""updated_at"": 1451520930 }"; - private const string MULTIPLE_ALERTS_JSON = @"[ + internal const string MULTIPLE_ALERTS_JSON = @"[ { - 'created_at': 1451498784, - 'email_to': 'test@example.com', - 'id': 46, - 'percentage': 90, - 'type': 'usage_limit', - 'updated_at': 1451498784 + ""created_at"": 1451498784, + ""email_to"": ""test@example.com"", + ""id"": 46, + ""percentage"": 90, + ""type"": ""usage_limit"", + ""updated_at"": 1451498784 }, { - 'created_at': 1451498812, - 'email_to': 'test@example.com', - 'frequency': 'monthly', - 'id': 47, - 'type': 'stats_notification', - 'updated_at': 1451498812 + ""created_at"": 1451498812, + ""email_to"": ""test@example.com"", + ""frequency"": ""monthly"", + ""id"": 47, + ""type"": ""stats_notification"", + ""updated_at"": 1451498812 }, { - 'created_at': 1451520930, - 'email_to': 'test@example.com', - 'frequency': 'daily', - 'id': 48, - 'type': 'stats_notification', - 'updated_at': 1451520930 + ""created_at"": 1451520930, + ""email_to"": ""test@example.com"", + ""frequency"": ""daily"", + ""id"": 48, + ""type"": ""stats_notification"", + ""updated_at"": 1451520930 } ]"; @@ -61,7 +61,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_ALERT_JSON); + var result = JsonSerializer.Deserialize(SINGLE_ALERT_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs index 1f0ba57f..41e0b7e4 100644 --- a/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/ApiKeysTests.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,27 +15,27 @@ public class ApiKeysTests { #region FIELDS - private const string ENDPOINT = "api_keys"; + internal const string ENDPOINT = "api_keys"; - private const string SINGLE_API_KEY_JSON = @"{ - 'api_key': 'SG.xxxxxxxx.yyyyyyyy', - 'api_key_id': 'xxxxxxxx', - 'name': 'My API Key', - 'scopes': [ - 'mail.send', - 'alerts.create', - 'alerts.read' + internal const string SINGLE_API_KEY_JSON = @"{ + ""api_key"": ""SG.xxxxxxxx.yyyyyyyy"", + ""api_key_id"": ""xxxxxxxx"", + ""name"": ""My API Key"", + ""scopes"": [ + ""mail.send"", + ""alerts.create"", + ""alerts.read"" ] }"; - private const string MULTIPLE_API_KEY_JSON = @"{ - 'result': [ + internal const string MULTIPLE_API_KEY_JSON = @"{ + ""result"": [ { - 'name': 'A New Hope', - 'api_key_id': 'xxxxxxxx' + ""name"": ""A New Hope"", + ""api_key_id"": ""xxxxxxxx"" }, { - 'name': 'Another key', - 'api_key_id': 'yyyyyyyy' + ""name"": ""Another key"", + ""api_key_id"": ""yyyyyyyy"" } ] }"; @@ -48,7 +48,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_API_KEY_JSON); + var result = JsonSerializer.Deserialize(SINGLE_API_KEY_JSON); // Assert result.ShouldNotBeNull(); @@ -214,10 +214,10 @@ public async Task CreateWithAllPermissionsAsync() // Arrange var name = "My API Key with all permissions"; var userScopesJson = @"{ - 'scopes': [ - 'aaa', - 'bbb', - 'ccc' + ""scopes"": [ + ""aaa"", + ""bbb"", + ""ccc"" ] }"; @@ -243,10 +243,10 @@ public async Task CreateWithReadOnlyPermissionsAsync() // Arrange var name = "My API Key with read-only permissions"; var userScopesJson = @"{ - 'scopes': [ - 'aaa', - 'bbb', - 'ccc' + ""scopes"": [ + ""aaa"", + ""bbb"", + ""ccc"" ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/BatchesTests.cs b/Source/StrongGrid.UnitTests/Resources/BatchesTests.cs index 6dd9f1a2..abaddd10 100644 --- a/Source/StrongGrid.UnitTests/Resources/BatchesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/BatchesTests.cs @@ -13,29 +13,29 @@ public class BatchesTests { #region FIELDS - private const string ENDPOINT = "mail/batch"; + internal const string ENDPOINT = "mail/batch"; - private const string SINGLE_BATCH_JSON = @"{ - 'batch_id': 'BATCH_ID_1', - 'status': 'cancel' + internal const string SINGLE_BATCH_JSON = @"{ + ""batch_id"": ""BATCH_ID_1"", + ""status"": ""cancel"" }"; - private const string MULTIPLE_BATCHES_JSON = @"[ + internal const string MULTIPLE_BATCHES_JSON = @"[ { - 'batch_id': 'BATCH_ID_1', - 'status': 'cancel' + ""batch_id"": ""BATCH_ID_1"", + ""status"": ""cancel"" }, { - 'batch_id': 'BATCH_ID_2', - 'status': 'pause' + ""batch_id"": ""BATCH_ID_2"", + ""status"": ""pause"" } ]"; - private const string MULTIPLE_BATCHES_SINGLE_ITEM_JSON = @"[ + internal const string MULTIPLE_BATCHES_SINGLE_ITEM_JSON = @"[ { - 'batch_id': 'BATCH_ID_1', - 'status': 'cancel' + ""batch_id"": ""BATCH_ID_1"", + ""status"": ""cancel"" } ]"; - private const string EMPTY_BATCHES_JSON = @"[ + internal const string EMPTY_BATCHES_JSON = @"[ ]"; #endregion @@ -66,7 +66,7 @@ public async Task ValidateBatchIdAsync_true() var batchId = "ABC123"; var apiResponse = @"{ - 'batch_id': 'ABC123' + ""batch_id"": ""ABC123"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -91,10 +91,10 @@ public async Task ValidateBatchIdAsync_false() var batchId = "ABC123"; var apiResponse = @"{ - 'errors': [ + ""errors"": [ { - 'field': null, - 'message': 'invalid batch id' + ""field"": null, + ""message"": ""invalid batch id"" } ] }"; @@ -121,10 +121,10 @@ public async Task ValidateBatchIdAsync_problem() var batchId = "ABC123"; var apiResponse = @"{ - 'errors': [ + ""errors"": [ { - 'field': null, - 'message': 'an error has occurred' + ""field"": null, + ""message"": ""an error has occurred"" } ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs b/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs index a046dc39..9e02340c 100644 --- a/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/BlocksTests.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,20 +15,20 @@ public class BlocksTests { #region FIELDS - private const string ENDPOINT = "suppression/blocks"; + internal const string ENDPOINT = "suppression/blocks"; - private const string SINGLE_BLOCK_JSON = @"{ - 'created': 1443651154, - 'email': 'user1@example.com', - 'reason': 'error dialing remote address: dial tcp 10.57.152.165:25: no route to host', - 'status': '4.0.0' + internal const string SINGLE_BLOCK_JSON = @"{ + ""created"": 1443651154, + ""email"": ""user1@example.com"", + ""reason"": ""error dialing remote address: dial tcp 10.57.152.165:25: no route to host"", + ""status"": ""4.0.0"" }"; - private const string MULTIPLE_BLOCKS_JSON = @"[ + internal const string MULTIPLE_BLOCKS_JSON = @"[ { - 'created': 1443651154, - 'email': 'user1@example.com', - 'reason': 'error dialing remote address: dial tcp 10.57.152.165:25: no route to host', - 'status': '4.0.0' + ""created"": 1443651154, + ""email"": ""user1@example.com"", + ""reason"": ""error dialing remote address: dial tcp 10.57.152.165:25: no route to host"", + ""status"": ""4.0.0"" } ]"; @@ -40,7 +40,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_BLOCK_JSON); + var result = JsonSerializer.Deserialize(SINGLE_BLOCK_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/BouncesTests.cs b/Source/StrongGrid.UnitTests/Resources/BouncesTests.cs index 0e33f8a4..d867f7eb 100644 --- a/Source/StrongGrid.UnitTests/Resources/BouncesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/BouncesTests.cs @@ -1,12 +1,11 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; -using StrongGrid.Utilities; using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -17,26 +16,26 @@ public class BouncesTests { #region FIELDS - private const string ENDPOINT = "suppression/bounces"; + internal const string ENDPOINT = "suppression/bounces"; - private const string SINGLE_BOUNCE_JSON = @"{ - 'created': 1443651125, - 'email': 'testemail1@test.com', - 'reason': '550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp ', - 'status': '5.1.1' + internal const string SINGLE_BOUNCE_JSON = @"{ + ""created"": 1443651125, + ""email"": ""testemail1@test.com"", + ""reason"": ""550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp "", + ""status"": ""5.1.1"" }"; - private const string MULTIPLE_BOUNCES_JSON = @"[ + internal const string MULTIPLE_BOUNCES_JSON = @"[ { - 'created': 1443651125, - 'email': 'testemail1@test.com', - 'reason': '550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp ', - 'status': '5.1.1' + ""created"": 1443651125, + ""email"": ""testemail1@test.com"", + ""reason"": ""550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/answer/6596 o186si2389584ioe.63 - gsmtp "", + ""status"": ""5.1.1"" }, { - 'created': 1433800303, - 'email': 'testemail2@testing.com', - 'reason': '550 5.1.1 : Recipient address rejected: User unknown in virtual alias table ', - 'status': '5.1.1' + ""created"": 1433800303, + ""email"": ""testemail2@testing.com"", + ""reason"": ""550 5.1.1 : Recipient address rejected: User unknown in virtual alias table "", + ""status"": ""5.1.1"" } ]"; @@ -48,7 +47,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_BOUNCE_JSON); + var result = JsonSerializer.Deserialize(SINGLE_BOUNCE_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/CampaignsTests.cs b/Source/StrongGrid.UnitTests/Resources/CampaignsTests.cs index 2ed38246..a0414f95 100644 --- a/Source/StrongGrid.UnitTests/Resources/CampaignsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/CampaignsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models.Legacy; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,75 +16,75 @@ public class CampaignsTests { #region FIELDS - private const string ENDPOINT = "campaigns"; + internal const string ENDPOINT = "campaigns"; - private const string SINGLE_CAMPAIGN_JSON = @"{ - 'id': 986724, - 'title': 'March Newsletter', - 'subject': 'New Products for Spring!', - 'sender_id': 124451, - 'list_ids': [ + internal const string SINGLE_CAMPAIGN_JSON = @"{ + ""id"": 986724, + ""title"": ""March Newsletter"", + ""subject"": ""New Products for Spring!"", + ""sender_id"": 124451, + ""list_ids"": [ 110, 124 ], - 'segment_ids': [ + ""segment_ids"": [ 110 ], - 'categories': [ - 'spring line' + ""categories"": [ + ""spring line"" ], - 'suppression_group_id': 42, - 'custom_unsubscribe_url': '', - 'ip_pool': 'marketing', - 'html_content': '

Check out our spring line!

', - 'plain_content': 'Check out our spring line!', - 'status': 'Draft' + ""suppression_group_id"": 42, + ""custom_unsubscribe_url"": """", + ""ip_pool"": ""marketing"", + ""html_content"": ""

Check out our spring line!

"", + ""plain_content"": ""Check out our spring line!"", + ""status"": ""Draft"" }"; - private const string MULTIPLE_CAMPAIGNS_JSON = @"{ - 'result': [ + internal const string MULTIPLE_CAMPAIGNS_JSON = @"{ + ""result"": [ { - 'id': 986724, - 'title': 'March Newsletter', - 'subject': 'New Products for Spring!', - 'sender_id': 124451, - 'list_ids': [ + ""id"": 986724, + ""title"": ""March Newsletter"", + ""subject"": ""New Products for Spring!"", + ""sender_id"": 124451, + ""list_ids"": [ 110, 124 ], - 'segment_ids': [ + ""segment_ids"": [ 110 ], - 'categories': [ - 'spring line' + ""categories"": [ + ""spring line"" ], - 'suppression_group_id': 42, - 'custom_unsubscribe_url': '', - 'ip_pool': 'marketing', - 'html_content': '

Check out our spring line!

', - 'plain_content': 'Check out our spring line!', - 'status': 'Draft' + ""suppression_group_id"": 42, + ""custom_unsubscribe_url"": """", + ""ip_pool"": ""marketing"", + ""html_content"": ""

Check out our spring line!

"", + ""plain_content"": ""Check out our spring line!"", + ""status"": ""Draft"" }, { - 'id': 986723, - 'title': 'February Newsletter', - 'subject': 'Final Winter Product Sale!', - 'sender_id': 124451, - 'list_ids': [ + ""id"": 986723, + ""title"": ""February Newsletter"", + ""subject"": ""Final Winter Product Sale!"", + ""sender_id"": 124451, + ""list_ids"": [ 110, 124 ], - 'segment_ids': [ + ""segment_ids"": [ 110 ], - 'categories': [ - 'winter line' + ""categories"": [ + ""winter line"" ], - 'suppression_group_id': 42, - 'custom_unsubscribe_url': '', - 'ip_pool': 'marketing', - 'html_content': '

Last call for winter clothes!

', - 'plain_content': 'Last call for winter clothes!', - 'status': 'Sent' + ""suppression_group_id"": 42, + ""custom_unsubscribe_url"": """", + ""ip_pool"": ""marketing"", + ""html_content"": ""

Last call for winter clothes!

"", + ""plain_content"": ""Last call for winter clothes!"", + ""status"": ""Sent"" } ] }"; @@ -97,7 +97,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_CAMPAIGN_JSON); + var result = JsonSerializer.Deserialize(SINGLE_CAMPAIGN_JSON); // Assert result.ShouldNotBeNull(); @@ -236,8 +236,8 @@ public async Task SendNowAsync() var campaignId = 986724; var apiResponse = @"{ - 'id': 986724, - 'status': 'Scheduled' + ""id"": 986724, + ""status"": ""Scheduled"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -262,9 +262,9 @@ public async Task ScheduleAsync() var sendOn = DateTime.UtcNow.AddHours(5); var apiResponse = @"{ - 'id': 986724, - 'send_at': 1489771528, - 'status': 'Scheduled' + ""id"": 986724, + ""send_at"": 1489771528, + ""status"": ""Scheduled"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -289,9 +289,9 @@ public async Task RescheduleAsync() var sendOn = DateTime.UtcNow.AddHours(15); var apiResponse = @"{ - 'id': 986724, - 'send_at': 1489451436, - 'status': 'Scheduled' + ""id"": 986724, + ""send_at"": 1489451436, + ""status"": ""Scheduled"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -314,7 +314,7 @@ public async Task GetScheduledDateAsync() // Arrange var campaignId = 986724; var apiResponse = @"{ - 'send_at': 1489771528 + ""send_at"": 1489771528 }"; var mockHttp = new MockHttpMessageHandler(); diff --git a/Source/StrongGrid.UnitTests/Resources/DesignsTests.cs b/Source/StrongGrid.UnitTests/Resources/DesignsTests.cs index 13be6b02..5933397c 100644 --- a/Source/StrongGrid.UnitTests/Resources/DesignsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/DesignsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,55 +16,55 @@ public class DesignsTests { #region FIELDS - private const string ENDPOINT = "designs"; - - private const string SINGLE_DESIGN_JSON = @"{ - 'id':'4fa4db1f-219e-4599-8239-05dde4404611', - 'name':'This is my name', - 'html_content':'This is a test', - 'plain_content':'This is a test', - 'generate_plain_content':true, - 'thumbnail_url':'//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png', - 'subject':'This is the subject', - 'created_at':'2019-12-24T20:14:41Z', - 'updated_at':'2019-12-24T20:15:22Z', - 'editor':'code', - 'categories':['one','two','three'] + internal const string ENDPOINT = "designs"; + + internal const string SINGLE_DESIGN_JSON = @"{ + ""id"":""4fa4db1f-219e-4599-8239-05dde4404611"", + ""name"":""This is my name"", + ""html_content"":""This is a test"", + ""plain_content"":""This is a test"", + ""generate_plain_content"":true, + ""thumbnail_url"":""//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png"", + ""subject"":""This is the subject"", + ""created_at"":""2019-12-24T20:14:41Z"", + ""updated_at"":""2019-12-24T20:15:22Z"", + ""editor"":""code"", + ""categories"":[""one"",""two"",""three""] }"; - private const string MULTIPLE_DESIGNS_JSON = @"{ - 'result': [ + internal const string MULTIPLE_DESIGNS_JSON = @"{ + ""result"": [ { - 'id':'4fa4db1f-219e-4599-8239-05dde4404611', - 'name':'This is my name', - 'html_content':'This is a test', - 'plain_content':'This is a test', - 'generate_plain_content':true, - 'thumbnail_url':'//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png', - 'subject':'This is the subject', - 'created_at':'2019-12-24T20:14:41Z', - 'updated_at':'2019-12-24T20:15:22Z', - 'editor':'code', - 'categories':['one','two','three'] + ""id"":""4fa4db1f-219e-4599-8239-05dde4404611"", + ""name"":""This is my name"", + ""html_content"":""This is a test"", + ""plain_content"":""This is a test"", + ""generate_plain_content"":true, + ""thumbnail_url"":""//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png"", + ""subject"":""This is the subject"", + ""created_at"":""2019-12-24T20:14:41Z"", + ""updated_at"":""2019-12-24T20:15:22Z"", + ""editor"":""code"", + ""categories"":[""one"",""two"",""three""] }, { - 'id':'another_key', - 'name':'Another name', - 'html_content':'This is another test', - 'plain_content':'This is another test', - 'generate_plain_content':true, - 'thumbnail_url':'//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png', - 'subject':'This is the other subject', - 'created_at':'2019-12-24T20:14:41Z', - 'updated_at':'2019-12-24T20:15:22Z', - 'editor':'code', - 'categories':['four','five'] + ""id"":""another_key"", + ""name"":""Another name"", + ""html_content"":""This is another test"", + ""plain_content"":""This is another test"", + ""generate_plain_content"":true, + ""thumbnail_url"":""//us-east-2-production-thumbnail-bucket.s3.amazonaws.com/a6d262cec2588fe05c894ea162f8a1f26d91f37fe7fa412f2c3ecf091d14d60b.png"", + ""subject"":""This is the other subject"", + ""created_at"":""2019-12-24T20:14:41Z"", + ""updated_at"":""2019-12-24T20:15:22Z"", + ""editor"":""code"", + ""categories"":[""four"",""five""] } ], - '_metadata':{ - 'prev':'https://api.sendgrid.com/v3/designs?page_token=prev_token', - 'self':'https://api.sendgrid.com/v3/designs?page_token=self_token', - 'next':'https://api.sendgrid.com/v3/designs?page_token=next_token', - 'count':5 + ""_metadata"":{ + ""prev"":""https://api.sendgrid.com/v3/designs?page_token=prev_token"", + ""self"":""https://api.sendgrid.com/v3/designs?page_token=self_token"", + ""next"":""https://api.sendgrid.com/v3/designs?page_token=next_token"", + ""count"":5 } }"; @@ -76,7 +76,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_DESIGN_JSON); + var result = JsonSerializer.Deserialize(SINGLE_DESIGN_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/EmailActivitiesTests.cs b/Source/StrongGrid.UnitTests/Resources/EmailActivitiesTests.cs index ef4c0c1c..6845d26a 100644 --- a/Source/StrongGrid.UnitTests/Resources/EmailActivitiesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/EmailActivitiesTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -8,6 +7,7 @@ using System; using System.Collections.Generic; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -18,22 +18,22 @@ public class EmailActivitiesTests { #region FIELDS - private const string ENDPOINT = "messages"; - - private const string SINGLE_MESSAGE = @"{ - 'from_email': 'test@example.com', - 'msg_id': 'thtIPCIcR_iFZDws2JCrwA.filter0004p3las1-2776-5ACA5525-31.1', - 'subject': 'Dear customer', - 'to_email': 'bob@example.com', - 'status': 'delivered', - 'opens_count': 2, - 'clicks_count': 1, - 'last_event_time': '2018-04-08T17:47:18Z' + internal const string ENDPOINT = "messages"; + + internal const string SINGLE_MESSAGE = @"{ + ""from_email"": ""test@example.com"", + ""msg_id"": ""thtIPCIcR_iFZDws2JCrwA.filter0004p3las1-2776-5ACA5525-31.1"", + ""subject"": ""Dear customer"", + ""to_email"": ""bob@example.com"", + ""status"": ""delivered"", + ""opens_count"": 2, + ""clicks_count"": 1, + ""last_event_time"": ""2018-04-08T17:47:18Z"" }"; - private const string NO_MESSAGES_FOUND = "{'messages':[]}"; - private const string ONE_MESSAGE_FOUND = "{'messages':[" + SINGLE_MESSAGE + "]}"; - private const string MULTIPLE_MESSAGES_FOUND = "{'messages':[" + + internal const string NO_MESSAGES_FOUND = "{\"messages\":[]}"; + internal const string ONE_MESSAGE_FOUND = "{\"messages\":[" + SINGLE_MESSAGE + "]}"; + internal const string MULTIPLE_MESSAGES_FOUND = "{\"messages\":[" + SINGLE_MESSAGE + "," + SINGLE_MESSAGE + "," + SINGLE_MESSAGE + @@ -47,7 +47,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_MESSAGE); + var result = JsonSerializer.Deserialize(SINGLE_MESSAGE); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/EmailValidationTests.cs b/Source/StrongGrid.UnitTests/Resources/EmailValidationTests.cs index 878d6682..53d37c88 100644 --- a/Source/StrongGrid.UnitTests/Resources/EmailValidationTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/EmailValidationTests.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -14,55 +14,55 @@ public class EmailValidationTests { #region FIELDS - private const string ENDPOINT = "validations/email"; - - private const string INVALID_EMAIL_RESPONSE = @"{ - 'email': 'john.doe@gmial.com', - 'verdict': 'Invalid', - 'score': 0.00089, - 'local': 'john.doe', - 'host': 'gmial.com', - 'suggestion': 'gmail.com', - 'checks': { - 'domain': { - 'has_valid_address_syntax': true, - 'has_mx_or_a_record': true, - 'is_suspected_disposable_address': false + internal const string ENDPOINT = "validations/email"; + + internal const string INVALID_EMAIL_JSON = @"{ + ""email"": ""john.doe@gmial.com"", + ""verdict"": ""Invalid"", + ""score"": 0.00089, + ""local"": ""john.doe"", + ""host"": ""gmial.com"", + ""suggestion"": ""gmail.com"", + ""checks"": { + ""domain"": { + ""has_valid_address_syntax"": true, + ""has_mx_or_a_record"": true, + ""is_suspected_disposable_address"": false }, - 'local_part': { - 'is_suspected_role_address': false + ""local_part"": { + ""is_suspected_role_address"": false }, - 'additional': { - 'has_known_bounces': false, - 'has_suspected_bounces': true + ""additional"": { + ""has_known_bounces"": false, + ""has_suspected_bounces"": true } }, - 'ip_address': '123.45.67.89' + ""ip_address"": ""123.45.67.89"" }"; - private const string VALID_EMAIL_RESPONSE = @"{ - 'email': 'valid_email_address@mtsg.me', - 'verdict': 'Valid', - 'score': 0.93357, - 'local': 'valid_email_address', - 'host': 'mtsg.me', - 'checks': { - 'domain': { - 'has_valid_address_syntax': true, - 'has_mx_or_a_record': true, - 'is_suspected_disposable_address': false + internal const string VALID_EMAIL_JSON = @"{ + ""email"": ""valid_email_address@mtsg.me"", + ""verdict"": ""Valid"", + ""score"": 0.93357, + ""local"": ""valid_email_address"", + ""host"": ""mtsg.me"", + ""checks"": { + ""domain"": { + ""has_valid_address_syntax"": true, + ""has_mx_or_a_record"": true, + ""is_suspected_disposable_address"": false }, - 'local_part': { - 'is_suspected_role_address': false + ""local_part"": { + ""is_suspected_role_address"": false }, - 'additional': { - 'has_known_bounces': false, - 'has_suspected_bounces': false + ""additional"": { + ""has_known_bounces"": false, + ""has_suspected_bounces"": false } }, - 'source': 'TEST', - 'ip_address': '123.123.123.123' + ""source"": ""TEST"", + ""ip_address"": ""123.123.123.123"" }"; #endregion @@ -73,7 +73,7 @@ public void Parse_invalid_email_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(INVALID_EMAIL_RESPONSE); + var result = JsonSerializer.Deserialize(INVALID_EMAIL_JSON); // Assert result.ShouldNotBeNull(); @@ -104,7 +104,7 @@ public void Parse_valid_email_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(VALID_EMAIL_RESPONSE); + var result = JsonSerializer.Deserialize(VALID_EMAIL_JSON); // Assert result.ShouldNotBeNull(); @@ -132,7 +132,7 @@ public void Parse_valid_email_json() public async Task ValidateAsync() { // Arrange - var apiResponse = "{'result':" + VALID_EMAIL_RESPONSE + "}"; + var apiResponse = "{\"result\":" + VALID_EMAIL_JSON + "}"; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Post, Utils.GetSendGridApiUri(ENDPOINT)).Respond("application/json", apiResponse); diff --git a/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs b/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs index c94ad2b8..14f9b161 100644 --- a/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/GlobalSuppressionTests.cs @@ -13,19 +13,19 @@ public class GlobalSuppressionTests { #region FIELDS - private const string ENDPOINT = "asm/suppressions/global"; - private const string GLOBALLY_UNSUBSCRIBED = @"[ + internal const string ENDPOINT = "asm/suppressions/global"; + internal const string GLOBALLY_UNSUBSCRIBED = @"[ { - 'email': 'example@bogus.com', - 'created': 1422313607 + ""email"": ""example@bogus.com"", + ""created"": 1422313607 }, { - 'email': 'bogus@example.com', - 'created': 1422313607 + ""email"": ""bogus@example.com"", + ""created"": 1422313607 }, { - 'email': 'invalid@somewhere.com', - 'created': 1422313607 + ""email"": ""invalid@somewhere.com"", + ""created"": 1422313607 } ]"; @@ -57,9 +57,9 @@ public async Task AddAsync() // Arrange var emails = new[] { "test1@example.com", "test2@example.com" }; var apiResponse = @"{ - 'recipient_emails': [ - 'test1@example.com', - 'test2@example.com' + ""recipient_emails"": [ + ""test1@example.com"", + ""test2@example.com"" ] }"; @@ -104,7 +104,7 @@ public async Task IsUnsubscribedAsync_true() var email = "test1@example.com"; var apiResponse = @"{ - 'recipient_email': 'test1@example.com' + ""recipient_email"": ""test1@example.com"" }"; var mockHttp = new MockHttpMessageHandler(); diff --git a/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs b/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs index 11057953..2d797fcb 100644 --- a/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/InvalidEmailsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,23 +16,23 @@ public class InvalidEmailsTests { #region FIELDS - private const string ENDPOINT = "suppression/invalid_emails"; + internal const string ENDPOINT = "suppression/invalid_emails"; - private const string SINGLE_INVALID_EMAIL_JSON = @"{ - 'created': 1454433146, - 'email': 'test1@example.com', - 'reason': 'Mail domain mentioned in email address is unknown' + internal const string SINGLE_INVALID_EMAIL_JSON = @"{ + ""created"": 1454433146, + ""email"": ""test1@example.com"", + ""reason"": ""Mail domain mentioned in email address is unknown"" }"; - private const string MULTIPLE_INVALID_EMAILS_JSON = @"[ + internal const string MULTIPLE_INVALID_EMAILS_JSON = @"[ { - 'created': 1449953655, - 'email': 'user1@example.com', - 'reason': 'Mail domain mentioned in email address is unknown' + ""created"": 1449953655, + ""email"": ""user1@example.com"", + ""reason"": ""Mail domain mentioned in email address is unknown"" }, { - 'created': 1449939373, - 'email': 'user1@example.com', - 'reason': 'Mail domain mentioned in email address is unknown' + ""created"": 1449939373, + ""email"": ""user1@example.com"", + ""reason"": ""Mail domain mentioned in email address is unknown"" } ]"; @@ -44,7 +44,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_INVALID_EMAIL_JSON); + var result = JsonSerializer.Deserialize(SINGLE_INVALID_EMAIL_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs b/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs index e0dcc2dc..456884bd 100644 --- a/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/IpAddressesTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,35 +16,35 @@ public class IpAddressesTests { #region FIELDS - private const string ENDPOINT = "ips"; + internal const string ENDPOINT = "ips"; - private const string SINGLE_ASSIGNED_IPADDRESS_JSON = @"{ - 'ip': '192.168.1.1', - 'pools': [ - 'pool1', - 'pool2' + internal const string SINGLE_ASSIGNED_IPADDRESS_JSON = @"{ + ""ip"": ""192.168.1.1"", + ""pools"": [ + ""pool1"", + ""pool2"" ], - 'whitelabeled': false, - 'start_date': 1409616000, - 'subusers': [ - 'tim@sendgrid.net' + ""whitelabeled"": false, + ""start_date"": 1409616000, + ""subusers"": [ + ""tim@sendgrid.net"" ], - 'warmup': false, - 'assigned_at': 1482883200 + ""warmup"": false, + ""assigned_at"": 1482883200 }"; - private const string SINGLE_UNASSIGNED_IPADDRESS_JSON = @"{ - 'ip': '208.115.214.22', - 'pools': [], - 'whitelabeled': true, - 'rdns': 'o1.email.burgermail.com', - 'start_date': 1409616000, - 'subusers': [], - 'warmup': false, - 'assigned_at': 1482883200 + internal const string SINGLE_UNASSIGNED_IPADDRESS_JSON = @"{ + ""ip"": ""208.115.214.22"", + ""pools"": [], + ""whitelabeled"": true, + ""rdns"": ""o1.email.burgermail.com"", + ""start_date"": 1409616000, + ""subusers"": [], + ""warmup"": false, + ""assigned_at"": 1482883200 }"; - private const string MULTIPLE_IPADDRESSES_JSON = "[" + + internal const string MULTIPLE_IPADDRESSES_JSON = "[" + SINGLE_ASSIGNED_IPADDRESS_JSON + "," + SINGLE_UNASSIGNED_IPADDRESS_JSON + "]"; @@ -57,7 +57,7 @@ public void Parse_single_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_ASSIGNED_IPADDRESS_JSON); + var result = JsonSerializer.Deserialize(SINGLE_ASSIGNED_IPADDRESS_JSON); // Assert result.ShouldNotBeNull(); @@ -80,7 +80,7 @@ public void Parse_multiple_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(MULTIPLE_IPADDRESSES_JSON); + var result = JsonSerializer.Deserialize(MULTIPLE_IPADDRESSES_JSON); // Assert result.ShouldNotBeNull(); @@ -101,14 +101,14 @@ public async Task AddAsync() { // Arrange var apiResponse = @"{ - 'ips': [ + ""ips"": [ { - 'ip': '1.2.3.4', - 'subusers': [ 'jdesautels' ] + ""ip"": ""1.2.3.4"", + ""subusers"": [ ""jdesautels"" ] } ], - 'remaining_ips':2, - 'warmup': false + ""remaining_ips"":2, + ""warmup"": false }"; var mockHttp = new MockHttpMessageHandler(); @@ -136,11 +136,11 @@ public async Task GetRemainingCountAsync() { // Arrange var apiResponse = @"{ - 'results': [ + ""results"": [ { - 'remaining': 2, - 'period': 'month', - 'price_per_ip': 20 + ""remaining"": 2, + ""period"": ""month"", + ""price_per_ip"": 20 } ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/IpPoolsTests.cs b/Source/StrongGrid.UnitTests/Resources/IpPoolsTests.cs index 49d8740a..32628d75 100644 --- a/Source/StrongGrid.UnitTests/Resources/IpPoolsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/IpPoolsTests.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,15 +15,15 @@ public class IpPoolsTests { #region FIELDS - private const string ENDPOINT = "ips/pools"; + internal const string ENDPOINT = "ips/pools"; - private const string SINGLE_IPPOOL_JSON = @"{ - 'pool_name': 'marketing', - 'ips': + internal const string SINGLE_IPPOOL_JSON = @"{ + ""pool_name"": ""marketing"", + ""ips"": [ - { 'ip': '1.1.1.1', 'start_date': null, 'warmup': false }, - { 'ip': '2.2.2.2', 'start_date': null, 'warmup': false }, - { 'ip': '3.3.3.3', 'start_date': null, 'warmup': false } + { ""ip"": ""1.1.1.1"", ""start_date"": null, ""warmup"": false }, + { ""ip"": ""2.2.2.2"", ""start_date"": null, ""warmup"": false }, + { ""ip"": ""3.3.3.3"", ""start_date"": null, ""warmup"": false } ] }"; @@ -35,7 +35,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_IPPOOL_JSON); + var result = JsonSerializer.Deserialize(SINGLE_IPPOOL_JSON); // Assert result.ShouldNotBeNull(); @@ -53,7 +53,7 @@ public async Task CreateAsync() var name = "marketing"; var apiResponse = @"{ - 'name': 'marketing' + ""name"": ""marketing"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -78,10 +78,10 @@ public async Task GetAllNamesAsync() // Arrange var apiResponse = @"[ { - 'name': 'marketing' + ""name"": ""marketing"" }, { - 'name': 'transactional' + ""name"": ""transactional"" } ]"; @@ -132,7 +132,7 @@ public async Task UpdateAsync() var newName = "New Name"; var apiResponse = @"{ - 'name': 'New Name' + ""name"": ""New Name"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -179,12 +179,12 @@ public async Task AddAdressAsync() var address = "0.0.0.0"; var apiResponse = @"{ - 'ip': '000.00.00.0', - 'pools': [ - 'test1' + ""ip"": ""000.00.00.0"", + ""pools"": [ + ""test1"" ], - 'start_date': 1409616000, - 'warmup': true + ""start_date"": 1409616000, + ""warmup"": true }"; var mockHttp = new MockHttpMessageHandler(); diff --git a/Source/StrongGrid.UnitTests/Resources/LegacyCategoriesTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacyCategoriesTests.cs index b2a0af72..4ad5fb45 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacyCategoriesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacyCategoriesTests.cs @@ -12,14 +12,14 @@ public class LegacyCategoriesTests { #region FIELDS - private const string ENDPOINT = "categories"; - - private const string MULTIPLE_CATEGORIES_JSON = @"[ - { 'category': 'cat1' }, - { 'category': 'cat2' }, - { 'category': 'cat3' }, - { 'category': 'cat4' }, - { 'category': 'cat5' } + internal const string ENDPOINT = "categories"; + + internal const string MULTIPLE_CATEGORIES_JSON = @"[ + { ""category"": ""cat1"" }, + { ""category"": ""cat2"" }, + { ""category"": ""cat3"" }, + { ""category"": ""cat4"" }, + { ""category"": ""cat5"" } ]"; #endregion diff --git a/Source/StrongGrid.UnitTests/Resources/LegacyContactsTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacyContactsTests.cs index 198ace2d..89b53583 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacyContactsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacyContactsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -7,6 +6,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -17,51 +17,51 @@ public class LegacyContactsTests { #region FIELDS - private const string ENDPOINT = "contactdb/recipients"; - - private const string SINGLE_RECIPIENT_JSON = @"{ - 'created_at': 1422313607, - 'email': 'jones@example.com', - 'first_name': null, - 'id': 'YUBh', - 'last_clicked': null, - 'last_emailed': null, - 'last_name': 'Jones', - 'last_opened': null, - 'updated_at': 1422313790, - 'custom_fields': [ + internal const string ENDPOINT = "contactdb/recipients"; + + internal const string SINGLE_RECIPIENT_JSON = @"{ + ""created_at"": 1422313607, + ""email"": ""jones@example.com"", + ""first_name"": null, + ""id"": ""YUBh"", + ""last_clicked"": null, + ""last_emailed"": null, + ""last_name"": ""Jones"", + ""last_opened"": null, + ""updated_at"": 1422313790, + ""custom_fields"": [ { - 'id': 23, - 'name': 'pet', - 'value': 'Indiana', - 'type': 'text' + ""id"": 23, + ""name"": ""pet"", + ""value"": ""Indiana"", + ""type"": ""text"" } ] }"; - private const string MULTIPLE_RECIPIENTS_JSON = @"{ - 'recipients': [ + internal const string MULTIPLE_RECIPIENTS_JSON = @"{ + ""recipients"": [ { - 'created_at': 1422313607, - 'email': 'jones@example.com', - 'first_name': null, - 'id': 'YUBh', - 'last_clicked': null, - 'last_emailed': null, - 'last_name': 'Jones', - 'last_opened': null, - 'updated_at': 1422313790, - 'custom_fields': [ + ""created_at"": 1422313607, + ""email"": ""jones@example.com"", + ""first_name"": null, + ""id"": ""YUBh"", + ""last_clicked"": null, + ""last_emailed"": null, + ""last_name"": ""Jones"", + ""last_opened"": null, + ""updated_at"": 1422313790, + ""custom_fields"": [ { - 'id': 23, - 'name': 'pet', - 'value': 'Indiana', - 'type': 'text' + ""id"": 23, + ""name"": ""pet"", + ""value"": ""Indiana"", + ""type"": ""text"" }, { - 'id': 24, - 'name': 'age', - 'value': '43', - 'type': 'number' + ""id"": 24, + ""name"": ""age"", + ""value"": ""43"", + ""type"": ""number"" } ] } @@ -76,7 +76,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_RECIPIENT_JSON); + var result = JsonSerializer.Deserialize(SINGLE_RECIPIENT_JSON); // Assert result.ShouldNotBeNull(); @@ -107,16 +107,16 @@ public async Task CreateAsync_success() var lastName = "Doe"; var apiResponse = @"{ - 'error_count': 0, - 'error_indices': [ + ""error_count"": 0, + ""error_indices"": [ ], - 'unmodified_indices': [ + ""unmodified_indices"": [ ], - 'new_count': 1, - 'persisted_recipients': [ - 'am9uZXNAZXhhbXBsZS5jb20=' + ""new_count"": 1, + ""persisted_recipients"": [ + ""am9uZXNAZXhhbXBsZS5jb20="" ], - 'updated_count': 0 + ""updated_count"": 0 }"; var mockHttp = new MockHttpMessageHandler(); @@ -143,16 +143,16 @@ public async Task CreateAsync_failure() var lastName = "Doe"; var apiResponse = @"{ - 'error_count': 1, - 'error_indices': [0], - 'unmodified_indices': [], - 'new_count': 0, - 'persisted_recipients': [], - 'updated_count': 0, - 'errors': [ + ""error_count"": 1, + ""error_indices"": [0], + ""unmodified_indices"": [], + ""new_count"": 0, + ""persisted_recipients"": [], + ""updated_count"": 0, + ""errors"": [ { - 'message': 'Invalid email.', - 'error_indices': [0] + ""message"": ""Invalid email."", + ""error_indices"": [0] } ] }"; @@ -185,23 +185,23 @@ public async Task ImportAsync() }; var apiResponse = @"{ - 'error_count': 1, - 'error_indices': [ + ""error_count"": 1, + ""error_indices"": [ 2 ], - 'unmodified_indices': [ + ""unmodified_indices"": [ 3 ], - 'new_count': 2, - 'persisted_recipients': [ - 'YUBh', - 'bWlsbGVyQG1pbGxlci50ZXN0' + ""new_count"": 2, + ""persisted_recipients"": [ + ""YUBh"", + ""bWlsbGVyQG1pbGxlci50ZXN0"" ], - 'updated_count': 0, - 'errors': [ + ""updated_count"": 0, + ""errors"": [ { - 'message': 'Invalid email.', - 'error_indices': [ + ""message"": ""Invalid email."", + ""error_indices"": [ 2 ] } @@ -239,17 +239,17 @@ public async Task UpdateAsync_success() var lastName = "Jones"; var apiResponse = @"{ - 'error_count': 0, - 'error_indices': [ + ""error_count"": 0, + ""error_indices"": [ ], - 'unmodified_indices': [ + ""unmodified_indices"": [ 1 ], - 'new_count': 0, - 'persisted_recipients': [ - 'am9uZXNAZXhhbXBsZS5jb20=' + ""new_count"": 0, + ""persisted_recipients"": [ + ""am9uZXNAZXhhbXBsZS5jb20="" ], - 'updated_count': 1 + ""updated_count"": 1 }"; var mockHttp = new MockHttpMessageHandler(); @@ -283,16 +283,16 @@ public async Task UpdateAsync_failure() var lastName = "Jones"; var apiResponse = @"{ - 'error_count': 1, - 'error_indices': [0], - 'unmodified_indices': [], - 'new_count': 0, - 'persisted_recipients': [], - 'updated_count': 0, - 'errors': [ + ""error_count"": 1, + ""error_indices"": [0], + ""unmodified_indices"": [], + ""new_count"": 0, + ""persisted_recipients"": [], + ""updated_count"": 0, + ""errors"": [ { - 'message': 'Invalid email.', - 'error_indices': [0] + ""message"": ""Invalid email."", + ""error_indices"": [0] } ] }"; @@ -413,7 +413,7 @@ public async Task GetBillableCountAsync() { // Arrange var apiResponse = @"{ - 'recipient_count': 2 + ""recipient_count"": 2 }"; var mockHttp = new MockHttpMessageHandler(); @@ -436,7 +436,7 @@ public async Task GetTotalCountAsync() { // Arrange var apiResponse = @"{ - 'recipient_count': 3 + ""recipient_count"": 3 }"; var mockHttp = new MockHttpMessageHandler(); @@ -484,29 +484,29 @@ public async Task SearchAsync() } }; var apiResponse = @"{ - 'recipients': [ + ""recipients"": [ { - 'created_at': 1422313607, - 'email': 'jones@example.com', - 'first_name': null, - 'id': 'YUBh', - 'last_clicked': 12345, - 'last_emailed': null, - 'last_name': 'Miller', - 'last_opened': null, - 'updated_at': 1422313790, - 'custom_fields': [ + ""created_at"": 1422313607, + ""email"": ""jones@example.com"", + ""first_name"": null, + ""id"": ""YUBh"", + ""last_clicked"": 12345, + ""last_emailed"": null, + ""last_name"": ""Miller"", + ""last_opened"": null, + ""updated_at"": 1422313790, + ""custom_fields"": [ { - 'id': 23, - 'name': 'pet', - 'value': 'Indiana', - 'type': 'text' + ""id"": 23, + ""name"": ""pet"", + ""value"": ""Indiana"", + ""type"": ""text"" }, { - 'id': 24, - 'name': 'age', - 'value': '43', - 'type': 'number' + ""id"": 24, + ""name"": ""age"", + ""value"": ""43"", + ""type"": ""number"" } ] } @@ -542,29 +542,29 @@ public async Task SearchAsync_without_conditions() var listId = (int?)null; var conditions = (SearchCondition[])null; var apiResponse = @"{ - 'recipients': [ + ""recipients"": [ { - 'created_at': 1422313607, - 'email': 'jones@example.com', - 'first_name': null, - 'id': 'YUBh', - 'last_clicked': 12345, - 'last_emailed': null, - 'last_name': 'Miller', - 'last_opened': null, - 'updated_at': 1422313790, - 'custom_fields': [ + ""created_at"": 1422313607, + ""email"": ""jones@example.com"", + ""first_name"": null, + ""id"": ""YUBh"", + ""last_clicked"": 12345, + ""last_emailed"": null, + ""last_name"": ""Miller"", + ""last_opened"": null, + ""updated_at"": 1422313790, + ""custom_fields"": [ { - 'id': 23, - 'name': 'pet', - 'value': 'Indiana', - 'type': 'text' + ""id"": 23, + ""name"": ""pet"", + ""value"": ""Indiana"", + ""type"": ""text"" }, { - 'id': 24, - 'name': 'age', - 'value': '43', - 'type': 'number' + ""id"": 24, + ""name"": ""age"", + ""value"": ""43"", + ""type"": ""number"" } ] } @@ -599,16 +599,16 @@ public async Task GetListsAsync() // Arrange var contactId = "YUBh"; var listsJson = @"{ - 'lists': [ + ""lists"": [ { - 'id': 1, - 'name': 'prospects', - 'recipient_count': 1 + ""id"": 1, + ""name"": ""prospects"", + ""recipient_count"": 1 }, { - 'id': 2, - 'name': 'customers', - 'recipient_count': 1 + ""id"": 2, + ""name"": ""customers"", + ""recipient_count"": 1 } ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/LegacyCustomFieldsTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacyCustomFieldsTests.cs index 3fe25bc0..dfce7301 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacyCustomFieldsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacyCustomFieldsTests.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources.Legacy; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,29 +15,29 @@ public class LegacyCustomFieldsTests { #region FIELDS - private const string ENDPOINT = "contactdb/custom_fields"; + internal const string ENDPOINT = "contactdb/custom_fields"; - private const string SINGLE_CUSTOM_FIELD_JSON = @"{ - 'id': 1, - 'name': 'customfield1', - 'type': 'text' + internal const string SINGLE_CUSTOM_FIELD_JSON = @"{ + ""id"": 1, + ""name"": ""customfield1"", + ""type"": ""text"" }"; - private const string MULTIPLE_CUSTOM_FIELDS_JSON = @"{ - 'custom_fields': [ + internal const string MULTIPLE_CUSTOM_FIELDS_JSON = @"{ + ""custom_fields"": [ { - 'id': 1, - 'name': 'birthday', - 'type': 'date' + ""id"": 1, + ""name"": ""birthday"", + ""type"": ""date"" }, { - 'id': 2, - 'name': 'middle_name', - 'type': 'text' + ""id"": 2, + ""name"": ""middle_name"", + ""type"": ""text"" }, { - 'id': 3, - 'name': 'favorite_number', - 'type': 'number' + ""id"": 3, + ""name"": ""favorite_number"", + ""type"": ""number"" } ] }"; @@ -50,7 +50,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_CUSTOM_FIELD_JSON); + var result = JsonSerializer.Deserialize(SINGLE_CUSTOM_FIELD_JSON); // Assert result.ShouldNotBeNull(); @@ -147,42 +147,42 @@ public async Task GetReservedFieldsAsync() { // Arrange var apiResponse = @"{ - 'reserved_fields': [ + ""reserved_fields"": [ { - 'name': 'first_name', - 'type': 'text' + ""name"": ""first_name"", + ""type"": ""text"" }, { - 'name': 'last_name', - 'type': 'text' + ""name"": ""last_name"", + ""type"": ""text"" }, { - 'name': 'email', - 'type': 'text' + ""name"": ""email"", + ""type"": ""text"" }, { - 'name': 'created_at', - 'type': 'date' + ""name"": ""created_at"", + ""type"": ""date"" }, { - 'name': 'updated_at', - 'type': 'date' + ""name"": ""updated_at"", + ""type"": ""date"" }, { - 'name': 'last_emailed', - 'type': 'date' + ""name"": ""last_emailed"", + ""type"": ""date"" }, { - 'name': 'last_clicked', - 'type': 'date' + ""name"": ""last_clicked"", + ""type"": ""date"" }, { - 'name': 'last_opened', - 'type': 'date' + ""name"": ""last_opened"", + ""type"": ""date"" }, { - 'name': 'my_custom_field', - 'type': 'text' + ""name"": ""my_custom_field"", + ""type"": ""text"" } ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/LegacyListsTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacyListsTests.cs index 2c6abb60..043f9fd4 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacyListsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacyListsTests.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Resources.Legacy; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -14,19 +14,19 @@ public class LegacyListsTests { #region FIELDS - private const string ENDPOINT = "contactdb/lists"; + internal const string ENDPOINT = "contactdb/lists"; - private const string SINGLE_LIST_JSON = @"{ - 'id': 1, - 'name': 'listname', - 'recipient_count': 0 + internal const string SINGLE_LIST_JSON = @"{ + ""id"": 1, + ""name"": ""listname"", + ""recipient_count"": 0 }"; - private const string MULTIPLE_LISTS_JSON = @"{ - 'lists': [ + internal const string MULTIPLE_LISTS_JSON = @"{ + ""lists"": [ { - 'id': 1, - 'name': 'the jones', - 'recipient_count': 1 + ""id"": 1, + ""name"": ""the jones"", + ""recipient_count"": 1 } ] }"; @@ -39,7 +39,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_LIST_JSON); + var result = JsonSerializer.Deserialize(SINGLE_LIST_JSON); // Assert result.ShouldNotBeNull(); @@ -180,17 +180,17 @@ public async Task GetRecipientsAsync() var page = 1; var apiResponse = @"{ - 'recipients': [ + ""recipients"": [ { - 'created_at': 1422395108, - 'email': 'e@example.com', - 'first_name': 'Ed', - 'id': 'YUBh', - 'last_clicked': null, - 'last_emailed': null, - 'last_name': null, - 'last_opened': null, - 'updated_at': 1422395108 + ""created_at"": 1422395108, + ""email"": ""e@example.com"", + ""first_name"": ""Ed"", + ""id"": ""YUBh"", + ""last_clicked"": null, + ""last_emailed"": null, + ""last_name"": null, + ""last_opened"": null, + ""updated_at"": 1422395108 } ] }"; diff --git a/Source/StrongGrid.UnitTests/Resources/LegacySegmentsTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacySegmentsTests.cs index a0ea0bae..5e25b140 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacySegmentsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacySegmentsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using StrongGrid.Resources.Legacy; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,48 +16,48 @@ public class LegacySegmentsTests { #region FIELDS - private const string ENDPOINT = "contactdb/segments"; + internal const string ENDPOINT = "contactdb/segments"; - private const string SINGLE_SEGMENT_JSON = @"{ - 'id': 1, - 'name': 'Last Name Miller', - 'list_id': 4, - 'conditions': [ + internal const string SINGLE_SEGMENT_JSON = @"{ + ""id"": 1, + ""name"": ""Last Name Miller"", + ""list_id"": 4, + ""conditions"": [ { - 'field': 'last_name', - 'value': 'Miller', - 'operator': 'eq', - 'and_or': '' + ""field"": ""last_name"", + ""value"": ""Miller"", + ""operator"": ""eq"", + ""and_or"": """" }, { - 'field': 'last_clicked', - 'value': '01/02/2015', - 'operator': 'gt', - 'and_or': 'and' + ""field"": ""last_clicked"", + ""value"": ""01/02/2015"", + ""operator"": ""gt"", + ""and_or"": ""and"" }, { - 'field': 'clicks.campaign_identifier', - 'value': '513', - 'operator': 'eq', - 'and_or': 'or' + ""field"": ""clicks.campaign_identifier"", + ""value"": ""513"", + ""operator"": ""eq"", + ""and_or"": ""or"" } ] }"; - private const string MULTIPLE_SEGMENTS_JSON = @"{ - 'segments': [ + internal const string MULTIPLE_SEGMENTS_JSON = @"{ + ""segments"": [ { - 'id': 1, - 'name': 'Last Name Miller', - 'list_id': 4, - 'conditions': [ + ""id"": 1, + ""name"": ""Last Name Miller"", + ""list_id"": 4, + ""conditions"": [ { - 'field': 'last_name', - 'value': 'Miller', - 'operator': 'eq', - 'and_or': '' + ""field"": ""last_name"", + ""value"": ""Miller"", + ""operator"": ""eq"", + ""and_or"": """" } ], - 'recipient_count': 1 + ""recipient_count"": 1 } ] }"; @@ -70,7 +70,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_SEGMENT_JSON); + var result = JsonSerializer.Deserialize(SINGLE_SEGMENT_JSON); // Assert result.ShouldNotBeNull(); @@ -268,23 +268,23 @@ public async Task GetRecipientsAsync() var page = 1; var apiResponse = @"{ - 'recipients': [ + ""recipients"": [ { - 'created_at': 1422313607, - 'email': 'jones@example.com', - 'first_name': null, - 'id': 'YUBh', - 'last_clicked': null, - 'last_emailed': null, - 'last_name': 'Jones', - 'last_opened': null, - 'updated_at': 1422313790, - 'custom_fields': [ + ""created_at"": 1422313607, + ""email"": ""jones@example.com"", + ""first_name"": null, + ""id"": ""YUBh"", + ""last_clicked"": null, + ""last_emailed"": null, + ""last_name"": ""Jones"", + ""last_opened"": null, + ""updated_at"": 1422313790, + ""custom_fields"": [ { - 'id': 23, - 'name': 'pet', - 'value': 'Indiana', - 'type': 'text' + ""id"": 23, + ""name"": ""pet"", + ""value"": ""Indiana"", + ""type"": ""text"" } ] } diff --git a/Source/StrongGrid.UnitTests/Resources/LegacySenderIdentitiesTests.cs b/Source/StrongGrid.UnitTests/Resources/LegacySenderIdentitiesTests.cs index 529a18dc..6b64336c 100644 --- a/Source/StrongGrid.UnitTests/Resources/LegacySenderIdentitiesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/LegacySenderIdentitiesTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,52 +16,52 @@ public class LegacySenderIdentitiesTests { #region FIELDS - private const string ENDPOINT = "senders"; + internal const string ENDPOINT = "senders"; - private const string SINGLE_SENDER_IDENTITY_JSON = @"{ - 'id': 1, - 'nickname': 'My Sender ID', - 'from': { - 'email': 'from@example.com', - 'name': 'Example INC' + internal const string SINGLE_SENDER_IDENTITY_JSON = @"{ + ""id"": 1, + ""nickname"": ""My Sender ID"", + ""from"": { + ""email"": ""from@example.com"", + ""name"": ""Example INC"" }, - 'reply_to': { - 'email': 'replyto@example.com', - 'name': 'Example INC' + ""reply_to"": { + ""email"": ""replyto@example.com"", + ""name"": ""Example INC"" }, - 'address': '123 Elm St.', - 'address_2': 'Apt. 456', - 'city': 'Denver', - 'state': 'Colorado', - 'zip': '80202', - 'country': 'United States', - 'verified': { 'status': true, 'reason': '' }, - 'updated_at': 1449872165, - 'created_at': 1449872165, - 'locked': false + ""address"": ""123 Elm St."", + ""address_2"": ""Apt. 456"", + ""city"": ""Denver"", + ""state"": ""Colorado"", + ""zip"": ""80202"", + ""country"": ""United States"", + ""verified"": { ""status"": true, ""reason"": """" }, + ""updated_at"": 1449872165, + ""created_at"": 1449872165, + ""locked"": false }"; - private const string MULTIPLE_SENDER_IDENTITIES_JSON = @"[ + internal const string MULTIPLE_SENDER_IDENTITIES_JSON = @"[ { - 'id': 1, - 'nickname': 'My Sender ID', - 'from': { - 'email': 'from@example.com', - 'name': 'Example INC' + ""id"": 1, + ""nickname"": ""My Sender ID"", + ""from"": { + ""email"": ""from@example.com"", + ""name"": ""Example INC"" }, - 'reply_to': { - 'email': 'replyto@example.com', - 'name': 'Example INC' + ""reply_to"": { + ""email"": ""replyto@example.com"", + ""name"": ""Example INC"" }, - 'address': '123 Elm St.', - 'address_2': 'Apt. 456', - 'city': 'Denver', - 'state': 'Colorado', - 'zip': '80202', - 'country': 'United States', - 'verified': { 'status': true, 'reason': '' }, - 'updated_at': 1449872165, - 'created_at': 1449872165, - 'locked': false + ""address"": ""123 Elm St."", + ""address_2"": ""Apt. 456"", + ""city"": ""Denver"", + ""state"": ""Colorado"", + ""zip"": ""80202"", + ""country"": ""United States"", + ""verified"": { ""status"": true, ""reason"": """" }, + ""updated_at"": 1449872165, + ""created_at"": 1449872165, + ""locked"": false } ]"; @@ -73,7 +73,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_SENDER_IDENTITY_JSON); + var result = JsonSerializer.Deserialize(SINGLE_SENDER_IDENTITY_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/MailTests.cs b/Source/StrongGrid.UnitTests/Resources/MailTests.cs index 616a4e09..ca082255 100644 --- a/Source/StrongGrid.UnitTests/Resources/MailTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/MailTests.cs @@ -19,7 +19,7 @@ public class MailTests { #region FIELDS - private const string ENDPOINT = "mail"; + internal const string ENDPOINT = "mail"; #endregion diff --git a/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs b/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs index 6e7377d6..979f17d1 100644 --- a/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SenderAuthenticationTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,281 +16,281 @@ public class SenderAuthenticationTests { #region FIELDS - private const string ENDPOINT = "whitelabel"; - - private const string SINGLE_DOMAIN_JSON = @"{ - 'id': 1, - 'domain': 'example.com', - 'subdomain': 'mail', - 'username': 'john@example.com', - 'user_id': 7, - 'ips': [ - '192.168.1.1', - '192.168.1.2' + internal const string ENDPOINT = "whitelabel"; + + internal const string SINGLE_DOMAIN_JSON = @"{ + ""id"": 1, + ""domain"": ""example.com"", + ""subdomain"": ""mail"", + ""username"": ""john@example.com"", + ""user_id"": 7, + ""ips"": [ + ""192.168.1.1"", + ""192.168.1.2"" ], - 'custom_spf': true, - 'default': true, - 'legacy': false, - 'automatic_security': true, - 'valid': true, - 'dns': { - 'mail_cname': { - 'host': 'mail.example.com', - 'type': 'cname', - 'data': 'u7.wl.sendgrid.net', - 'valid': true + ""custom_spf"": true, + ""default"": true, + ""legacy"": false, + ""automatic_security"": true, + ""valid"": true, + ""dns"": { + ""mail_cname"": { + ""host"": ""mail.example.com"", + ""type"": ""cname"", + ""data"": ""u7.wl.sendgrid.net"", + ""valid"": true }, - 'spf': { - 'host': 'example.com', - 'type': 'txt', - 'data': 'v=spf1 include:u7.wl.sendgrid.net -all', - 'valid': true + ""spf"": { + ""host"": ""example.com"", + ""type"": ""txt"", + ""data"": ""v=spf1 include:u7.wl.sendgrid.net -all"", + ""valid"": true }, - 'dkim1': { - 'host': 's1._domainkey.example.com', - 'type': 'cname', - 'data': 's1._domainkey.u7.wl.sendgrid.net', - 'valid': true + ""dkim1"": { + ""host"": ""s1._domainkey.example.com"", + ""type"": ""cname"", + ""data"": ""s1._domainkey.u7.wl.sendgrid.net"", + ""valid"": true }, - 'dkim2': { - 'host': 's2._domainkey.example.com', - 'type': 'cname', - 'data': 's2._domainkey.u7.wl.sendgrid.net', - 'valid': true + ""dkim2"": { + ""host"": ""s2._domainkey.example.com"", + ""type"": ""cname"", + ""data"": ""s2._domainkey.u7.wl.sendgrid.net"", + ""valid"": true } } }"; - private const string MULTIPLE_DOMAINS_JSON = @"[ + internal const string MULTIPLE_DOMAINS_JSON = @"[ { - 'id': 1, - 'domain': 'example.com', - 'subdomain': 'mail', - 'username': 'john@example.com', - 'user_id': 7, - 'ips': [ - '192.168.1.1', - '192.168.1.2' + ""id"": 1, + ""domain"": ""example.com"", + ""subdomain"": ""mail"", + ""username"": ""john@example.com"", + ""user_id"": 7, + ""ips"": [ + ""192.168.1.1"", + ""192.168.1.2"" ], - 'custom_spf': true, - 'default': true, - 'legacy': false, - 'automatic_security': true, - 'valid': true, - 'dns': { - 'mail_cname': { - 'host': 'mail.example.com', - 'type': 'cname', - 'data': 'u7.wl.sendgrid.net', - 'valid': true + ""custom_spf"": true, + ""default"": true, + ""legacy"": false, + ""automatic_security"": true, + ""valid"": true, + ""dns"": { + ""mail_cname"": { + ""host"": ""mail.example.com"", + ""type"": ""cname"", + ""data"": ""u7.wl.sendgrid.net"", + ""valid"": true }, - 'spf': { - 'host': 'example.com', - 'type': 'txt', - 'data': 'v=spf1 include:u7.wl.sendgrid.net -all', - 'valid': true + ""spf"": { + ""host"": ""example.com"", + ""type"": ""txt"", + ""data"": ""v=spf1 include:u7.wl.sendgrid.net -all"", + ""valid"": true }, - 'dkim1': { - 'host': 's1._domainkey.example.com', - 'type': 'cname', - 'data': 's1._domainkey.u7.wl.sendgrid.net', - 'valid': true + ""dkim1"": { + ""host"": ""s1._domainkey.example.com"", + ""type"": ""cname"", + ""data"": ""s1._domainkey.u7.wl.sendgrid.net"", + ""valid"": true }, - 'dkim2': { - 'host': 's2._domainkey.example.com', - 'type': 'cname', - 'data': 's2._domainkey.u7.wl.sendgrid.net', - 'valid': true + ""dkim2"": { + ""host"": ""s2._domainkey.example.com"", + ""type"": ""cname"", + ""data"": ""s2._domainkey.u7.wl.sendgrid.net"", + ""valid"": true } } }, { - 'id': 2, - 'domain': 'example2.com', - 'subdomain': 'news', - 'username': 'jane@example2.com', - 'user_id': 8, - 'ips': [ + ""id"": 2, + ""domain"": ""example2.com"", + ""subdomain"": ""news"", + ""username"": ""jane@example2.com"", + ""user_id"": 8, + ""ips"": [ ], - 'custom_spf': false, - 'default': true, - 'legacy': false, - 'automatic_security': true, - 'valid': false, - 'dns': { - 'mail_server': { - 'host': 'news.example2.com', - 'type': 'mx', - 'data': 'sendgrid.net', - 'valid': false + ""custom_spf"": false, + ""default"": true, + ""legacy"": false, + ""automatic_security"": true, + ""valid"": false, + ""dns"": { + ""mail_server"": { + ""host"": ""news.example2.com"", + ""type"": ""mx"", + ""data"": ""sendgrid.net"", + ""valid"": false }, - 'subdomain_spf': { - 'host': 'news.example2.com', - 'type': 'txt', - 'data': 'v=spf1 include:sendgrid.net ~all', - 'valid': false + ""subdomain_spf"": { + ""host"": ""news.example2.com"", + ""type"": ""txt"", + ""data"": ""v=spf1 include:sendgrid.net ~all"", + ""valid"": false }, - 'domain_spf': { - 'host': 'example2.com', - 'type': 'txt', - 'data': 'v=spf1 include:news.example2.com -all', - 'valid': false + ""domain_spf"": { + ""host"": ""example2.com"", + ""type"": ""txt"", + ""data"": ""v=spf1 include:news.example2.com -all"", + ""valid"": false }, - 'dkim': { - 'host': 's1._domainkey.example2.com', - 'type': 'txt', - 'data': 'k=rsa; t=s; p=publicKey', - 'valid': false + ""dkim"": { + ""host"": ""s1._domainkey.example2.com"", + ""type"": ""txt"", + ""data"": ""k=rsa; t=s; p=publicKey"", + ""valid"": false } } } ]"; - private const string SINGLE_IP_JSON = @"{ - 'id': 1, - 'ip': '192.168.1.1', - 'rdns': 'o1.email.example.com', - 'users': [ + internal const string SINGLE_IP_JSON = @"{ + ""id"": 1, + ""ip"": ""192.168.1.1"", + ""rdns"": ""o1.email.example.com"", + ""users"": [ { - 'username': 'john@example.com', - 'user_id': 7 + ""username"": ""john@example.com"", + ""user_id"": 7 }, { - 'username': 'jane@example.com', - 'user_id': 8 + ""username"": ""jane@example.com"", + ""user_id"": 8 } ], - 'subdomain': 'email', - 'domain': 'example.com', - 'valid': true, - 'legacy': false, - 'a_record': { - 'valid': true, - 'type': 'a', - 'host': 'o1.email.example.com', - 'data': '192.168.1.1' + ""subdomain"": ""email"", + ""domain"": ""example.com"", + ""valid"": true, + ""legacy"": false, + ""a_record"": { + ""valid"": true, + ""type"": ""a"", + ""host"": ""o1.email.example.com"", + ""data"": ""192.168.1.1"" } }"; - private const string MULTIPLE_IPS_JSON = @"[ + internal const string MULTIPLE_IPS_JSON = @"[ { - 'id': 1, - 'ip': '192.168.1.1', - 'rdns': 'o1.email.example.com', - 'users': [ + ""id"": 1, + ""ip"": ""192.168.1.1"", + ""rdns"": ""o1.email.example.com"", + ""users"": [ { - 'username': 'john@example.com', - 'user_id': 7 + ""username"": ""john@example.com"", + ""user_id"": 7 }, { - 'username': 'jane@example.com', - 'user_id': 8 + ""username"": ""jane@example.com"", + ""user_id"": 8 } ], - 'subdomain': 'email', - 'domain': 'example.com', - 'valid': true, - 'legacy': false, - 'a_record': { - 'valid': true, - 'type': 'a', - 'host': 'o1.email.example.com', - 'data': '192.168.1.1' + ""subdomain"": ""email"", + ""domain"": ""example.com"", + ""valid"": true, + ""legacy"": false, + ""a_record"": { + ""valid"": true, + ""type"": ""a"", + ""host"": ""o1.email.example.com"", + ""data"": ""192.168.1.1"" } }, { - 'id': 2, - 'ip': '192.168.1.2', - 'rdns': 'o2.email.example.com', - 'users': [ + ""id"": 2, + ""ip"": ""192.168.1.2"", + ""rdns"": ""o2.email.example.com"", + ""users"": [ { - 'username': 'john@example.com', - 'user_id': 7 + ""username"": ""john@example.com"", + ""user_id"": 7 }, { - 'username': 'jane@example2.com', - 'user_id': 9 + ""username"": ""jane@example2.com"", + ""user_id"": 9 } ], - 'subdomain': 'email', - 'domain': 'example.com', - 'valid': true, - 'legacy': false, - 'a_record': { - 'valid': true, - 'type': 'a', - 'host': 'o2.email.example.com', - 'data': '192.168.1.2' + ""subdomain"": ""email"", + ""domain"": ""example.com"", + ""valid"": true, + ""legacy"": false, + ""a_record"": { + ""valid"": true, + ""type"": ""a"", + ""host"": ""o2.email.example.com"", + ""data"": ""192.168.1.2"" } } ]"; - private const string SINGLE_LINK_JSON = @"{ - 'id': 1, - 'domain': 'example.com', - 'subdomain': 'mail', - 'username': 'john@example.com', - 'user_id': 7, - 'default': true, - 'valid': true, - 'legacy': false, - 'dns': { - 'domain_cname': { - 'valid': true, - 'type': 'cname', - 'host': 'mail.example.com', - 'data': 'sendgrid.net' + internal const string SINGLE_LINK_JSON = @"{ + ""id"": 1, + ""domain"": ""example.com"", + ""subdomain"": ""mail"", + ""username"": ""john@example.com"", + ""user_id"": 7, + ""default"": true, + ""valid"": true, + ""legacy"": false, + ""dns"": { + ""domain_cname"": { + ""valid"": true, + ""type"": ""cname"", + ""host"": ""mail.example.com"", + ""data"": ""sendgrid.net"" }, - 'owner_cname': { - 'valid': true, - 'type': 'cname', - 'host': '7.example.com', - 'data': 'sendgrid.net' + ""owner_cname"": { + ""valid"": true, + ""type"": ""cname"", + ""host"": ""7.example.com"", + ""data"": ""sendgrid.net"" } } }"; - private const string MULTIPLE_LINKS_JSON = @"[ + internal const string MULTIPLE_LINKS_JSON = @"[ { - 'id': 1, - 'domain': 'example.com', - 'subdomain': 'mail', - 'username': 'john@example.com', - 'user_id': 7, - 'default': true, - 'valid': true, - 'legacy': false, - 'dns': { - 'domain_cname': { - 'valid': true, - 'type': 'cname', - 'host': 'mail.example.com', - 'data': 'sendgrid.net' + ""id"": 1, + ""domain"": ""example.com"", + ""subdomain"": ""mail"", + ""username"": ""john@example.com"", + ""user_id"": 7, + ""default"": true, + ""valid"": true, + ""legacy"": false, + ""dns"": { + ""domain_cname"": { + ""valid"": true, + ""type"": ""cname"", + ""host"": ""mail.example.com"", + ""data"": ""sendgrid.net"" }, - 'owner_cname': { - 'valid': true, - 'type': 'cname', - 'host': '7.example.com', - 'data': 'sendgrid.net' + ""owner_cname"": { + ""valid"": true, + ""type"": ""cname"", + ""host"": ""7.example.com"", + ""data"": ""sendgrid.net"" } } }, { - 'id': 2, - 'domain': 'example2.com', - 'subdomain': 'news', - 'username': 'john@example.com', - 'user_id': 8, - 'default': false, - 'valid': false, - 'legacy': false, - 'dns': { - 'domain_cname': { - 'valid': true, - 'type': 'cname', - 'host': 'news.example2.com', - 'data': 'sendgrid.net' + ""id"": 2, + ""domain"": ""example2.com"", + ""subdomain"": ""news"", + ""username"": ""john@example.com"", + ""user_id"": 8, + ""default"": false, + ""valid"": false, + ""legacy"": false, + ""dns"": { + ""domain_cname"": { + ""valid"": true, + ""type"": ""cname"", + ""host"": ""news.example2.com"", + ""data"": ""sendgrid.net"" }, - 'owner_cname': { - 'valid': false, - 'type': 'cname', - 'host': '8.example2.com', - 'data': 'sendgrid.net' + ""owner_cname"": { + ""valid"": false, + ""type"": ""cname"", + ""host"": ""8.example2.com"", + ""data"": ""sendgrid.net"" } } } @@ -304,7 +304,7 @@ public void Parse_AuthenticatedDomain_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_DOMAIN_JSON); + var result = JsonSerializer.Deserialize(SINGLE_DOMAIN_JSON); // Assert result.ShouldNotBeNull(); @@ -521,24 +521,24 @@ public async Task ValidateDomainAsync() var domainId = 1L; var apiResponse = @"{ - 'id': 1, - 'valid': true, - 'validation_results': { - 'mail_cname': { - 'valid': false, - 'reason': 'Expected your MX record to be \'mx.sendgrid.net\' but found \'example.com\'.' + ""id"": 1, + ""valid"": true, + ""validation_results"": { + ""mail_cname"": { + ""valid"": false, + ""reason"": ""Expected your MX record to be \""mx.sendgrid.net\"" but found \""example.com\""."" }, - 'dkim1': { - 'valid': true, - 'reason': null + ""dkim1"": { + ""valid"": true, + ""reason"": null }, - 'dkim2': { - 'valid': true, - 'reason': null + ""dkim2"": { + ""valid"": true, + ""reason"": null }, - 'spf': { - 'valid': true, - 'reason': null + ""spf"": { + ""valid"": true, + ""reason"": null } } }"; @@ -563,7 +563,7 @@ public async Task ValidateDomainAsync() result.ValidationResults.Dkim2.IsValid.ShouldBe(true); result.ValidationResults.Dkim2.Reason.ShouldBeNull(); result.ValidationResults.Mail.IsValid.ShouldBe(false); - result.ValidationResults.Mail.Reason.ShouldBe("Expected your MX record to be \'mx.sendgrid.net\' but found \'example.com\'."); + result.ValidationResults.Mail.Reason.ShouldBe("Expected your MX record to be \"mx.sendgrid.net\" but found \"example.com\"."); result.ValidationResults.Spf.IsValid.ShouldBe(true); result.ValidationResults.Spf.Reason.ShouldBeNull(); } @@ -722,12 +722,12 @@ public async Task ValidateReverseDnsAsync() var id = 1L; var apiResponse = @"{ - 'id': 1, - 'valid': true, - 'validation_results': { - 'a_record': { - 'valid': true, - 'reason': null + ""id"": 1, + ""valid"": true, + ""validation_results"": { + ""a_record"": { + ""valid"": true, + ""reason"": null } } }"; @@ -865,16 +865,16 @@ public async Task ValidateLinkAsync() var linkId = 1L; var apiResponse = @"{ - 'id': 1, - 'valid': true, - 'validation_results': { - 'domain_cname': { - 'valid': false, - 'reason': 'Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'.' + ""id"": 1, + ""valid"": true, + ""validation_results"": { + ""domain_cname"": { + ""valid"": false, + ""reason"": ""Expected CNAME to match \""sendgrid.net.\"" but found \""example.com.\""."" }, - 'owner_cname': { - 'valid': true, - 'reason': null + ""owner_cname"": { + ""valid"": true, + ""reason"": null } } }"; @@ -895,7 +895,7 @@ public async Task ValidateLinkAsync() result.LinkId.ShouldBe(1); result.IsValid.ShouldBe(true); result.ValidationResults.Domain.IsValid.ShouldBe(false); - result.ValidationResults.Domain.Reason.ShouldBe("Expected CNAME to match \'sendgrid.net.\' but found \'example.com.\'."); + result.ValidationResults.Domain.Reason.ShouldBe("Expected CNAME to match \"sendgrid.net.\" but found \"example.com.\"."); result.ValidationResults.Owner.IsValid.ShouldBe(true); result.ValidationResults.Owner.Reason.ShouldBeNull(); } diff --git a/Source/StrongGrid.UnitTests/Resources/SettingsTests.cs b/Source/StrongGrid.UnitTests/Resources/SettingsTests.cs index 003aa6f5..2091c1f8 100644 --- a/Source/StrongGrid.UnitTests/Resources/SettingsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SettingsTests.cs @@ -1,9 +1,9 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -14,11 +14,11 @@ public class SettingsTests { #region FIELDS - private const string SINGLE_GLOBAL_SETTING_JSON = @"{ - 'name': 'bcc', - 'title': 'BCC', - 'description': 'lorem ipsum... .', - 'enabled': true + internal const string SINGLE_GLOBAL_SETTING_JSON = @"{ + ""name"": ""bcc"", + ""title"": ""BCC"", + ""description"": ""lorem ipsum... ."", + ""enabled"": true }"; #endregion @@ -29,7 +29,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_GLOBAL_SETTING_JSON); + var result = JsonSerializer.Deserialize(SINGLE_GLOBAL_SETTING_JSON); // Assert result.ShouldNotBeNull(); @@ -44,8 +44,8 @@ public async Task GetEnforcedTlsSettingsAsync() { // Arrange var apiResponse = @"{ - 'require_tls': true, - 'require_valid_cert': false + ""require_tls"": true, + ""require_valid_cert"": false }"; var mockHttp = new MockHttpMessageHandler(); @@ -73,8 +73,8 @@ public async Task UpdateEnforcedTlsSettingsAsync() var requireValidCert = true; var apiResponse = @"{ - 'require_tls': true, - 'require_valid_cert': true + ""require_tls"": true, + ""require_valid_cert"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -102,12 +102,12 @@ public async Task GetAllMailSettingsAsync() var offset = 3; var apiResponse = @"{ - 'result': [ + ""result"": [ { - 'name': 'bcc', - 'title': 'BCC', - 'description': 'lorem ipsum... .', - 'enabled': true + ""name"": ""bcc"", + ""title"": ""BCC"", + ""description"": ""lorem ipsum... ."", + ""enabled"": true } ] }"; @@ -137,12 +137,12 @@ public async Task GetAllPartnerSettingsAsync() var offset = 3; var apiResponse = @"{ - 'result': [ + ""result"": [ { - 'name': 'new_relic', - 'title': 'New Relic', - 'description': 'lorem ipsum... .', - 'enabled': true + ""name"": ""new_relic"", + ""title"": ""New Relic"", + ""description"": ""lorem ipsum... ."", + ""enabled"": true } ] }"; @@ -169,8 +169,8 @@ public async Task GetNewRelicSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'license_key': 'key' + ""enabled"": true, + ""license_key"": ""key"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -198,8 +198,8 @@ public async Task UpdateNewRelicSettings() var licenseKey = "abc123"; var apiResponse = @"{ - 'enabled': true, - 'license_key': 'abc123' + ""enabled"": true, + ""license_key"": ""abc123"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -227,12 +227,12 @@ public async Task GetAllTrackingSettingsAsync() var offset = 3; var apiResponse = @"{ - 'result': [ + ""result"": [ { - 'name': 'open', - 'title': 'Open Tracking', - 'description': 'lorem ipsum... .', - 'enabled': true + ""name"": ""open"", + ""title"": ""Open Tracking"", + ""description"": ""lorem ipsum... ."", + ""enabled"": true } ] }"; @@ -259,8 +259,8 @@ public async Task GetClickTrackingSettingsAsync() { // Arrange var apiResponse = @"{ - 'enable_text': true, - 'enabled': false, + ""enable_text"": true, + ""enabled"": false }"; var mockHttp = new MockHttpMessageHandler(); @@ -287,8 +287,8 @@ public async Task UpdateClickTrackingSettingsAsync() var enabledInHtml = true; var apiResponse = @"{ - 'enable_text': false, - 'enabled': true, + ""enable_text"": false, + ""enabled"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -312,12 +312,12 @@ public async Task GetGoogleAnalyticsGlobalSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'utm_source': 'sendgrid.com', - 'utm_medium': 'email', - 'utm_term': '', - 'utm_content': '', - 'utm_campaign': 'website' + ""enabled"": true, + ""utm_source"": ""sendgrid.com"", + ""utm_medium"": ""email"", + ""utm_term"": """", + ""utm_content"": """", + ""utm_campaign"": ""website"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -353,12 +353,12 @@ public async Task UpdateGoogleAnalyticsGlobalAsync() var utmCampaign = "website"; var apiResponse = @"{ - 'enabled': true, - 'utm_source': 'sendgrid.com', - 'utm_medium': 'email', - 'utm_term': '', - 'utm_content': '', - 'utm_campaign': 'website' + ""enabled"": true, + ""utm_source"": ""sendgrid.com"", + ""utm_medium"": ""email"", + ""utm_term"": """", + ""utm_content"": """", + ""utm_campaign"": ""website"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -381,7 +381,7 @@ public async Task GetOpenTrackingSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, + ""enabled"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -406,7 +406,7 @@ public async Task UpdateOpenTrackingSettingsAsync() var enabled = true; var apiResponse = @"{ - 'enabled': true, + ""enabled"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -429,12 +429,12 @@ public async Task GetSubscriptionTrackingSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'landing': 'landing page html', - 'url': 'url', - 'replace': 'replacement tag', - 'html_content': 'html content', - 'plain_content': 'text content' + ""enabled"": true, + ""landing"": ""landing page html"", + ""url"": ""url"", + ""replace"": ""replacement tag"", + ""html_content"": ""html content"", + ""plain_content"": ""text content"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -470,12 +470,12 @@ public async Task UpdateSubscriptionTrackingSettingsAsync() var textContent = "text content"; var apiResponse = @"{ - 'enabled': true, - 'landing': 'landing page html', - 'url': 'url', - 'replace': 'replacement tag', - 'html_content': 'html content', - 'plain_content': 'text content' + ""enabled"": true, + ""landing"": ""landing page html"", + ""url"": ""url"", + ""replace"": ""replacement tag"", + ""html_content"": ""html content"", + ""plain_content"": ""text content"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -493,68 +493,15 @@ public async Task UpdateSubscriptionTrackingSettingsAsync() result.ShouldNotBeNull(); } - [Fact] - public async Task GetBccMailSettingsAsync() - { - // Arrange - var apiResponse = @"{ - 'enabled': true, - 'email': 'email@example.com' - }"; - - var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri("mail_settings/bcc")).Respond("application/json", apiResponse); - - var client = Utils.GetFluentClient(mockHttp); - var settings = new Settings(client); - - // Act - var result = await settings.GetBccMailSettingsAsync(null, CancellationToken.None).ConfigureAwait(false); - - // Assert - mockHttp.VerifyNoOutstandingExpectation(); - mockHttp.VerifyNoOutstandingRequest(); - result.ShouldNotBeNull(); - result.Enabled.ShouldBe(true); - result.EmailAddress.ShouldBe("email@example.com"); - } - - [Fact] - public async Task UpdateBccMailSettingsAsync() - { - // Arrange - var enabled = true; - var email = "email@example.com"; - - var apiResponse = @"{ - 'enabled': true, - 'email': 'email@example.com' - }"; - - var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(new HttpMethod("PATCH"), Utils.GetSendGridApiUri("mail_settings/bcc")).Respond("application/json", apiResponse); - - var client = Utils.GetFluentClient(mockHttp); - var settings = new Settings(client); - - // Act - var result = await settings.UpdateBccMailSettingsAsync(enabled, email, null, CancellationToken.None).ConfigureAwait(false); - - // Assert - mockHttp.VerifyNoOutstandingExpectation(); - mockHttp.VerifyNoOutstandingRequest(); - result.ShouldNotBeNull(); - } - [Fact] public async Task GetAddressWhitelistMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'list': [ - 'email1@example.com', - 'example.com' + ""enabled"": true, + ""list"": [ + ""email1@example.com"", + ""example.com"" ] }"; @@ -586,10 +533,10 @@ public async Task UpdateAddressWhitelistMailSettingsAsync() var emailAddresses = new[] { "email@example.com", "example.com" }; var apiResponse = @"{ - 'enabled': true, - 'list': [ - 'email1@example.com', - 'example.com' + ""enabled"": true, + ""list"": [ + ""email1@example.com"", + ""example.com"" ] }"; @@ -613,9 +560,9 @@ public async Task GetFooterMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'html_content': '... 123 ...', - 'plain_content': '... abc ...' + ""enabled"": true, + ""html_content"": ""... 123 ..."", + ""plain_content"": ""... abc ..."" }"; var mockHttp = new MockHttpMessageHandler(); @@ -645,9 +592,9 @@ public async Task UpdateFooterMailSettingsAsync() var textContent = "text content"; var apiResponse = @"{ - 'enabled': true, - 'html_content': 'html content', - 'plain_content': 'text content' + ""enabled"": true, + ""html_content"": ""html content"", + ""plain_content"": ""text content"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -670,8 +617,8 @@ public async Task GetForwardSpamMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'email': 'email address' + ""enabled"": true, + ""email"": ""email address"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -699,8 +646,8 @@ public async Task UpdateForwardSpamMailSettingsAsync() var email = "email address"; var apiResponse = @"{ - 'enabled': true, - 'email': 'email address' + ""enabled"": true, + ""email"": ""email address"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -723,7 +670,7 @@ public async Task GetPlainContentMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, + ""enabled"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -748,7 +695,7 @@ public async Task UpdatPlainContentMailSettingsAsync() var enabled = true; var apiResponse = @"{ - 'enabled': true, + ""enabled"": true }"; var mockHttp = new MockHttpMessageHandler(); @@ -766,70 +713,13 @@ public async Task UpdatPlainContentMailSettingsAsync() result.ShouldBeTrue(); } - [Fact] - public async Task GetSpamCheckMailSettingsAsync() - { - // Arrange - var apiResponse = @"{ - 'enabled': true, - 'url': 'url', - 'max_score': 5 - }"; - - var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(HttpMethod.Get, Utils.GetSendGridApiUri("mail_settings/spam_check")).Respond("application/json", apiResponse); - - var client = Utils.GetFluentClient(mockHttp); - var settings = new Settings(client); - - // Act - var result = await settings.GetSpamCheckMailSettingsAsync(null, CancellationToken.None).ConfigureAwait(false); - - // Assert - mockHttp.VerifyNoOutstandingExpectation(); - mockHttp.VerifyNoOutstandingRequest(); - result.ShouldNotBeNull(); - result.Enabled.ShouldBe(true); - result.Url.ShouldBe("url"); - result.Threshold.ShouldBe(5); - } - - [Fact] - public async Task UpdateSpamCheckMailSettingsAsync() - { - // Arrange - var enabled = true; - var postToUrl = "url"; - var threshold = 5; - - var apiResponse = @"{ - 'enabled': true, - 'url': 'url', - 'max_score': 5 - }"; - - var mockHttp = new MockHttpMessageHandler(); - mockHttp.Expect(new HttpMethod("PATCH"), Utils.GetSendGridApiUri("mail_settings/spam_check")).Respond("application/json", apiResponse); - - var client = Utils.GetFluentClient(mockHttp); - var settings = new Settings(client); - - // Act - var result = await settings.UpdateSpamCheckMailSettingsAsync(enabled, postToUrl, threshold, null, CancellationToken.None).ConfigureAwait(false); - - // Assert - mockHttp.VerifyNoOutstandingExpectation(); - mockHttp.VerifyNoOutstandingRequest(); - result.ShouldNotBeNull(); - } - [Fact] public async Task GetTemplateMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'html_content': ' <% body %> ' + ""enabled"": true, + ""html_content"": "" <% body %> "" }"; var mockHttp = new MockHttpMessageHandler(); @@ -854,11 +744,11 @@ public async Task UpdateTemplateMailSettingsAsync() { // Arrange var enabled = true; - var htmlContent = "' <% body %> "; + var htmlContent = " <% body %> "; var apiResponse = @"{ - 'enabled': true, - 'html_content': ' <% body %> ' + ""enabled"": true, + ""html_content"": "" <% body %> "" }"; var mockHttp = new MockHttpMessageHandler(); @@ -881,9 +771,9 @@ public async Task GetBouncePurgeMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'hard_bounces': 5, - 'soft_bounces': 5 + ""enabled"": true, + ""hard_bounces"": 5, + ""soft_bounces"": 5 }"; var mockHttp = new MockHttpMessageHandler(); @@ -913,9 +803,9 @@ public async Task UpdateBouncePurgeMailSettingsAsync() var softBounces = 5; var apiResponse = @"{ - 'enabled': true, - 'hard_bounces': 5, - 'soft_bounces': 5 + ""enabled"": true, + ""hard_bounces"": 5, + ""soft_bounces"": 5 }"; var mockHttp = new MockHttpMessageHandler(); @@ -938,8 +828,8 @@ public async Task GetForwardBounceMailSettingsAsync() { // Arrange var apiResponse = @"{ - 'enabled': true, - 'email': 'email address' + ""enabled"": true, + ""email"": ""email address"" }"; var mockHttp = new MockHttpMessageHandler(); @@ -967,8 +857,8 @@ public async Task UpdatForwardBounceMailSettingsAsync() var email = "email address"; var apiResponse = @"{ - 'enabled': true, - 'email': 'email address' + ""enabled"": true, + ""email"": ""email address"" }"; var mockHttp = new MockHttpMessageHandler(); diff --git a/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs b/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs index 4c112afe..9b34d7e5 100644 --- a/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SpamReportsTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,25 +16,25 @@ public class SpamReportsTests { #region FIELDS - private const string ENDPOINT = "suppression/spam_reports"; + internal const string ENDPOINT = "suppression/spam_reports"; - private const string SINGLE_SPAM_REPORT_JSON = @"[ + internal const string SINGLE_SPAM_REPORT_JSON = @"[ { - 'created': 1454433146, - 'email': 'test1@example.com', - 'ip': '10.89.32.5' + ""created"": 1454433146, + ""email"": ""test1@example.com"", + ""ip"": ""10.89.32.5"" } ]"; - private const string MULTIPLE_SPAM_REPORTS_JSON = @"[ + internal const string MULTIPLE_SPAM_REPORTS_JSON = @"[ { - 'created': 1443651141, - 'email': 'user1@example.com', - 'ip': '10.63.202.100' + ""created"": 1443651141, + ""email"": ""user1@example.com"", + ""ip"": ""10.63.202.100"" }, { - 'created': 1443651154, - 'email': 'user2@example.com', - 'ip': '10.63.202.100' + ""created"": 1443651154, + ""email"": ""user2@example.com"", + ""ip"": ""10.63.202.100"" } ]"; @@ -46,7 +46,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_SPAM_REPORT_JSON); + var result = JsonSerializer.Deserialize(SINGLE_SPAM_REPORT_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/StatisticsTests.cs b/Source/StrongGrid.UnitTests/Resources/StatisticsTests.cs index d7cc6874..e1823777 100644 --- a/Source/StrongGrid.UnitTests/Resources/StatisticsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/StatisticsTests.cs @@ -19,53 +19,54 @@ public async Task GetGlobalStatsAsync() // Arrange var startDate = new DateTime(2015, 1, 1); var endDate = new DateTime(2015, 1, 2); + var apiResponse = @"[ { - 'date': '2015-01-01', - 'stats': [ + ""date"": ""2015-01-01"", + ""stats"": [ { - 'metrics': { - 'blocks': 1, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 1, - 'delivered': 1, - 'invalid_emails': 1, - 'opens': 1, - 'processed': 2, - 'requests': 3, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 1, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 1, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 1, + ""delivered"": 1, + ""invalid_emails"": 1, + ""opens"": 1, + ""processed"": 2, + ""requests"": 3, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 1, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 } } ] }, { - 'date': '2015-01-02', - 'stats': [ + ""date"": ""2015-01-02"", + ""stats"": [ { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 0, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 0, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 } } ] @@ -100,100 +101,100 @@ public async Task GetCategoryStatsAsync() var apiResponse = @"[ { - 'date': '2015 - 01 - 01', - 'stats': [ + ""date"": ""2015-01-01"", + ""stats"": [ { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 0, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 0, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'cat1', - 'type': 'category' + ""name"": ""cat1"", + ""type"": ""category"" }, { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 0, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 0, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'cat2', - 'type': 'category' + ""name"": ""cat2"", + ""type"": ""category"" } ] }, { - 'date': '2015-01-02', - 'stats': [ + ""date"": ""2015-01-02"", + ""stats"": [ { - 'metrics': { - 'blocks': 10, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 10, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 10, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 10, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'cat1', - 'type': 'category' + ""name"": ""cat1"", + ""type"": ""category"" }, { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 6, - 'deferred': 0, - 'delivered': 5, - 'invalid_emails': 0, - 'opens': 6, - 'processed': 0, - 'requests': 5, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 5, - 'unique_opens': 5, - 'unsubscribe_drops': 0, - 'unsubscribes': 6 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 6, + ""deferred"": 0, + ""delivered"": 5, + ""invalid_emails"": 0, + ""opens"": 6, + ""processed"": 0, + ""requests"": 5, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 5, + ""unique_opens"": 5, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 6 }, - 'name': 'cat2', - 'type': 'category' + ""name"": ""cat2"", + ""type"": ""category"" } ] } @@ -225,102 +226,103 @@ public async Task GetSubusersStatsAsync() var subusers = new[] { "user1", "user2" }; var startDate = new DateTime(2015, 1, 1); var endDate = new DateTime(2015, 1, 2); + var apiResponse = @"[ { - 'date': '2015-01-01', - 'stats': [ + ""date"": ""2015-01-01"", + ""stats"": [ { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 0, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 0, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'user1', - 'type': 'subuser' + ""name"": ""user1"", + ""type"": ""subuser"" }, { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 0, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 0, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'user2', - 'type': 'subuser' + ""name"": ""user2"", + ""type"": ""subuser"" } ] }, { - 'date': '2015-01-02', - 'stats': [ + ""date"": ""2015-01-02"", + ""stats"": [ { - 'metrics': { - 'blocks': 10, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'invalid_emails': 0, - 'opens': 0, - 'processed': 0, - 'requests': 10, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0, - 'unsubscribe_drops': 0, - 'unsubscribes': 0 + ""metrics"": { + ""blocks"": 10, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""invalid_emails"": 0, + ""opens"": 0, + ""processed"": 0, + ""requests"": 10, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 0 }, - 'name': 'user1', - 'type': 'subuser' + ""name"": ""user1"", + ""type"": ""subuser"" }, { - 'metrics': { - 'blocks': 0, - 'bounce_drops': 0, - 'bounces': 0, - 'clicks': 6, - 'deferred': 0, - 'delivered': 5, - 'invalid_emails': 0, - 'opens': 6, - 'processed': 0, - 'requests': 5, - 'spam_report_drops': 0, - 'spam_reports': 0, - 'unique_clicks': 5, - 'unique_opens': 5, - 'unsubscribe_drops': 0, - 'unsubscribes': 6 + ""metrics"": { + ""blocks"": 0, + ""bounce_drops"": 0, + ""bounces"": 0, + ""clicks"": 6, + ""deferred"": 0, + ""delivered"": 5, + ""invalid_emails"": 0, + ""opens"": 6, + ""processed"": 0, + ""requests"": 5, + ""spam_report_drops"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 5, + ""unique_opens"": 5, + ""unsubscribe_drops"": 0, + ""unsubscribes"": 6 }, - 'name': 'user2', - 'type': 'subuser' + ""name"": ""user2"", + ""type"": ""subuser"" } ] } @@ -352,34 +354,35 @@ public async Task GetCountryStatsAsync() var country = "US"; var startDate = new DateTime(2014, 10, 1); var endDate = new DateTime(2014, 10, 2); + var apiResponse = @"[ { - 'date': '2014-10-01', - 'stats': [ + ""date"": ""2014-10-01"", + ""stats"": [ { - 'metrics': { - 'clicks': 0, - 'opens': 1, - 'unique_clicks': 0, - 'unique_opens': 1 + ""metrics"": { + ""clicks"": 0, + ""opens"": 1, + ""unique_clicks"": 0, + ""unique_opens"": 1 }, - 'name': 'us', - 'type': 'country' + ""name"": ""us"", + ""type"": ""country"" } ] }, { - 'date': '2014-10-02', - 'stats': [ + ""date"": ""2014-10-02"", + ""stats"": [ { - 'metrics': { - 'clicks': 0, - 'opens': 0, - 'unique_clicks': 0, - 'unique_opens': 0 + ""metrics"": { + ""clicks"": 0, + ""opens"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0 }, - 'name': 'us', - 'type': 'country' + ""name"": ""us"", + ""type"": ""country"" } ] } @@ -410,30 +413,31 @@ public async Task GetDeviceTypesStatsAsync() // Arrange var startDate = new DateTime(2014, 10, 1); var endDate = new DateTime(2014, 10, 2); + var apiResponse = @"[ { - 'date': '2014-10-01', - 'stats': [ + ""date"": ""2014-10-01"", + ""stats"": [ { - 'metrics': { - 'opens': 1, - 'unique_opens': 1 + ""metrics"": { + ""opens"": 1, + ""unique_opens"": 1 }, - 'name': 'Webmail', - 'type': 'device' + ""name"": ""Webmail"", + ""type"": ""device"" } ] }, { - 'date': '2014-10-02', - 'stats': [ + ""date"": ""2014-10-02"", + ""stats"": [ { - 'metrics': { - 'opens': 0, - 'unique_opens': 0 + ""metrics"": { + ""opens"": 0, + ""unique_opens"": 0 }, - 'name': 'Webmail', - 'type': 'device' + ""name"": ""Webmail"", + ""type"": ""device"" } ] } @@ -465,30 +469,31 @@ public async Task GetClientTypesStatsAsync() // Arrange var startDate = new DateTime(2014, 10, 1); var endDate = new DateTime(2014, 10, 2); + var apiResponse = @"[ { - 'date': '2014-10-01', - 'stats': [ + ""date"": ""2014-10-01"", + ""stats"": [ { - 'metrics': { - 'opens': 1, - 'unique_opens': 1 + ""metrics"": { + ""opens"": 1, + ""unique_opens"": 1 }, - 'name': 'Gmail', - 'type': 'client' + ""name"": ""Gmail"", + ""type"": ""client"" } ] }, { - 'date': '2014-10-02', - 'stats': [ + ""date"": ""2014-10-02"", + ""stats"": [ { - 'metrics': { - 'opens': 0, - 'unique_opens': 0 + ""metrics"": { + ""opens"": 0, + ""unique_opens"": 0 }, - 'name': 'Gmail', - 'type': 'client' + ""name"": ""Gmail"", + ""type"": ""client"" } ] } @@ -521,46 +526,47 @@ public async Task GetInboxProvidersStatsAsync() var providers = new[] { "Gmail", "Hotmail" }; var startDate = new DateTime(2014, 10, 1); var endDate = new DateTime(2014, 10, 2); + var apiResponse = @"[ { - 'date': '2014-10-01', - 'stats': [ + ""date"": ""2014-10-01"", + ""stats"": [ { - 'metrics': { - 'blocks': 1, - 'bounces': 0, - 'clicks': 0, - 'deferred': 1, - 'delivered': 1, - 'drops': 0, - 'opens': 1, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 1 + ""metrics"": { + ""blocks"": 1, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 1, + ""delivered"": 1, + ""drops"": 0, + ""opens"": 1, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 1 }, - 'name': 'Gmail', - 'type': 'esp' + ""name"": ""Gmail"", + ""type"": ""esp"" } ] }, { - 'date': '2014-10-02', - 'stats': [ + ""date"": ""2014-10-02"", + ""stats"": [ { - 'metrics': { - 'blocks': 0, - 'bounces': 0, - 'clicks': 0, - 'deferred': 0, - 'delivered': 0, - 'drops': 0, - 'opens': 0, - 'spam_reports': 0, - 'unique_clicks': 0, - 'unique_opens': 0 + ""metrics"": { + ""blocks"": 0, + ""bounces"": 0, + ""clicks"": 0, + ""deferred"": 0, + ""delivered"": 0, + ""drops"": 0, + ""opens"": 0, + ""spam_reports"": 0, + ""unique_clicks"": 0, + ""unique_opens"": 0 }, - 'name': 'Gmail', - 'type': 'esp' + ""name"": ""Gmail"", + ""type"": ""esp"" } ] } @@ -592,46 +598,47 @@ public async Task GetBrowsersStatsAsync() var browsers = new[] { "Chrome", "Firefox" }; var startDate = new DateTime(2014, 10, 1); var endDate = new DateTime(2014, 10, 2); + var apiResponse = @"[ { - 'date': '2014-10-01', - 'stats': [ + ""date"": ""2014-10-01"", + ""stats"": [ { - 'metrics': { - 'clicks': 0, - 'unique_clicks': 0 + ""metrics"": { + ""clicks"": 0, + ""unique_clicks"": 0 }, - 'name': 'Chrome', - 'type': 'browser' + ""name"": ""Chrome"", + ""type"": ""browser"" }, { - 'metrics': { - 'clicks': 1, - 'unique_clicks': 1 + ""metrics"": { + ""clicks"": 1, + ""unique_clicks"": 1 }, - 'name': 'Firefox', - 'type': 'browser' + ""name"": ""Firefox"", + ""type"": ""browser"" } ] }, { - 'date': '2014-10-02', - 'stats': [ + ""date"": ""2014-10-02"", + ""stats"": [ { - 'metrics': { - 'clicks': 0, - 'unique_clicks': 0 + ""metrics"": { + ""clicks"": 0, + ""unique_clicks"": 0 }, - 'name': 'Chrome', - 'type': 'browser' + ""name"": ""Chrome"", + ""type"": ""browser"" }, { - 'metrics': { - 'clicks': 1, - 'unique_clicks': 1 + ""metrics"": { + ""clicks"": 1, + ""unique_clicks"": 1 }, - 'name': 'Firefox', - 'type': 'browser' + ""name"": ""Firefox"", + ""type"": ""browser"" } ] } diff --git a/Source/StrongGrid.UnitTests/Resources/SubusersTests.cs b/Source/StrongGrid.UnitTests/Resources/SubusersTests.cs index 1b009b49..80a3c701 100644 --- a/Source/StrongGrid.UnitTests/Resources/SubusersTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SubusersTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -7,6 +6,7 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -17,60 +17,60 @@ public class SubusersTests { #region FIELDS - private const string ENDPOINT = "subusers"; + internal const string ENDPOINT = "subusers"; - private const string SINGLE_SUBUSER_JSON = @"{ - 'id': 1, - 'username': 'TestUser', - 'email': 'Test@example.com', - 'disabled': true + internal const string SINGLE_SUBUSER_JSON = @"{ + ""id"": 1, + ""username"": ""TestUser"", + ""email"": ""Test@example.com"", + ""disabled"": true }"; - private const string SINGLE_SUBUSER_CREATED_JSON = @"{ - 'id': 1, - 'username': 'TestUser', - 'password': 'somepass', - 'email': 'Test@example.com', - 'ips': [ - '1.1.1.1', - '2.2.2.2' + internal const string SINGLE_SUBUSER_CREATED_JSON = @"{ + ""id"": 1, + ""username"": ""TestUser"", + ""password"": ""somepass"", + ""email"": ""Test@example.com"", + ""ips"": [ + ""1.1.1.1"", + ""2.2.2.2"" ] }"; - private const string MULTIPLE_SUBUSER_JSON = @"[ + internal const string MULTIPLE_SUBUSER_JSON = @"[ { - 'id': 1, - 'username': 'TestUser', - 'email': 'Test@example.com', - 'disabled': false + ""id"": 1, + ""username"": ""TestUser"", + ""email"": ""Test@example.com"", + ""disabled"": false }, { - 'id': 2, - 'username': 'John', - 'email': 'John@example.com', - 'disabled': true + ""id"": 2, + ""username"": ""John"", + ""email"": ""John@example.com"", + ""disabled"": true } ]"; - private const string MULTIPLE_IPS_JSON = @"[ - '1.1.1.1', - '2.2.2.2' + internal const string MULTIPLE_IPS_JSON = @"[ + ""1.1.1.1"", + ""2.2.2.2"" ]"; - private const string MONITOR_SETTINGS_JSON = @"{ - 'email': 'test@example.com', - 'frequency': 500 + internal const string MONITOR_SETTINGS_JSON = @"{ + ""email"": ""test@example.com"", + ""frequency"": 500 }"; - private const string SINGLE_REPUTATION_JSON = @"[ + internal const string SINGLE_REPUTATION_JSON = @"[ { - 'username': 'example_subuser', - 'reputation': 99 + ""username"": ""example_subuser"", + ""reputation"": 99 } ]"; - private const string MULTIPLE_REPUTATIONS_JSON = @"[ + internal const string MULTIPLE_REPUTATIONS_JSON = @"[ { - 'username': 'example_subuser', - 'reputation': 99 + ""username"": ""example_subuser"", + ""reputation"": 99 }, { - 'username': 'example_subuser2', - 'reputation': 95.2 + ""username"": ""example_subuser2"", + ""reputation"": 95.2 } ]"; @@ -82,7 +82,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_SUBUSER_JSON); + var result = JsonSerializer.Deserialize(SINGLE_SUBUSER_JSON); // Assert result.ShouldNotBeNull(); @@ -98,7 +98,7 @@ public void Parse_json_created() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_SUBUSER_CREATED_JSON); + var result = JsonSerializer.Deserialize(SINGLE_SUBUSER_CREATED_JSON); // Assert result.ShouldNotBeNull(); @@ -116,7 +116,7 @@ public void Parse_json_MonitorSettings() // Arrange // Act - var result = JsonConvert.DeserializeObject(MONITOR_SETTINGS_JSON); + var result = JsonSerializer.Deserialize(MONITOR_SETTINGS_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/SuppresionsTests.cs b/Source/StrongGrid.UnitTests/Resources/SuppresionsTests.cs index e6ef1289..1e7a7897 100644 --- a/Source/StrongGrid.UnitTests/Resources/SuppresionsTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/SuppresionsTests.cs @@ -13,50 +13,50 @@ public class SuppresionsTests { #region FIELDS - private const string ENDPOINT = "asm"; - private const string ALL_GROUPS_JSON = @"{ - 'suppressions': [ + internal const string ENDPOINT = "asm"; + internal const string ALL_GROUPS_JSON = @"{ + ""suppressions"": [ { - 'description': 'Optional description.', - 'id': 1, - 'is_default': true, - 'name': 'Weekly News', - 'suppressed': true + ""description"": ""Optional description."", + ""id"": 1, + ""is_default"": true, + ""name"": ""Weekly News"", + ""suppressed"": true }, { - 'description': 'Some daily news.', - 'id': 2, - 'is_default': true, - 'name': 'Daily News', - 'suppressed': true + ""description"": ""Some daily news."", + ""id"": 2, + ""is_default"": true, + ""name"": ""Daily News"", + ""suppressed"": true }, { - 'description': 'An old group.', - 'id': 2, - 'is_default': false, - 'name': 'Old News', - 'suppressed': false + ""description"": ""An old group."", + ""id"": 2, + ""is_default"": false, + ""name"": ""Old News"", + ""suppressed"": false } ] }"; - private const string ALL_SUPPRESSIONS_JSON = @"[ + internal const string ALL_SUPPRESSIONS_JSON = @"[ { - 'email':'test @example.com', - 'group_id': 1, - 'group_name': 'Weekly News', - 'created_at': 1410986704 + ""email"":""test @example.com"", + ""group_id"": 1, + ""group_name"": ""Weekly News"", + ""created_at"": 1410986704 }, { - 'email':'test1@example.com', - 'group_id': 2, - 'group_name': 'Daily News', - 'created_at': 1411493671 + ""email"":""test1@example.com"", + ""group_id"": 2, + ""group_name"": ""Daily News"", + ""created_at"": 1411493671 }, { - 'email':'test2@example.com', - 'group_id': 2, - 'group_name': 'Daily News', - 'created_at': 1411493671 + ""email"":""test2@example.com"", + ""group_id"": 2, + ""group_name"": ""Daily News"", + ""created_at"": 1411493671 } ]"; @@ -115,8 +115,8 @@ public async Task GetUnsubscribedAddressesAsync() var groupId = 123; var apiResponse = @"[ - 'test1@example.com', - 'test2@example.com' + ""test1@example.com"", + ""test2@example.com"" ]"; var mockHttp = new MockHttpMessageHandler(); @@ -145,9 +145,9 @@ public async Task AddAddressToUnsubscribeGroupAsync_single_email() var email = "test1@example.com"; var apiResponse = @"{ - 'recipient_emails': [ - 'test1@example.com', - 'test2@example.com' + ""recipient_emails"": [ + ""test1@example.com"", + ""test2@example.com"" ] }"; @@ -173,9 +173,9 @@ public async Task AddAddressToUnsubscribeGroupAsync_multiple_emails() var emails = new[] { "test1@example.com", "test2@example.com" }; var apiResponse = @"{ - 'recipient_emails': [ - 'test1@example.com', - 'test2@example.com' + ""recipient_emails"": [ + ""test1@example.com"", + ""test2@example.com"" ] }"; @@ -222,9 +222,9 @@ public async Task IsSuppressedAsync_true() var groupId = 123; var apiResponse = @"[ - 'a@a.com', - 'b@b.com', - 'test@example.com' + ""a@a.com"", + ""b@b.com"", + ""test@example.com"" ]"; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Post, Utils.GetSendGridApiUri(ENDPOINT, "groups", groupId, "suppressions/search")).Respond("application/json", apiResponse); @@ -249,8 +249,8 @@ public async Task IsSuppressedAsync_false() var groupId = 123; var apiResponse = @"[ - 'a@a.com', - 'b@b.com' + ""a@a.com"", + ""b@b.com"" ]"; var mockHttp = new MockHttpMessageHandler(); mockHttp.Expect(HttpMethod.Post, Utils.GetSendGridApiUri(ENDPOINT, "groups", groupId, "suppressions/search")).Respond("application/json", apiResponse); diff --git a/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs b/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs index 6d35bbce..d7a86029 100644 --- a/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/TeammatesTests.cs @@ -1,10 +1,10 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; using StrongGrid.Resources; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -15,107 +15,107 @@ public class TeammatesTests { #region FIELDS - private const string ENDPOINT = "teammates"; + internal const string ENDPOINT = "teammates"; - private const string MULTIPLE_ACCESS_REQUESTS_JSON = @"[ + internal const string MULTIPLE_ACCESS_REQUESTS_JSON = @"[ { - 'id': 1, - 'scope_group_name': 'Mail Settings', - 'username': 'teammate1', - 'email': 'teammate1@example.com', - 'first_name': 'Teammate', - 'last_name': 'One' + ""id"": 1, + ""scope_group_name"": ""Mail Settings"", + ""username"": ""teammate1"", + ""email"": ""teammate1@example.com"", + ""first_name"": ""Teammate"", + ""last_name"": ""One"" }, { - 'id': 2, - 'scope_group_name': 'Stats', - 'username': 'teammate2', - 'email': 'teammate2@example.com', - 'first_name': 'Teammate', - 'last_name': 'Two' + ""id"": 2, + ""scope_group_name"": ""Stats"", + ""username"": ""teammate2"", + ""email"": ""teammate2@example.com"", + ""first_name"": ""Teammate"", + ""last_name"": ""Two"" } ]"; - private const string SINGLE_INVITATION_JSON = @"{ - 'email': 'teammate1 @example.com', - 'scopes': [ - 'user.profile.read', - 'user.profile.update' + internal const string SINGLE_INVITATION_JSON = @"{ + ""email"": ""teammate1 @example.com"", + ""scopes"": [ + ""user.profile.read"", + ""user.profile.update"" ], - 'is_admin': false + ""is_admin"": false }"; - private const string MULTIPLE_INVITATIONS_JSON = @"{ - 'result': [ + internal const string MULTIPLE_INVITATIONS_JSON = @"{ + ""result"": [ { - 'email': 'user1@example.com', - 'scopes': [ - 'user.profile.read', - 'user.profile.edit' + ""email"": ""user1@example.com"", + ""scopes"": [ + ""user.profile.read"", + ""user.profile.edit"" ], - 'is_admin': false, - 'pending_id': 'abcd123abc', - 'expiration_date': 1456424263 + ""is_admin"": false, + ""pending_id"": ""abcd123abc"", + ""expiration_date"": 1456424263 }, { - 'email': 'user2@example.com', - 'scopes': [], - 'is_admin': true, - 'pending_id': 'bcde234bcd', - 'expiration_date': 1456424263 + ""email"": ""user2@example.com"", + ""scopes"": [], + ""is_admin"": true, + ""pending_id"": ""bcde234bcd"", + ""expiration_date"": 1456424263 } ] }"; - private const string SINGLE_TEAMMATE_JSON = @"{ - 'username': 'teammate1', - 'email': 'teammate1@example.com', - 'first_name': 'Jane', - 'last_name': 'Doe', - 'user_type': 'owner', - 'is_admin': true, - 'phone': '123-345-3453', - 'website': 'www.example.com', - 'company': 'ACME Inc.', - 'address': '123 Acme St', - 'address2': '', - 'city': 'City', - 'state': 'CA', - 'country': 'USA', - 'zip': '12345' + internal const string SINGLE_TEAMMATE_JSON = @"{ + ""username"": ""teammate1"", + ""email"": ""teammate1@example.com"", + ""first_name"": ""Jane"", + ""last_name"": ""Doe"", + ""user_type"": ""owner"", + ""is_admin"": true, + ""phone"": ""123-345-3453"", + ""website"": ""www.example.com"", + ""company"": ""ACME Inc."", + ""address"": ""123 Acme St"", + ""address2"": """", + ""city"": ""City"", + ""state"": ""CA"", + ""country"": ""USA"", + ""zip"": ""12345"" }"; - private const string MULTIPLE_TEAMMATES_JSON = @"{ - 'result': [ + internal const string MULTIPLE_TEAMMATES_JSON = @"{ + ""result"": [ { - 'username': 'teammate2', - 'email': 'teammate2@example.com', - 'first_name': 'John', - 'last_name': 'Doe', - 'user_type': 'teammate', - 'is_admin': false, - 'phone': '123-345-3453', - 'website': 'www.example.com', - 'company': 'ACME Inc.', - 'address': '123 Acme St', - 'address2': '', - 'city': 'City', - 'state': 'CA', - 'country': 'USA', - 'zip': '12345' + ""username"": ""teammate2"", + ""email"": ""teammate2@example.com"", + ""first_name"": ""John"", + ""last_name"": ""Doe"", + ""user_type"": ""teammate"", + ""is_admin"": false, + ""phone"": ""123-345-3453"", + ""website"": ""www.example.com"", + ""company"": ""ACME Inc."", + ""address"": ""123 Acme St"", + ""address2"": """", + ""city"": ""City"", + ""state"": ""CA"", + ""country"": ""USA"", + ""zip"": ""12345"" }, { - 'username': 'teammate3', - 'email': 'teammate3@example.com', - 'first_name': 'Steve', - 'last_name': 'Doe', - 'user_type': 'admin', - 'is_admin': true, - 'phone': '123-345-3453', - 'website': 'www.example.com', - 'company': 'ACME Inc.', - 'address': '123 Acme St', - 'address2': '', - 'city': 'City', - 'state': 'CA', - 'country': 'USA', - 'zip': '12345' + ""username"": ""teammate3"", + ""email"": ""teammate3@example.com"", + ""first_name"": ""Steve"", + ""last_name"": ""Doe"", + ""user_type"": ""admin"", + ""is_admin"": true, + ""phone"": ""123-345-3453"", + ""website"": ""www.example.com"", + ""company"": ""ACME Inc."", + ""address"": ""123 Acme St"", + ""address2"": """", + ""city"": ""City"", + ""state"": ""CA"", + ""country"": ""USA"", + ""zip"": ""12345"" } ] }"; @@ -128,7 +128,7 @@ public void Parse_json() // Arrange // Act - var result = JsonConvert.DeserializeObject(SINGLE_TEAMMATE_JSON); + var result = JsonSerializer.Deserialize(SINGLE_TEAMMATE_JSON); // Assert result.ShouldNotBeNull(); diff --git a/Source/StrongGrid.UnitTests/Resources/TemplatesTests.cs b/Source/StrongGrid.UnitTests/Resources/TemplatesTests.cs index a71592ae..063363d0 100644 --- a/Source/StrongGrid.UnitTests/Resources/TemplatesTests.cs +++ b/Source/StrongGrid.UnitTests/Resources/TemplatesTests.cs @@ -1,4 +1,3 @@ -using Newtonsoft.Json; using RichardSzalay.MockHttp; using Shouldly; using StrongGrid.Models; @@ -6,6 +5,7 @@ using System; using System.Net; using System.Net.Http; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Xunit; @@ -16,51 +16,51 @@ public class TemplatesTests { #region FIELDS - private const string ENDPOINT = "templates"; + internal const string ENDPOINT = "templates"; - private const string SINGLE_TEMPLATE_JSON = @"{ - 'id': 'e8ac01d5-a07a-4a71-b14c-4721136fe6aa', - 'name': 'example template name', - 'versions': [ + internal const string SINGLE_TEMPLATE_JSON = @"{ + ""id"": ""e8ac01d5-a07a-4a71-b14c-4721136fe6aa"", + ""name"": ""example template name"", + ""versions"": [ { - 'id': 'de37d11b-082a-42c0-9884-c0c143015a47', - 'user_id': 1234, - 'template_id': 'd51480ba-ca3f-465c-bc3e-ceb71d73c38d', - 'active': 1, - 'name': 'example version', - 'html_content': '<%body%>Click to Reset', - 'plain_content': 'Click to Reset<%body%>', - 'subject': '<%subject%>', - 'updated_at': '2014-05-22 20:05:21' + ""id"": ""de37d11b-082a-42c0-9884-c0c143015a47"", + ""user_id"": 1234, + ""template_id"": ""d51480ba-ca3f-465c-bc3e-ceb71d73c38d"", + ""active"": 1, + ""name"": ""example version"", + ""html_content"": ""<%body%>Click to Reset"", + ""plain_content"": ""Click to Reset<%body%>"", + ""subject"": ""<%subject%>"", + ""updated_at"": ""2014-05-22 20:05:21"" } ] }"; - private const string MULTIPLE_TEMPLATES_JSON = @"{ - 'templates': [ + internal const string MULTIPLE_TEMPLATES_JSON = @"{ + ""templates"": [ { - 'id': 'e8ac01d5-a07a-4a71-b14c-4721136fe6aa', - 'name': 'example template name', - 'versions': [ + ""id"": ""e8ac01d5-a07a-4a71-b14c-4721136fe6aa"", + ""name"": ""example template name"", + ""versions"": [ { - 'id': '5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f', - 'template_id': '9c59c1fb-931a-40fc-a658-50f871f3e41c', - 'active': 1, - 'name': 'example version name', - 'updated_at': '2014-03-19 18:56:33' + ""id"": ""5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"", + ""template_id"": ""9c59c1fb-931a-40fc-a658-50f871f3e41c"", + ""active"": 1, + ""name"": ""example version name"", + ""updated_at"": ""2014-03-19 18:56:33"" } ] } ] }"; - private const string SINGLE_TEMPLATE_VERSION_JSON = @"{ - 'id': '8aefe0ee-f12b-4575-b5b7-c97e21cb36f3', - 'template_id': 'ddb96bbc-9b92-425e-8979-99464621b543', - 'active': 1, - 'name': 'example_version_name', - 'html_content': '<%body%>', - 'plain_content': '<%body%>', - 'subject': '<%subject%>', - 'updated_at': '2014-03-19 18:56:33' + internal const string SINGLE_TEMPLATE_VERSION_JSON = @"{ + ""id"": ""8aefe0ee-f12b-4575-b5b7-c97e21cb36f3"", + ""template_id"": ""ddb96bbc-9b92-425e-8979-99464621b543"", + ""active"": 1, + ""name"": ""example_version_name"", + ""html_content"": ""<%body%>"", + ""plain_content"": ""<%body%>"", + ""subject"": ""<%subject%>"", + ""updated_at"": ""2014-03-19 18:56:33"" }"; #endregion @@ -71,7 +71,7 @@ public void Parse_Template_json() // Arrange // Act - var result = JsonConvert.DeserializeObject