Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c442e79
Wired up template_data for client
jemeric May 30, 2025
84372e1
Reverted unintentional changes
jemeric May 30, 2025
74d1802
Fixed a couple more accidental changes
jemeric May 30, 2025
7b2714a
Trying dynamically created log for tests
jemeric Jun 4, 2025
da7e3f0
Updating .net version
jemeric Jun 4, 2025
e00138b
Update appveyor image
jemeric Jun 4, 2025
f17441b
Try again with updated framework target
jemeric Jun 5, 2025
dfa338f
Added Nuget config to try to fix appveyor issues
jemeric Jun 5, 2025
3088522
Try adding missing dependency for appveyor
jemeric Jun 5, 2025
1c7427b
Another attempt at fixing expired logs tests
jemeric Jun 5, 2025
4f91a6a
Switched void to Task for appropriate async syntax
jemeric Jun 5, 2025
8a000d1
Debugging invalid log id
jemeric Jun 5, 2025
caae8da
Upgrade NUnit to wait on async setup
jemeric Jun 5, 2025
aa24cd3
Added short wait before running tests
jemeric Jun 5, 2025
614eed1
Trying again using OneTimeSetup to fix synchronousity issues
jemeric Jun 5, 2025
04a676f
Trying Onetimesetup for API tests to see if it resolves other failures
jemeric Jun 5, 2025
df13f4a
Another attempt to force the setup to run synchronously
jemeric Jun 5, 2025
e66d158
Trying again with 1 second delay
jemeric Jun 5, 2025
7991de2
A bit of cleanup
jemeric Jun 5, 2025
cef4b47
Clean up extra spacing
jemeric Jun 5, 2025
ebd57b4
Bumped the log check delay
jemeric Jun 5, 2025
a0883d6
Going back to 1 second timeout since it seemed sufficient
jemeric Jun 6, 2025
38c7a48
Going back to 2s delay
jemeric Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>UPDATE</h1></body></html>"; // 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);
Expand Down Expand Up @@ -206,11 +210,14 @@ catch (AggregateException exception)
```csharp
var templateVersionName = "New Template Version";
var templateSubject = "New Version!";
var template_data = new Dictionary<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>NEW TEMPLATE VERSION</h1></body></html>"; // 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);
Expand Down Expand Up @@ -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<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>NEW TEMPLATE VERSION</h1></body></html>"; // 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);
Expand Down
7 changes: 7 additions & 0 deletions Sendwithus/Nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear /> <!-- Clear all inherited sources -->
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
4 changes: 4 additions & 0 deletions Sendwithus/SendwithusClient/API/Helpers/TemplateVersion.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace Sendwithus
{
Expand All @@ -17,6 +18,7 @@ public class TemplateVersion
public string text { get; set; }
public string subject { get; set; }
public string preheader { get; set; }
public Dictionary<string, object> template_data { get; set; }
public string locale { get; set; }
public bool published { get; set; }

Expand All @@ -37,6 +39,8 @@ public TemplateVersion(string name, string subject)
html = String.Empty;
text = String.Empty;
preheader = String.Empty;
template_data = new Dictionary<string, object>();
;
locale = String.Empty;
published = false;
}
Expand Down
5 changes: 4 additions & 1 deletion Sendwithus/SendwithusClient/SendwithusClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks>net8.0;net461</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>1701;1702;1705;1591</NoWarn>
<IsPackable>true</IsPackable>
Expand All @@ -21,4 +21,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions Sendwithus/SendwithusTest/SendwithusClientTest.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks>net8.0;net461</TargetFrameworks>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 26 additions & 6 deletions Sendwithus/SendwithusTest/Tests/BatchApiRequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@ public class BatchApiRequestTest
{
private const string DEFAULT_ESP_ACCOUNT_ID = "esp_e3ut7pFtWttcN4HNoQ8Vgm";
private const string DEFAULT_EMAIL_ADDRESS = "[email protected]";
private const string DEFAULT_LOG_ID = "log_e7c783fc7efca27006e043ca12282e9f-3";
private const string DEFAULT_TEMPLATE_ID = "tem_yn2viZ8Gm2uaydMK9pgR2B";
private string DEFAULT_LOG_ID;

/// <summary>
/// Sets the API
/// </summary>
[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<string, object>();
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(2000);
});

task.Wait(); // synchronously block
}
catch (Exception ex)
{
Assert.Fail(ex.ToString());
}
}

/// <summary>
Expand Down Expand Up @@ -78,7 +98,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
Expand Down Expand Up @@ -128,7 +148,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
Expand Down Expand Up @@ -157,7 +177,7 @@ public async Task TestBatchApiRequestsElevenRequestsWithoutOverrideAsync()
ValidateIndividualBatchedApiCallResponse<List<Snippet>>(batchResponses[1]);
ValidateIndividualBatchedApiCallResponse<Customer>(batchResponses[2]);
ValidateIndividualBatchedApiCallResponse<RenderTemplateResponse>(batchResponses[3]);
await Log.GetLogEventsAsync(BatchApiRequestTest.DEFAULT_LOG_ID); // GET
await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID); // GET
ValidateIndividualBatchedApiCallResponse<Customer>(batchResponses[5]);
ValidateIndividualBatchedApiCallResponse<EmailResponse>(batchResponses[6]);
ValidateIndividualBatchedApiCallResponse<List<DripCampaignDetails>>(batchResponses[7]);
Expand Down Expand Up @@ -192,7 +212,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
Expand Down
38 changes: 30 additions & 8 deletions Sendwithus/SendwithusTest/Tests/LogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,43 @@ namespace SendwithusTest
[TestFixture]
public class LogTest
{
private const string DEFAULT_LOG_ID = "log_e7c783fc7efca27006e043ca12282e9f-3";
private string DEFAULT_LOG_ID;
private const string DEFAULT_EMAIL_ADDRESS = "[email protected]";
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;


/// <summary>
/// Sets the API
/// Sets the API
/// </summary>
[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<string, object>();
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(2000);
});

task.Wait(); // synchronously block
}
catch (Exception ex)
{
Assert.Fail(ex.ToString());
}
}

/// <summary>
Expand All @@ -39,12 +61,12 @@ public void InitializeUnitTesting()
[Test]
public async Task TestGetLogAsync()
{
Trace.WriteLine(String.Format("GET /logs/{0}", DEFAULT_LOG_ID));
Trace.WriteLine(String.Format("GET /logs/{0}", this.DEFAULT_LOG_ID));

// Make the API call
try
{
var log = await Log.GetLogAsync(DEFAULT_LOG_ID);
var log = await Log.GetLogAsync(this.DEFAULT_LOG_ID);

// Validate the response
SendwithusClientTest.ValidateResponse(log);
Expand All @@ -62,12 +84,12 @@ 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);
var logEvents = await Log.GetLogEventsAsync(this.DEFAULT_LOG_ID);

// Validate the response
SendwithusClientTest.ValidateResponse(logEvents);
Expand All @@ -90,7 +112,7 @@ public async Task TestResendLogAsync()
// Make the API call
try
{
var logResendResponse = await Log.ResendLogAsync(DEFAULT_LOG_ID);
var logResendResponse = await Log.ResendLogAsync(this.DEFAULT_LOG_ID);

// Validate the response
SendwithusClientTest.ValidateResponse(logResendResponse);
Expand Down
10 changes: 10 additions & 0 deletions Sendwithus/SendwithusTest/Tests/TemplateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Net;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace SendwithusTest
{
Expand Down Expand Up @@ -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<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>NEW TEMPLATE VERSION</h1></body></html>";
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);
Expand Down Expand Up @@ -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<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>NEW TEMPLATE VERSION</h1></body></html>";
updatedTemplateVersion.text = "some text";
updatedTemplateVersion.preheader = "A Test Preheader";
updatedTemplateVersion.template_data = template_data;
try
{
var templateVersion = await Template.CreateTemplateVersion(DEFAULT_TEMPLATE_ID, updatedTemplateVersion);
Expand Down Expand Up @@ -748,11 +755,14 @@ public static async Task<Template> BuildAndSendCreateTemplateRequestWithAllParam
{
var templateVersionName = "New Template Version";
var templateSubject = "New Version!";
var template_data = new Dictionary<string, object>();
template_data.Add("amount", "$12.00");
var updatedTemplateVersion = new TemplateVersion(templateVersionName, templateSubject);
updatedTemplateVersion.html = "<html><head></head><body><h1>NEW TEMPLATE VERSION</h1></body></html>";
updatedTemplateVersion.text = "some text";
updatedTemplateVersion.locale = DEFAULT_LOCALE;
updatedTemplateVersion.preheader = "Test Preheader";
updatedTemplateVersion.template_data = template_data;
return await Template.CreateTemplateAsync(updatedTemplateVersion);
}

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: 2.3.{build}
version: 2.4.{build}

#---------------------------------#
# environment configuration #
#---------------------------------#

# Build worker image (VM template)
image: Visual Studio 2017
image: Visual Studio 2022

# scripts that are called at very beginning, before repo cloning
init:
Expand Down