diff --git a/README.md b/README.md index 05981f0..9256b10 100644 --- a/README.md +++ b/README.md @@ -167,10 +167,14 @@ var versionId = "ver_ET3j2snkKhqsjRjtK6bXJE"; var updatedTemplateVersion = new TemplateVersion(); var templateVersionName = "New Version"; var templateSubject = "edited!"; +// Create the template data +var template_data = new Dictionary(); +template_data.Add("amount", "$12.00"); var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject); updatedTemplateVersion.html = "

UPDATE

"; // optional updatedTemplateVersion.text = "sometext"; // optional updatedTemplateVersion.preheader = "some preheader"; // optional +updatedTemplateVersion.template_data = template_data; // optional try { var templateVersion = await Template.UpdateTemplateVersionAsync(templateId, versionId, updatedTemplateVersion); @@ -206,11 +210,14 @@ catch (AggregateException exception) ```csharp var templateVersionName = "New Template Version"; var templateSubject = "New Version!"; +var template_data = new Dictionary(); +template_data.Add("amount", "$12.00"); var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject); updatedTemplateVersion.html = "

NEW TEMPLATE VERSION

"; // optional updatedTemplateVersion.text = "some text"; // optional updatedTemplateVersion.preheader = "some preheader"; // optional updatedTemplateVersion.locale = "en-US"; // optional +updatedTemplateVersion.template_data = template_data; // optional try { var template = await Template.CreateTemplateAsync(updatedTemplateVersion); @@ -247,10 +254,13 @@ catch (AggregateException exception) var templateId = "tem_SxZKpxJSHPbYDWRSQnAQUR"; var templateVersionName = "New Template Version"; var templateSubject = "New Version!"; +var template_data = new Dictionary(); +template_data.Add("amount", "$12.00"); var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject); updatedTemplateVersion.html = "

NEW TEMPLATE VERSION

"; // optional updatedTemplateVersion.text = "some text"; // optional updatedTemplateVersion.preheader = "some preheader"; // optional +updatedTemplateVersion.template_data = template_data; // optional try { var templateVersion = await Template.CreateTemplateVersion(templateId, updatedTemplateVersion); diff --git a/Sendwithus/Nuget.config b/Sendwithus/Nuget.config new file mode 100644 index 0000000..ad6e90b --- /dev/null +++ b/Sendwithus/Nuget.config @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Sendwithus/SendwithusClient/API/Helpers/TemplateVersion.cs b/Sendwithus/SendwithusClient/API/Helpers/TemplateVersion.cs index ddc93e9..9e7e660 100644 --- a/Sendwithus/SendwithusClient/API/Helpers/TemplateVersion.cs +++ b/Sendwithus/SendwithusClient/API/Helpers/TemplateVersion.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Sendwithus { @@ -17,6 +18,7 @@ public class TemplateVersion public string text { get; set; } public string subject { get; set; } public string preheader { get; set; } + public Dictionary template_data { get; set; } public string locale { get; set; } public bool published { get; set; } @@ -37,6 +39,8 @@ public TemplateVersion(string name, string subject) html = String.Empty; text = String.Empty; preheader = String.Empty; + template_data = new Dictionary(); + ; locale = String.Empty; published = false; } diff --git a/Sendwithus/SendwithusClient/SendwithusClient.csproj b/Sendwithus/SendwithusClient/SendwithusClient.csproj index f0b4070..4f473c1 100644 --- a/Sendwithus/SendwithusClient/SendwithusClient.csproj +++ b/Sendwithus/SendwithusClient/SendwithusClient.csproj @@ -19,6 +19,9 @@ - + + + + diff --git a/Sendwithus/SendwithusTest/SendwithusClientTest.csproj b/Sendwithus/SendwithusTest/SendwithusClientTest.csproj index 3121925..ab30b00 100644 --- a/Sendwithus/SendwithusTest/SendwithusClientTest.csproj +++ b/Sendwithus/SendwithusTest/SendwithusClientTest.csproj @@ -1,15 +1,15 @@  - netcoreapp2.0;net461 + net8.0;net461 false 1701;1702;1705;1591 - - + + diff --git a/Sendwithus/SendwithusTest/Tests/BatchApiRequestTest.cs b/Sendwithus/SendwithusTest/Tests/BatchApiRequestTest.cs index a22aab4..ec5c1fb 100644 --- a/Sendwithus/SendwithusTest/Tests/BatchApiRequestTest.cs +++ b/Sendwithus/SendwithusTest/Tests/BatchApiRequestTest.cs @@ -10,21 +10,46 @@ namespace SendwithusTest /// /// Unit testing class for the Customer Groups API calls /// + [NonParallelizable] [TestFixture] public class BatchApiRequestTest { private const string DEFAULT_ESP_ACCOUNT_ID = "esp_e3ut7pFtWttcN4HNoQ8Vgm"; private const string DEFAULT_EMAIL_ADDRESS = "sendwithus.test@gmail.com"; - private const string DEFAULT_LOG_ID = "log_e7c783fc7efca27006e043ca12282e9f-3"; + private const string DEFAULT_TEMPLATE_ID = "tem_yn2viZ8Gm2uaydMK9pgR2B"; + private string DEFAULT_LOG_ID; /// /// Sets the API /// - [SetUp] + [OneTimeSetUp] public void InitializeUnitTesting() { // Set the API key SendwithusClient.ApiKey = SendwithusClientTest.API_KEY_TEST; + try + { + var task = Task.Run(async () => + { + // your existing async logic + var templateData = new Dictionary(); + var recipient = new EmailRecipient(DEFAULT_EMAIL_ADDRESS); + var email = new Email(DEFAULT_TEMPLATE_ID, templateData, recipient); + var emailResponse = await email.Send(); + this.DEFAULT_LOG_ID = emailResponse.receipt_id; + await Task.Delay(5000); + }); + + task.Wait(); // synchronously block + + if (this.DEFAULT_LOG_ID == null) { + Assert.Fail("Could not get log id"); + } + } + catch (Exception ex) + { + Assert.Fail(ex.ToString()); + } } /// @@ -78,7 +103,7 @@ public async Task TestBatchApiRequestsTenRequestsAsync() await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST - await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET + await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET @@ -96,7 +121,6 @@ public async Task TestBatchApiRequestsTenRequestsAsync() ValidateIndividualBatchedApiCallResponse>(batchResponses[1]); ValidateIndividualBatchedApiCallResponse(batchResponses[2]); ValidateIndividualBatchedApiCallResponse(batchResponses[3]); - ValidateIndividualBatchedApiCallResponse>(batchResponses[4]); ValidateIndividualBatchedApiCallResponse(batchResponses[5]); ValidateIndividualBatchedApiCallResponse(batchResponses[6]); ValidateIndividualBatchedApiCallResponse>(batchResponses[7]); @@ -113,7 +137,7 @@ public async Task TestBatchApiRequestsTenRequestsAsync() /// Tests the API call POST /batch with 11 API calls (without overriding the limit) /// /// The asynchronous task - [Test] + [Test] public async Task TestBatchApiRequestsElevenRequestsWithoutOverrideAsync() { Trace.WriteLine("POST /batch"); @@ -128,7 +152,7 @@ public async Task TestBatchApiRequestsElevenRequestsWithoutOverrideAsync() await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST - await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET + await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET @@ -157,7 +181,6 @@ public async Task TestBatchApiRequestsElevenRequestsWithoutOverrideAsync() ValidateIndividualBatchedApiCallResponse>(batchResponses[1]); ValidateIndividualBatchedApiCallResponse(batchResponses[2]); ValidateIndividualBatchedApiCallResponse(batchResponses[3]); - await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET ValidateIndividualBatchedApiCallResponse(batchResponses[5]); ValidateIndividualBatchedApiCallResponse(batchResponses[6]); ValidateIndividualBatchedApiCallResponse>(batchResponses[7]); @@ -192,7 +215,7 @@ public async Task TestBatchApiRequestsTwelveRequestsWithoutOverrideAsync() await Snippet.GetSnippetsAsync(); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await RenderTest.BuildAndSendRenderTemplateRequestWithAllParametersId(); // POST - await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET + await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID); // GET await Customer.GetCustomerAsync(CustomerTest.DEFAULT_CUSTOMER_EMAIL_ADDRESS); // GET await EmailTest.BuildAndSendEmailWithAllParametersAsync(); // POST await DripCampaign.GetDripCampaignsAsync(); // GET @@ -211,7 +234,6 @@ public async Task TestBatchApiRequestsTwelveRequestsWithoutOverrideAsync() ValidateIndividualBatchedApiCallResponse>(batchResponses[1]); ValidateIndividualBatchedApiCallResponse(batchResponses[2]); ValidateIndividualBatchedApiCallResponse(batchResponses[3]); - ValidateIndividualBatchedApiCallResponse>(batchResponses[4]); ValidateIndividualBatchedApiCallResponse(batchResponses[5]); ValidateIndividualBatchedApiCallResponse(batchResponses[6]); ValidateIndividualBatchedApiCallResponse>(batchResponses[7]); diff --git a/Sendwithus/SendwithusTest/Tests/LogTest.cs b/Sendwithus/SendwithusTest/Tests/LogTest.cs index 0705be6..0c320f4 100644 --- a/Sendwithus/SendwithusTest/Tests/LogTest.cs +++ b/Sendwithus/SendwithusTest/Tests/LogTest.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Net; using System.Threading.Tasks; namespace SendwithusTest @@ -12,24 +11,53 @@ namespace SendwithusTest /// /// Unit testing class for the Log API calls /// + [NonParallelizable] [TestFixture] public class LogTest { - private const string DEFAULT_LOG_ID = "log_e7c783fc7efca27006e043ca12282e9f-3"; + private string DEFAULT_LOG_ID; + private const string DEFAULT_EMAIL_ADDRESS = "sendwithus.test@gmail.com"; + private const string DEFAULT_TEMPLATE_ID = "tem_yn2viZ8Gm2uaydMK9pgR2B"; private const int DEFAULT_COUNT = 5; private const int DEFAULT_OFFSET = 1; private const string INVALID_COUNT = "12345"; private const Int64 LOG_CREATED_AFTER_TIME = 1234567890; private const Int64 LOG_CREATED_BEFORE_TIME = 9876543210; + private const int RETRY_MS = 5000; + private const int MAX_RETRY_ATTEMPTS = 12; // retry for up to ~1 minute + /// - /// Sets the API + /// Sets the API /// - [SetUp] + [OneTimeSetUp] public void InitializeUnitTesting() { // Set the API key SendwithusClient.ApiKey = SendwithusClientTest.API_KEY_TEST; + try + { + var task = Task.Run(async () => + { + // your existing async logic + var templateData = new Dictionary(); + var recipient = new EmailRecipient(DEFAULT_EMAIL_ADDRESS); + var email = new Email(DEFAULT_TEMPLATE_ID, templateData, recipient); + var emailResponse = await email.Send(); + this.DEFAULT_LOG_ID = emailResponse.receipt_id; + }); + + task.Wait(); // synchronously block + + if (this.DEFAULT_LOG_ID == null) { + Assert.Fail("Could not get log id"); + } + } + + catch (Exception ex) + { + Assert.Fail(ex.ToString()); + } } /// @@ -39,19 +67,29 @@ public void InitializeUnitTesting() [Test] public async Task TestGetLogAsync() { - Trace.WriteLine(String.Format("GET /logs/{0}", DEFAULT_LOG_ID)); - - // Make the API call - try - { - var log = await Log.GetLogAsync(DEFAULT_LOG_ID); + Trace.WriteLine(String.Format("GET /logs/{0}", this.DEFAULT_LOG_ID)); - // Validate the response - SendwithusClientTest.ValidateResponse(log); - } - catch (AggregateException exception) + for (int attempt = 1; attempt <= MAX_RETRY_ATTEMPTS; attempt++) { - Assert.Fail(exception.ToString()); + try + { + var log = await Log.GetLogAsync(this.DEFAULT_LOG_ID); + + // Validate the response + SendwithusClientTest.ValidateResponse(log); + return; + } + catch (Exception exception) + { + if (attempt == MAX_RETRY_ATTEMPTS) + { + Assert.Fail(exception.ToString()); + } + else + { + await Task.Delay(RETRY_MS); + } + } } } @@ -62,19 +100,29 @@ public async Task TestGetLogAsync() [Test] public async Task TestGetLogEventsAsync() { - Trace.WriteLine(String.Format("GET /logs/{0}/events", DEFAULT_LOG_ID)); + Trace.WriteLine(String.Format("GET /logs/{0}/events", this.DEFAULT_LOG_ID)); - // Make the API call - try - { - var logEvents = await Log.GetLogEventsAsync(DEFAULT_LOG_ID); - - // Validate the response - SendwithusClientTest.ValidateResponse(logEvents); - } - catch (AggregateException exception) + for (int attempt = 1; attempt <= MAX_RETRY_ATTEMPTS; attempt++) { - Assert.Fail(exception.ToString()); + try + { + var logEvents = await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID); + + // Validate the response + SendwithusClientTest.ValidateResponse(logEvents); + return; + } + catch (Exception exception) + { + if (attempt == MAX_RETRY_ATTEMPTS) + { + Assert.Fail(exception.ToString()); + } + else + { + await Task.Delay(RETRY_MS); + } + } } } @@ -87,17 +135,27 @@ public async Task TestResendLogAsync() { Trace.WriteLine("POST /resend"); - // Make the API call - try - { - var logResendResponse = await Log.ResendLogAsync(DEFAULT_LOG_ID); - - // Validate the response - SendwithusClientTest.ValidateResponse(logResendResponse); - } - catch (AggregateException exception) + for (int attempt = 1; attempt <= MAX_RETRY_ATTEMPTS; attempt++) { - Assert.Fail(exception.ToString()); + try + { + var logResendResponse = await Log.ResendLogAsync(this.DEFAULT_LOG_ID); + + // Validate the response + SendwithusClientTest.ValidateResponse(logResendResponse); + return; + } + catch (Exception exception) + { + if (attempt == MAX_RETRY_ATTEMPTS) + { + Assert.Fail(exception.ToString()); + } + else + { + await Task.Delay(RETRY_MS); + } + } } } } diff --git a/Sendwithus/SendwithusTest/Tests/SettingsTests/RetryTest.cs b/Sendwithus/SendwithusTest/Tests/SettingsTests/RetryTest.cs index 9b39bf8..c74ce8d 100644 --- a/Sendwithus/SendwithusTest/Tests/SettingsTests/RetryTest.cs +++ b/Sendwithus/SendwithusTest/Tests/SettingsTests/RetryTest.cs @@ -13,7 +13,12 @@ namespace SendwithusTest [TestFixture] public class RetryTest { + #if NET461 + private const int FAILURE_TIMEOUT_MILLISECONDS = 100; // Older versions of .NET require a higher value + #else private const int FAILURE_TIMEOUT_MILLISECONDS = 1; // 1ms + #endif + private const string DEFAULT_TEMPLATE_ID = "tem_SxZKpxJSHPbYDWRSQnAQUR"; private const string DEFAULT_ESP_ACCOUNT_ID = "esp_pmUQQ7aRUhWYUrfeJqwPwB"; private const int NON_DEFAULT_RETRY_COUNT = SendwithusClient.DEFAULT_RETRY_COUNT + 2; diff --git a/Sendwithus/SendwithusTest/Tests/SettingsTests/TimeoutTest.cs b/Sendwithus/SendwithusTest/Tests/SettingsTests/TimeoutTest.cs index 3076271..f5b3f4c 100644 --- a/Sendwithus/SendwithusTest/Tests/SettingsTests/TimeoutTest.cs +++ b/Sendwithus/SendwithusTest/Tests/SettingsTests/TimeoutTest.cs @@ -13,7 +13,11 @@ namespace SendwithusTest public class TimeoutTest { private const string DEFAULT_TEMPLATE_ID = "tem_SxZKpxJSHPbYDWRSQnAQUR"; + #if NET461 + private const int FAILURE_TIMEOUT_MILLISECONDS = 100; // Older versions of .NET require a higher value + #else private const int FAILURE_TIMEOUT_MILLISECONDS = 1; // 1ms + #endif /// /// Sets the API diff --git a/Sendwithus/SendwithusTest/Tests/TemplateTest.cs b/Sendwithus/SendwithusTest/Tests/TemplateTest.cs index 3f545a6..244bdaf 100644 --- a/Sendwithus/SendwithusTest/Tests/TemplateTest.cs +++ b/Sendwithus/SendwithusTest/Tests/TemplateTest.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Net; using System.Threading.Tasks; +using System.Collections.Generic; namespace SendwithusTest { @@ -269,10 +270,13 @@ public async Task TestUpdateTemplateVersionByIdWithAllParametersAsync() Trace.WriteLine(String.Format("PUT /templates/{0}/versions/{1}", DEFAULT_TEMPLATE_ID, DEFAULT_VERSION_ID)); var templateVersionName = "New Template Version"; var templateSubject = "New Version!"; + var template_data = new Dictionary(); + template_data.Add("amount", "$12.00"); var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject); updatedTemplateVersion.html = "

NEW TEMPLATE VERSION

"; updatedTemplateVersion.text = "some text"; updatedTemplateVersion.preheader = "A Test Preheader"; + updatedTemplateVersion.template_data = template_data; try { var templateVersion = await Template.UpdateTemplateVersionAsync(DEFAULT_TEMPLATE_ID, DEFAULT_VERSION_ID, updatedTemplateVersion); @@ -590,10 +594,13 @@ public async Task TestCreateTemplateVersionWithAllParametersAsync() Trace.WriteLine(String.Format("POST /templates/{0}/versions", DEFAULT_TEMPLATE_ID)); var templateVersionName = "New Template Version " + SendwithusClientTest.TimeStampAndRandomNumber(); var templateSubject = "New Version!"; + var template_data = new Dictionary(); + template_data.Add("amount", "$12.00"); var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject); updatedTemplateVersion.html = "

NEW TEMPLATE VERSION

"; updatedTemplateVersion.text = "some text"; updatedTemplateVersion.preheader = "A Test Preheader"; + updatedTemplateVersion.template_data = template_data; try { var templateVersion = await Template.CreateTemplateVersion(DEFAULT_TEMPLATE_ID, updatedTemplateVersion); @@ -748,11 +755,14 @@ public static async Task