diff --git a/.gitignore b/.gitignore
index 20cf3ed..1ef2e15 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# Created with the help of https://www.gitignore.io/api/visualstudio
+
+### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
@@ -17,14 +20,15 @@
[Rr]eleases/
x64/
x86/
+bld/
[Bb]in/
[Oo]bj/
+[Ll]og/
-# Roslyn cache directories
-*.ide/
-
-# Visual Studo 2015 cache/options directory
+# Visual Studio 2015 cache/options directory
.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
@@ -39,6 +43,11 @@ TestResult.xml
[Rr]eleasePS/
dlldata.c
+# DNX
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
*_i.c
*_p.c
*_i.h
@@ -61,7 +70,6 @@ dlldata.c
*.vssscc
.builds
*.pidb
-*.log
*.svclog
*.scc
@@ -72,14 +80,18 @@ _Chutzpah*
ipch/
*.aps
*.ncb
+*.opendb
*.opensdf
*.sdf
*.cachefile
+*.VC.db
+*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
+*.sap
# TFS 2012 Local Workspace
$tf/
@@ -92,7 +104,7 @@ _ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
-# JustCode is a .NET coding addin-in
+# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
@@ -101,9 +113,14 @@ _TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
# NCrunch
_NCrunch_*
.*crunch*.local.xml
+nCrunchTemp_*
# MightyMoose
*.mm.*
@@ -131,39 +148,63 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
-# TODO: Comment the next line if you want to checkin your web deploy settings
+# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
-# If using the old MSBuild-Integrated Package Restore, uncomment this:
+# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
+# NuGet v3's project.json files produces more ignoreable files
+*.nuget.props
+*.nuget.targets
-# Windows Azure Build Output
+# Microsoft Azure Build Output
csx/
*.build.csdef
-# Windows Store app package directory
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
-# Others
+# Visual Studio cache files
+# files ending in .cache can be ignored
*.[Cc]ache
+# but keep track of directories ending in .cache
+!*.[Cc]ache/
+
+# Others
ClientBin/
-[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
+*.jfm
*.pfx
*.publishsettings
node_modules/
-bower_components/
+orleans.codegen.cs
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
# RIA/Silverlight projects
Generated_Code/
@@ -188,6 +229,9 @@ UpgradeLog*.htm
# Microsoft Fakes
FakesAssemblies/
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
@@ -197,25 +241,50 @@ FakesAssemblies/
# Visual Studio 6 workspace options file
*.opt
-#LightSwitch generated files
-GeneratedArtifacts/
-_Pvt_Extensions/
-ModelManifest.xml
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# JetBrains Rider
+.idea/
+*.sln.iml
+
+# CodeRush
+.cr/
# WinMerge
*.bak
-# Code coverage data and reports
-CodeCoverageData/
-CodeCoverageReport/
+# Supercharger: http://supercharger.tools/
+*.scgdat
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake
+tools/
+
+### VisualStudio Patch ###
+build/
# =========================
# Operating System Files
# =========================
-# OSX
-# =========================
+# ---------- OSX ----------
.DS_Store
.AppleDouble
@@ -235,8 +304,7 @@ Network Trash Folder
Temporary Items
.apdisk
-# Windows
-# =========================
+# -------- Windows --------
# Windows image file caches
Thumbs.db
diff --git a/.nuget/packages.config b/.nuget/packages.config
deleted file mode 100644
index a6afa48..0000000
--- a/.nuget/packages.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.IntegrationTests/App.config b/CakeMail.RestClient.IntegrationTests/App.config
deleted file mode 100644
index 789867b..0000000
--- a/CakeMail.RestClient.IntegrationTests/App.config
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj b/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj
deleted file mode 100644
index 85429ed..0000000
--- a/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.csproj
+++ /dev/null
@@ -1,87 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {677D93C3-10C8-47AC-B196-60CA28F57A84}
- Exe
- Properties
- CakeMail.RestClient.IntegrationTests
- CakeMail.RestClient.IntegrationTests
- v4.5.2
- 512
-
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
- True
-
-
- ..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {86c4afc4-0c39-42c5-86a3-68462ea966df}
- CakeMail.RestClient
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.IntegrationTests/packages.config b/CakeMail.RestClient.IntegrationTests/packages.config
deleted file mode 100644
index ef6a3d4..0000000
--- a/CakeMail.RestClient.IntegrationTests/packages.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj b/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj
deleted file mode 100644
index 05f8498..0000000
--- a/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.csproj
+++ /dev/null
@@ -1,134 +0,0 @@
-
-
-
- Debug
- AnyCPU
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}
- Library
- Properties
- CakeMail.RestClient.UnitTests
- CakeMail.RestClient.UnitTests
- v4.5.2
- 512
- {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 10.0
- $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
- $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
- False
- UnitTest
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll
- True
-
-
- ..\packages\Moq.4.5.21\lib\net45\Moq.dll
- True
-
-
- ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
- True
-
-
- ..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll
- True
-
-
- ..\packages\Shouldly.2.8.2\lib\net451\Shouldly.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {86c4afc4-0c39-42c5-86a3-68462ea966df}
- CakeMail.RestClient
-
-
-
-
-
-
-
-
-
- False
-
-
- False
-
-
- False
-
-
- False
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs b/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs
deleted file mode 100644
index 1cfd74d..0000000
--- a/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs
+++ /dev/null
@@ -1,292 +0,0 @@
-using CakeMail.RestClient.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Moq;
-using RestSharp;
-using Shouldly;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient.UnitTests
-{
- [TestClass]
- public class CakeMailRestClientTests
- {
- private const string API_KEY = "...dummy API key...";
- private const string USER_KEY = "...dummy USER key...";
- private const long CLIENT_ID = 999;
-
- [TestMethod]
- public void RestClient_constructor()
- {
- // Arrange
- var mockHost = "myhost";
- var mockProxyHost = "localhost";
- var mockProxyPort = 8888;
- var mockTimeout = 777;
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockHost, mockTimeout, new WebProxy(mockProxyHost, mockProxyPort));
- var userAgent = apiClient.UserAgent;
- var userAgentParts = userAgent.Split(new[] { ';' });
- var baseUrl = apiClient.BaseUrl;
- var timeout = apiClient.Timeout;
- var proxy = apiClient.Proxy;
-
- // Assert
- userAgentParts[0].ShouldBe("CakeMail .NET REST Client");
- baseUrl.ShouldBe(new Uri($"https://{mockHost}"));
- timeout.ShouldBe(mockTimeout);
- ((WebProxy)proxy).Address.ShouldBe(new Uri(string.Format("http://{0}:{1}", mockProxyHost, mockProxyPort)));
- }
-
- [TestMethod]
- public void RestClient_constructor_with_IRestClient()
- {
- // Arrange
- var mockUserAgent = "... this is a mock user agent string ...";
- var mockProxyHost = "localhost";
- var mockProxyPort = 8888;
- var mockBaseUrl = new Uri("http://127.0.0.1");
- var mockTimeout = 777;
-
- var mockRestClient = new Mock(MockBehavior.Strict);
- mockRestClient.Setup(m => m.UserAgent).Returns(mockUserAgent);
- mockRestClient.Setup(m => m.Proxy).Returns(new WebProxy(mockProxyHost, mockProxyPort));
- mockRestClient.Setup(m => m.BaseUrl).Returns(mockBaseUrl);
- mockRestClient.Setup(m => m.Timeout).Returns(mockTimeout);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var userAgent = apiClient.UserAgent;
- var baseUrl = apiClient.BaseUrl;
- var timeout = apiClient.Timeout;
- var proxy = apiClient.Proxy;
-
- // Assert
- userAgent.ShouldBe(mockUserAgent);
- baseUrl.ShouldBe(mockBaseUrl);
- timeout.ShouldBe(mockTimeout);
- ((WebProxy)proxy).Address.ShouldBe(new Uri(string.Format("http://{0}:{1}", mockProxyHost, mockProxyPort)));
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsestatus_is_error()
- {
- // Arrange
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), ResponseStatus.Error, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsestatus_is_timeout()
- {
- // Arrange
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), ResponseStatus.TimedOut, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_request_is_successful_but_response_content_is_empty()
- {
- // Arrange
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), "", false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(CakeMailException))]
- public async Task RestClient_Throws_exception_when_request_is_successful_but_response_contenttype_is_not_specified()
- {
- // Arrange
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), "dummy content", false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsescode_is_between_400_and_499_and_content_is_empty()
- {
- // Arrange
- var response = new RestResponse
- {
- ResponseStatus = RestSharp.ResponseStatus.Completed,
- StatusCode = HttpStatusCode.Forbidden,
- Content = ""
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsescode_is_between_400_and_499_and_content_is_not_empty()
- {
- // Arrange
- var response = new RestResponse
- {
- ResponseStatus = RestSharp.ResponseStatus.Completed,
- StatusCode = HttpStatusCode.Forbidden,
- Content = "dummy content"
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsescode_is_between_500_and_599()
- {
- // Arrange
- var response = new RestResponse
- {
- ResponseStatus = RestSharp.ResponseStatus.Completed,
- StatusCode = HttpStatusCode.InternalServerError
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsescode_is_greater_than_599()
- {
- // Arrange
- var response = new RestResponse
- {
- ResponseStatus = RestSharp.ResponseStatus.Completed,
- StatusCode = (HttpStatusCode)600
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(HttpException))]
- public async Task RestClient_Throws_exception_when_responsecode_is_greater_than_599_and_custom_errormessage()
- {
- // Arrange
- var response = new RestResponse
- {
- ResponseStatus = RestSharp.ResponseStatus.Completed,
- StatusCode = (HttpStatusCode)600,
- ErrorMessage = "This is a bogus error message"
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync();
- }
-
- [TestMethod]
- [ExpectedException(typeof(CakeMailException))]
- public async Task RestClient_Throws_exception_when_cakemail_api_returns_failure()
- {
- // Arrange
- var response = new RestResponse
- {
- StatusCode = HttpStatusCode.OK,
- ContentType = "json",
- Content = "{\"status\":\"failure\",\"data\":\"An error has occured\"}"
- };
- var mockRestClient = new MockRestClient("/Country/GetList/", Enumerable.Empty(), response, false);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Countries.GetListAsync().ConfigureAwait(false);
- }
-
- [TestMethod]
- [ExpectedException(typeof(CakeMailPostException))]
- public async Task RestClient_Throws_exception_when_cakemail_api_returns_failure_with_post_details()
- {
- // Arrange
- var campaignId = 123L;
- var jsonResponse = string.Format("{{\"status\":\"failed\",\"data\":\"There is no campaign with the id {0} and client id {1}!\",\"post\":{{\"user_key\":\"{2}\",\"campaign_id\":\"{0}\",\"client_id\":\"{1}\"}}}}", campaignId, CLIENT_ID, USER_KEY);
- var parameters = new Parameter[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var mockRestClient = new MockRestClient("/Campaign/Delete/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID);
- }
-
- [TestMethod]
- [ExpectedException(typeof(CakeMailException))]
- public async Task RestClient_Throws_exception_when_reponse_contains_invalid_json()
- {
- // Arrange
- var campaignId = 123L;
- var jsonResponse = "{\"status\":\"success\",\"data\":\"{This content is not valid json (missing closing brackets)\"";
- var parameters = new Parameter[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var mockRestClient = new MockRestClient("/Campaign/Delete/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID);
- }
-
- [TestMethod]
- [ExpectedException(typeof(CakeMailException))]
- public async Task RestClient_Throws_exception_when_reponse_does_not_contain_expected_property()
- {
- // Arrange
- var categoryId = 123;
- var labels = new Dictionary
- {
- { "en_US", "My Category" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"we_expected_a_property_named_id_but_instead_we_received_this_bogus_property\":\"{0}\"}}}}", categoryId);
- var parameters = new Parameter[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Category" }
- };
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/Lists.cs b/CakeMail.RestClient.UnitTests/Lists.cs
deleted file mode 100644
index 32aa4f9..0000000
--- a/CakeMail.RestClient.UnitTests/Lists.cs
+++ /dev/null
@@ -1,2422 +0,0 @@
-using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
-using Shouldly;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient.UnitTests
-{
- [TestClass]
- public class ListsTests
- {
- private const long CLIENT_ID = 999;
-
- [TestMethod]
- public async Task CreateList_with_minimal_parameters()
- {
- // Arrange
- var name = "My new list";
- var defaultSenderName = "Bob Smith";
- var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = defaultSenderName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = defaultSenderAddress }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
- var mockRestClient = new MockRestClient("/List/Create/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.CreateAsync(MockRestClient.USER_KEY, name, defaultSenderName, defaultSenderAddress);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task CreateList_with_spampolicyaccepted()
- {
- // Arrange
- var name = "My new list";
- var defaultSenderName = "Bob Smith";
- var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = defaultSenderName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = defaultSenderAddress },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_policy", Value = "accepted" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
- var mockRestClient = new MockRestClient("/List/Create/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.CreateAsync(MockRestClient.USER_KEY, name, defaultSenderName, defaultSenderAddress, spamPolicyAccepted: true);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task CreateList_with_clientid()
- {
- // Arrange
- var name = "My new list";
- var defaultSenderName = "Bob Smith";
- var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = defaultSenderName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = defaultSenderAddress },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
- var mockRestClient = new MockRestClient("/List/Create/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.CreateAsync(MockRestClient.USER_KEY, name, defaultSenderName, defaultSenderAddress, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task DeleteList_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/Delete/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteAsync(MockRestClient.USER_KEY, listId, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteList_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/Delete/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteAsync(MockRestClient.USER_KEY, listId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetList_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
-
- // Actt
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task GetList_with_includestatistics_true()
- {
- await GetList_with_includestatistics(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task GetList_with_includestatistics_false()
- {
- await GetList_with_includestatistics(false).ConfigureAwait(false);
- }
-
- private async Task GetList_with_includestatistics(bool includeStatistics)
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = includeStatistics ? "false" : "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, includeStatistics: includeStatistics);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task GetList_with_calculateengagement_true()
- {
- await GetList_with_calculateengagement(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task GetList_with_calculateengagement_false()
- {
- await GetList_with_calculateengagement(false).ConfigureAwait(false);
- }
-
- private async Task GetList_with_calculateengagement(bool calculateEngagement)
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = calculateEngagement ? "true" : "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, calculateEngagement: calculateEngagement);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task GetList_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(listId);
- }
-
- [TestMethod]
- public async Task GetLists_with_status()
- {
- // Arrange
- var status = ListStatus.Active;
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, status: status);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_name()
- {
- // Arrange
- var name = "Dummy List";
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, name: name);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_sortby()
- {
- // Arrange
- var sortBy = ListsSortBy.Name;
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sort_by", Value = sortBy.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, sortBy: sortBy);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_sortdirection()
- {
- // Arrange
- var sortDirection = SortDirection.Ascending;
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "direction", Value = sortDirection.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, sortDirection: sortDirection);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_limit()
- {
- // Arrange
- var limit = 5;
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, limit: limit);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_offset()
- {
- // Arrange
- var offset = 25;
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, offset: offset);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetLists_with_clientid()
- {
- // Arrange
- var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetListsAsync(MockRestClient.USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(123);
- result.ToArray()[1].Id.ShouldBe(456);
- }
-
- [TestMethod]
- public async Task GetListsCount_with_status()
- {
- // Arrange
- var status = ListStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, status: status);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListsCount_with_name()
- {
- // Arrange
- var name = "Dummy List";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, name: name);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListsCount_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetCountAsync(MockRestClient.USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task UpdateList_name()
- {
- // Arrange
- var listId = 12345L;
- var name = "My list";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, name: name);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_language()
- {
- // Arrange
- var listId = 12345L;
- var language = "fr-FR";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "language", Value = language }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, language: language);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_spampolicy_accepted()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_policy", Value = "accepted" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, spamPolicyAccepted: true);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_spampolicy_declined()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_policy", Value = "declined" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, spamPolicyAccepted: false);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_status()
- {
- // Arrange
- var listId = 12345L;
- var status = ListStatus.Archived;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, status: status);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_sendername()
- {
- // Arrange
- var listId = 12345L;
- var senderName = "Bob Smith";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = senderName }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, senderName: senderName);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_senderemail()
- {
- // Arrange
- var listId = 12345L;
- var senderEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = senderEmail }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, senderEmail: senderEmail);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_gotooi()
- {
- // Arrange
- var listId = 12345L;
- var goto_oi = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "goto_oi", Value = goto_oi }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, goto_oi: goto_oi);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_gotodi()
- {
- // Arrange
- var listId = 12345L;
- var goto_di = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "goto_di", Value = goto_di }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, goto_di: goto_di);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_gotooo()
- {
- // Arrange
- var listId = 12345L;
- var goto_oo = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "goto_oo", Value = goto_oo }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, goto_oo: goto_oo);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_webhook()
- {
- // Arrange
- var listId = 12345L;
- var webhook = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "webhook", Value = webhook }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, webhook: webhook);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateList_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task AddListField_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var name = "My field";
- var fieldType = FieldType.Text;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "field", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = fieldType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = "add" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/EditStructure/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.AddFieldAsync(MockRestClient.USER_KEY, listId, name, fieldType);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task AddListField_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var name = "My field";
- var fieldType = FieldType.Integer;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "field", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = fieldType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = "add" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/EditStructure/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.AddFieldAsync(MockRestClient.USER_KEY, listId, name, fieldType, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteListField_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var name = "My field";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "field", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = "delete" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/EditStructure/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteFieldAsync(MockRestClient.USER_KEY, listId, name);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteListField_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var name = "My field";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "field", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = "delete" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/EditStructure/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteFieldAsync(MockRestClient.USER_KEY, listId, name, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetListFields_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"id\":\"integer\",\"email\":\"text\",\"registered\":\"timestamp\"}}";
- var mockRestClient = new MockRestClient("/List/GetFields/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task GetListFields_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"id\":\"integer\",\"email\":\"text\",\"registered\":\"timestamp\"}}";
- var mockRestClient = new MockRestClient("/List/GetFields/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task GetListFields_returns_null()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":null}";
- var mockRestClient = new MockRestClient("/List/GetFields/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetFieldsAsync(MockRestClient.USER_KEY, listId, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task AddTestEmail_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/AddTestEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.AddTestEmailAsync(MockRestClient.USER_KEY, listId, email);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task AddTestEmail_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/AddTestEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.AddTestEmailAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteTestEmail_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteTestEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteTestEmailAsync(MockRestClient.USER_KEY, listId, email);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteTestEmail_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteTestEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteTestEmailAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetTestEmails_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var testEmail1 = "aaa@aaa.com";
- var testEmail2 = "bbb@bbb.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"testemails\":[\"{0}\",\"{1}\"]}}}}", testEmail1, testEmail2);
- var mockRestClient = new MockRestClient("/List/GetTestEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetTestEmailsAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].ShouldBe(testEmail1);
- result.ToArray()[1].ShouldBe(testEmail2);
- }
-
- [TestMethod]
- public async Task GetTestEmails_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var testEmail1 = "aaa@aaa.com";
- var testEmail2 = "bbb@bbb.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"testemails\":[\"{0}\",\"{1}\"]}}}}", testEmail1, testEmail2);
- var mockRestClient = new MockRestClient("/List/GetTestEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetTestEmailsAsync(MockRestClient.USER_KEY, listId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].ShouldBe(testEmail1);
- result.ToArray()[1].ShouldBe(testEmail2);
- }
-
- [TestMethod]
- public async Task Subscribe_with_autoresponders_true()
- {
- await Subscribe_with_autoresponders(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task Subscribe_with_autoresponders_false()
- {
- await Subscribe_with_autoresponders(false).ConfigureAwait(false);
- }
-
- private async Task Subscribe_with_autoresponders(bool autoResponder)
- {
- // Arrange
- var listId = 12345L;
- var email = "aaa@aaa.com";
- var subscriberId = 777L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = autoResponder ? "true" : "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
- var mockRestClient = new MockRestClient("/List/SubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, autoResponders: autoResponder);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(subscriberId);
- }
-
- [TestMethod]
- public async Task Subscribe_with_triggers_true()
- {
- await Subscribe_with_triggers(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task Subscribe_with_triggers_false()
- {
- await Subscribe_with_triggers(false).ConfigureAwait(false);
- }
-
- private async Task Subscribe_with_triggers(bool triggers)
- {
- // Arrange
- var listId = 12345L;
- var email = "aaa@aaa.com";
- var subscriberId = 777;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = triggers ? "true" : "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
- var mockRestClient = new MockRestClient("/List/SubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, triggers: triggers);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(subscriberId);
- }
-
- [TestMethod]
- public async Task Subscribe_with_customfields()
- {
- // Arrange
- var listId = 12345L;
- var email = "aaa@aaa.com";
- var subscriberId = 777;
- var firstName = "Bob";
- var lastName = "Smith";
- var customFields = new[]
- {
- new KeyValuePair("firstname", firstName),
- new KeyValuePair("lastname", lastName),
- new KeyValuePair("birthday", new DateTime(1973, 1, 1))
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "data[firstname]", Value = firstName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "data[lastname]", Value = lastName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "data[birthday]", Value = "1973-01-01 00:00:00" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
- var mockRestClient = new MockRestClient("/List/SubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, customFields: customFields);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(subscriberId);
- }
-
- [TestMethod]
- public async Task Subscribe_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var email = "aaa@aaa.com";
- var subscriberId = 777;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
- var mockRestClient = new MockRestClient("/List/SubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.SubscribeAsync(MockRestClient.USER_KEY, listId, email, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(subscriberId);
- }
-
- [TestMethod]
- public async Task Import_with_autoresponders_true()
- {
- await Import_with_autoresponders(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task Import_with_autoresponders_false()
- {
- await Import_with_autoresponders(false).ConfigureAwait(false);
- }
-
- private async Task Import_with_autoresponders(bool autoResponder)
- {
- // Arrange
- var listId = 12345L;
- var listMembers = new[]
- {
- new ListMember { Email = "aaa@aaa.com" },
- new ListMember { Email = "bbb@bbb.com" }
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "import_to", Value = "active" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = autoResponder ? "true" : "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][email]", Value = "aaa@aaa.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][email]", Value = "bbb@bbb.com" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
- var mockRestClient = new MockRestClient("/List/Import/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, autoResponders: autoResponder);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task Import_with_triggers_true()
- {
- await Import_with_triggers(true).ConfigureAwait(false);
- }
-
- [TestMethod]
- public async Task Import_with_triggers_false()
- {
- await Import_with_triggers(false).ConfigureAwait(false);
- }
-
- private async Task Import_with_triggers(bool triggers)
- {
- // Arrange
- var listId = 12345L;
- var listMembers = new[]
- {
- new ListMember { Email = "aaa@aaa.com" },
- new ListMember { Email = "bbb@bbb.com" }
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "import_to", Value = "active" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = triggers ? "true" : "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][email]", Value = "aaa@aaa.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][email]", Value = "bbb@bbb.com" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
- var mockRestClient = new MockRestClient("/List/Import/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, triggers: triggers);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task Import_with_customfields()
- {
- // Arrange
- var listId = 12345L;
- var listMembers = new[]
- {
- new ListMember { Email = "aaa@aaa.com", CustomFields = new Dictionary { { "firstname", "Bob" }, { "lastname", "Smith" }, { "age", 41 }, { "birthday", new DateTime(1973, 1, 1) } } },
- new ListMember { Email = "bbb@bbb.com", CustomFields = new Dictionary { { "firstname", "Jane" }, { "lastname", "Doe" }, { "age", 50 }, { "birthday", new DateTime(1964, 1, 1) } } }
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "import_to", Value = "active" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][email]", Value = "aaa@aaa.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][firstname]", Value = "Bob" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][lastname]", Value = "Smith" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][age]", Value = 41 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][birthday]", Value = "1973-01-01 00:00:00" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][email]", Value = "bbb@bbb.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][firstname]", Value = "Jane" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][lastname]", Value = "Doe" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][age]", Value = 50 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][birthday]", Value = "1964-01-01 00:00:00" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
- var mockRestClient = new MockRestClient("/List/Import/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, autoResponders: true);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task Import_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var listMembers = new[]
- {
- new ListMember { Email = "aaa@aaa.com" },
- new ListMember { Email = "bbb@bbb.com" }
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "import_to", Value = "active" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[0][email]", Value = "aaa@aaa.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record[1][email]", Value = "bbb@bbb.com" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
- var mockRestClient = new MockRestClient("/List/Import/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task Import_zero_subscribers()
- {
- // Arrange
- var listId = 12345L;
- var listMembers = (ListMember[])null;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "import_to", Value = "active" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "autoresponders", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "triggers", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
- var mockRestClient = new MockRestClient("/List/Import/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.ImportAsync(MockRestClient.USER_KEY, listId, listMembers);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task Unsubscribe_by_email()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UnsubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, email, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task Unsubscribe_by_email_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var email = "test@test.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UnsubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, email, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task Unsubscribe_by_memberid()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UnsubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, memberId, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task Unsubscribe_by_memberid_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UnsubscribeEmail/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UnsubscribeAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteListMember()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteMemberAsync(MockRestClient.USER_KEY, listId, memberId, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task DeleteListMember_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.DeleteMemberAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetListMember()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}}}", memberId);
- var mockRestClient = new MockRestClient("/List/GetRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMemberAsync(MockRestClient.USER_KEY, listId, memberId, null);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(memberId);
- }
-
- [TestMethod]
- public async Task GetListMember_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 555L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}}}", memberId);
- var mockRestClient = new MockRestClient("/List/GetRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMemberAsync(MockRestClient.USER_KEY, listId, memberId, CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Id.ShouldBe(memberId);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_status()
- {
- // Arrange
- var listId = 12345L;
- var status = ListMemberStatus.Active;
- var jsonMember1 = string.Format("{{\"id\":\"1\",\"status\":\"{0}\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}", status);
- var jsonMember2 = string.Format("{{\"id\":\"2\",\"status\":\"{0}\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}}", status);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, status: status);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_query()
- {
- // Arrange
- var listId = 12345L;
- var query = "(... this is a bogus query ...)";
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "query", Value = query }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, query: query);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_sortby()
- {
- // Arrange
- var listId = 12345L;
- var sortBy = ListMembersSortBy.EmailAddress;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sort_by", Value = sortBy.GetEnumMemberValue() }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, sortBy: sortBy);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_sortdirection()
- {
- // Arrange
- var listId = 12345L;
- var sortDirection = SortDirection.Ascending;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "direction", Value = sortDirection.GetEnumMemberValue() }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, sortDirection: sortDirection);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_limit()
- {
- // Arrange
- var listId = 12345L;
- var limit = 5;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, limit: limit);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_offset()
- {
- // Arrange
- var listId = 12345L;
- var offset = 25;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, offset: offset);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembers_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- result.ToArray()[0].Id.ShouldBe(1);
- result.ToArray()[1].Id.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembersCount_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembersCount_with_status()
- {
- // Arrange
- var listId = 12345L;
- var status = ListMemberStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId, status: status);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListMembersCount_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/Show/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetMembersCountAsync(MockRestClient.USER_KEY, listId, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task UpdateMember_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UpdateRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateMemberAsync(MockRestClient.USER_KEY, listId, memberId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateMember_with_customfields()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 456L;
- var customFields = new[]
- {
- new KeyValuePair("fullname", "Bob Smith"),
- new KeyValuePair("birthday", new DateTime(1973, 1, 1))
- };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "data[fullname]", Value = "Bob Smith" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "data[birthday]", Value = "1973-01-01 00:00:00" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UpdateRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateMemberAsync(MockRestClient.USER_KEY, listId, memberId, customFields: customFields);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task UpdateMember_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var memberId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = memberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/UpdateRecord/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.UpdateMemberAsync(MockRestClient.USER_KEY, listId, memberId, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetListLogs_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
-
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_logtype()
- {
- // Arrange
- var listId = 12345L;
- var logType = LogType.Subscribe;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", subscribeLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, logType: logType);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(1);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_startdate()
- {
- // Arrange
- var listId = 12345L;
- var start = new DateTime(2015, 1, 1);
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, start: start);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_enddate()
- {
- // Arrange
- var listId = 12345L;
- var end = new DateTime(2015, 12, 31);
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, end: end);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_limit()
- {
- // Arrange
- var listId = 12345L;
- var limit = 5;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, limit: limit);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_offset()
- {
- // Arrange
- var listId = 12345L;
- var offset = 25;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, offset: offset);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_uniques_true()
- {
- // Arrange
- var listId = 12345L;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: true, totals: false);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogs_with_totals_true()
- {
- // Arrange
- var listId = 12345L;
- var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
- var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: true);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_minimal_parameters()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_logtype()
- {
- // Arrange
- var listId = 12345L;
- var logType = LogType.Click;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, logType: logType);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_startdate()
- {
- // Arrange
- var listId = 12345L;
- var start = new DateTime(2015, 1, 1);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, start: start);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_enddate()
- {
- // Arrange
- var listId = 12345L;
- var end = new DateTime(2015, 12, 31);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, end: end);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_clientid()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: false, clientId: CLIENT_ID);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_uniques_true()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, uniques: true, totals: false);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetListLogsCount_with_totals_true()
- {
- // Arrange
- var listId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetLog/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(MockRestClient.API_KEY, mockRestClient.Object);
- var result = await apiClient.Lists.GetLogsCountAsync(MockRestClient.USER_KEY, listId, uniques: false, totals: true);
-
- // Assert
- mockRestClient.Verify();
- result.ShouldBe(2);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/MockRestClient.cs b/CakeMail.RestClient.UnitTests/MockRestClient.cs
deleted file mode 100644
index e00378f..0000000
--- a/CakeMail.RestClient.UnitTests/MockRestClient.cs
+++ /dev/null
@@ -1,75 +0,0 @@
-using Moq;
-using RestSharp;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Threading;
-
-namespace CakeMail.RestClient.UnitTests
-{
- public class MockRestClient : Mock
- {
- public const string API_KEY = "...dummy API key...";
- public const string USER_KEY = "...dummy USER key...";
-
- public MockRestClient(string resource, IEnumerable parameters, RestResponse response, bool includeUserKeyParam = true) : base(MockBehavior.Strict)
- {
- ConfigureMock(resource, parameters, response, includeUserKeyParam);
- }
-
- public MockRestClient(string resource, IEnumerable parameters, ResponseStatus responseStatus, bool includeUserKeyParam = true) : base(MockBehavior.Strict)
- {
- var response = new RestResponse
- {
- ResponseStatus = responseStatus
- };
- ConfigureMock(resource, parameters, response, includeUserKeyParam);
- }
-
- public MockRestClient(string resource, IEnumerable parameters, string jsonResponse, bool includeUserKeyParam = true) : base(MockBehavior.Strict)
- {
- var response = new RestResponse
- {
- StatusCode = HttpStatusCode.OK,
- ContentType = "json",
- Content = jsonResponse
- };
- ConfigureMock(resource, parameters, response, includeUserKeyParam);
- }
-
- private void ConfigureMock(string resource, IEnumerable parameters, RestResponse response, bool includeUserKeyParam = true)
- {
- var standardParameters = new List();
- standardParameters.Add(new Parameter { Type = ParameterType.HttpHeader, Name = "apikey", Value = API_KEY });
- if (includeUserKeyParam) standardParameters.Add(new Parameter { Type = ParameterType.GetOrPost, Name = "user_key", Value = USER_KEY });
-
- var expectedParameters = parameters.Union(standardParameters.ToArray()).ToArray();
-
- Setup(m => m.BaseUrl).Returns(new Uri("http://localhost")).Verifiable();
- Setup(m => m.ExecuteTaskAsync(It.Is(r =>
- r.Method == Method.POST &&
- r.Resource == resource &&
- ValidateParameters(expectedParameters, r.Parameters)
- ), It.IsAny())).ReturnsAsync(response).Verifiable();
- }
-
- private bool ValidateParameters(IEnumerable expectedParameters, IEnumerable actualParameters)
- {
- if (actualParameters.Count() != expectedParameters.Count()) return false;
-
- // We only care about Name, Value and Type
- var expected = expectedParameters.Select(e => new { e.Name, e.Value, e.Type }).ToArray();
- var actual = actualParameters.Select(e => new { e.Name, e.Value, e.Type }).ToArray();
-
- foreach (var expectedParam in expected)
- {
- var actualParam = actual.SingleOrDefault(a => a.Name == expectedParam.Name);
- if (actualParam == null) return false;
- if (!actualParam.Equals(expectedParam)) return false;
- }
-
- return true;
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/Permissions.cs b/CakeMail.RestClient.UnitTests/Permissions.cs
deleted file mode 100644
index e334ddc..0000000
--- a/CakeMail.RestClient.UnitTests/Permissions.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
-using Shouldly;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient.UnitTests
-{
- [TestClass]
- public class PermissionsTests
- {
- private const string API_KEY = "...dummy API key...";
- private const string USER_KEY = "...dummy USER key...";
- private const long CLIENT_ID = 999;
-
- [TestMethod]
- public async Task SetPermissions_with_minimal_parameters()
- {
- // Arrange
- var userId = 1234L;
- var permissions = new string[] { "FirstPermission", "SecondPermission", "ThirdPermission" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[0]", Value = permissions[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[1]", Value = permissions[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[2]", Value = permissions[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Permission/SetPermissions/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, null);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SetPermissions_with_customerid()
- {
- // Arrange
- var userId = 1234L;
- var permissions = new string[] { "FirstPermission", "SecondPermission", "ThirdPermission" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[0]", Value = permissions[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[1]", Value = permissions[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "permission[2]", Value = permissions[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Permission/SetPermissions/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, CLIENT_ID);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetPermissions_with_minimal_parameters()
- {
- // Arrange
- var userId = 1234L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"FirstPermission\",\"SecondPermission\",\"ThirdPermission\"],\"user_id\":\"{0}\"}}}}", userId);
- var mockRestClient = new MockRestClient("/Permission/GetPermissions/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task GetPermissions_with_clientid()
- {
- // Arrange
- var userId = 1234L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"FirstPermission\",\"SecondPermission\",\"ThirdPermission\"],\"user_id\":\"{0}\"}}}}", userId);
- var mockRestClient = new MockRestClient("/Permission/GetPermissions/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/Relays.cs b/CakeMail.RestClient.UnitTests/Relays.cs
deleted file mode 100644
index 56ec479..0000000
--- a/CakeMail.RestClient.UnitTests/Relays.cs
+++ /dev/null
@@ -1,486 +0,0 @@
-using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
-using Shouldly;
-using System;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient.UnitTests
-{
- [TestClass]
- public class RelaysTests
- {
- private const string API_KEY = "...dummy API key...";
- private const string USER_KEY = "...dummy USER key...";
- private const long CLIENT_ID = 999;
- private const long TRACKING_ID = 123;
- private const string RECIPIENT_EMAIL = "bobsmith@fictitiouscompany.com";
- private const string SENDER_EMAIL = "marketing@marketingcompany.com";
- private const string SENDER_NAME = "The Marketing Group";
- private const string HTML_CONTENT = "Hello World";
- private const string TEXT_CONTENT = "Hello Wolrd";
- private const string SUBJECT = "Hello!";
-
- [TestMethod]
- public async Task SendRelay_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendRelay_with_SENDER_NAME()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = SENDER_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, SENDER_NAME);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendRelay_with_encoding()
- {
- // Arrange
- var encoding = MessageEncoding.Utf8;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, encoding: encoding);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendRelay_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendTrackedRelay_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_id", Value = TRACKING_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendTrackedRelay_with_SENDER_NAME()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_id", Value = TRACKING_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = SENDER_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, SENDER_NAME);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendTrackedRelay_with_encoding()
- {
- // Arrange
- var encoding = MessageEncoding.Utf8;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_id", Value = TRACKING_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, encoding: encoding);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task SendTrackedRelay_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_id", Value = TRACKING_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = RECIPIENT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = SUBJECT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = HTML_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = TEXT_CONTENT },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = SENDER_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_opening", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_html", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "track_clicks_in_text", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Relay/Send/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldBeTrue();
- }
-
- [TestMethod]
- public async Task GetRelaySentLogs_with_minimal_parameters()
- {
- // Arrange
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayOpenLogs_with_minimal_parameters()
- {
- // Arrange
- var logType = "open";
- var jsonOpenLog1 = "{\"email\":\"aaa@aaa.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"relay_id\":\"88258598\",\"sent_id\":\"8280816\",\"time\":\"2015-04-06 00:06:17\",\"tracking_id\":\"722823822\",\"user_agent\":\"Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)\"}";
- var jsonOpenLog2 = "{\"email\":\"bbb@bbb.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"relay_id\":\"88249402\",\"sent_id\":\"8271692\",\"time\":\"2015-04-06 00:13:41\",\"tracking_id\":\"1457837189\",\"user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko)\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"open_logs\":[{0},{1}]}}}}", jsonOpenLog1, jsonOpenLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetOpenLogsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayClickLogs_with_minimal_parameters()
- {
- // Arrange
- var logType = "clickthru";
- var jsonClickLog1 = "{\"email\":\"aaa@aaa.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"link_to\":\"http://www.fictitiouscompany.com\",\"relay_id\":\"88750676\",\"sent_id\":\"8356550\",\"time\":\"2015-04-06 00:17:52\",\"tracking_id\":\"1744041192\",\"user_agent\":\"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53\"}";
- var jsonClickLog2 = "{\"email\":\"bbb@bbb.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"link_to\":\"http://www.fictitiouscompany.com\",\"relay_id\":\"86668371\",\"sent_id\":\"8013252\",\"time\":\"2015-04-06 00:47:14\",\"tracking_id\":\"1558835933\",\"user_agent\":\"Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clickthru_logs\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetClickLogsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayBounceLogs_with_minimal_parameters()
- {
- // Arrange
- var logType = "bounce";
- var jsonBounceLog1 = "{\"bounce_type\":\"bounce_sb\",\"email\":\"aaa@aaa.com\",\"relay_id\":\"88935339\",\"sent_id\":\"0\",\"time\":\"2015-04-06 08:08:25\",\"tracking_id\":\"251364339\"}";
- var jsonBounceLog2 = "{\"bounce_type\":\"bounce_fm\",\"email\":\"bbb@bbb.com\",\"relay_id\":\"88240001\",\"sent_id\":\"0\",\"time\":\"2015-04-06 09:27:13\",\"tracking_id\":\"412676746\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"bounce_logs\":[{0},{1}]}}}}", jsonBounceLog1, jsonBounceLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetBounceLogsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_TRACKING_ID()
- {
- // Arrange
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_id", Value = TRACKING_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, TRACKING_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_startdate()
- {
- // Arrange
- var start = new DateTime(2015, 1, 1, 0, 0, 0);
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, start: start);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_enddate()
- {
- // Arrange
- var end = new DateTime(2015, 1, 1, 0, 0, 0);
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, end: end);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_limit()
- {
- // Arrange
- var limit = 5;
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, limit: limit);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_offset()
- {
- // Arrange
- var offset = 25;
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, offset: offset);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetRelayLogs_with_clientid()
- {
- // Arrange
- var logType = "sent";
- var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
- var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "log_type", Value = logType }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
- var mockRestClient = new MockRestClient("/Relay/GetLogs/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/SuppressionLists.cs b/CakeMail.RestClient.UnitTests/SuppressionLists.cs
deleted file mode 100644
index 45f3fa5..0000000
--- a/CakeMail.RestClient.UnitTests/SuppressionLists.cs
+++ /dev/null
@@ -1,790 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
-using Shouldly;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient.UnitTests
-{
- [TestClass]
- public class SuppressionListsTests
- {
- private const string API_KEY = "...dummy API key...";
- private const string USER_KEY = "...dummy USER key...";
- private const long CLIENT_ID = 999;
-
- [TestMethod]
- public async Task AddEmailAddressesToSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[0]", Value = emailAddresses[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[1]", Value = emailAddresses[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[2]", Value = emailAddresses[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddEmailAddressesToSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddEmailAddressesToSuppressionList_with_clientid()
- {
- // Arrange
- var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[0]", Value = emailAddresses[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[1]", Value = emailAddresses[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[2]", Value = emailAddresses[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddDomainsToSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[0]", Value = domains[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[1]", Value = domains[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[2]", Value = domains[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddDomainsToSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task AddDomainsToSuppressionList_with_clientid()
- {
- // Arrange
- var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[0]", Value = domains[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[1]", Value = domains[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[2]", Value = domains[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddLocalPartsToSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var localParts = new[] { "administrator", "manager", "info" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[0]", Value = localParts[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[1]", Value = localParts[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[2]", Value = localParts[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task AddLocalPartsToSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task AddLocalPartsToSuppressionList_with_clientid()
- {
- // Arrange
- var localParts = new[] { "administrator", "manager", "info" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[0]", Value = localParts[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[1]", Value = localParts[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[2]", Value = localParts[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ImportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveEmailAddressesFromSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[0]", Value = emailAddresses[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[1]", Value = emailAddresses[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[2]", Value = emailAddresses[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveEmailAddressesFromSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task RemoveEmailAddressesFromSuppressionList_with_clientid()
- {
- // Arrange
- var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[0]", Value = emailAddresses[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[1]", Value = emailAddresses[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email[2]", Value = emailAddresses[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveDomainsFromSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[0]", Value = domains[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[1]", Value = domains[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[2]", Value = domains[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveDomainsFromSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task RemoveDomainsFromSuppressionList_with_clientid()
- {
- // Arrange
- var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[0]", Value = domains[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[1]", Value = domains[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "domain[2]", Value = domains[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveLocalPartsFromSuppressionList_with_minimal_parameters()
- {
- // Arrange
- var localParts = new[] { "administrator", "manager", "info" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[0]", Value = localParts[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[1]", Value = localParts[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[2]", Value = localParts[2] }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task RemoveLocalPartsFromSuppressionList_with_null_array()
- {
- // Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, null);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(0);
- }
-
- [TestMethod]
- public async Task RemoveLocalPartsFromSuppressionList_with_clientid()
- {
- // Arrange
- var localParts = new[] { "administrator", "manager", "info" };
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[0]", Value = localParts[0] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[1]", Value = localParts[1] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "localpart[2]", Value = localParts[2] },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/DeleteLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts, CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(3);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddresses_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddresses_with_limit()
- {
- // Arrange
- var limit = 5;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, limit: limit);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddresses_with_offset()
- {
- // Arrange
- var offset = 25;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, offset: offset);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddresses_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomains_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomains_with_limit()
- {
- // Arrange
- var limit = 5;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, limit: limit);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomains_with_offset()
- {
- // Arrange
- var offset = 25;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, offset: offset);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomains_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalParts_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalParts_with_limit()
- {
- // Arrange
- var limit = 5;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, limit: limit);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalParts_with_offset()
- {
- // Arrange
- var offset = 25;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, offset: offset);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalParts_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldNotBeNull();
- result.Count().ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddressesCount_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY);
-
- // Assert
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedEmailAddressesCount_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportEmails/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomainsCount_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY);
-
- // Assert
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedDomainsCount_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportDomains/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalPartsCount_with_minimal_parameters()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY);
-
- // Assert
- result.ShouldBe(2);
- }
-
- [TestMethod]
- public async Task GetSuppressedLocalPartsCount_with_clientid()
- {
- // Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
- var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/SuppressionList/ExportLocalparts/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY, clientId: CLIENT_ID);
-
- // Assert
- result.ShouldBe(2);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs b/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs
deleted file mode 100644
index d5bdcd6..0000000
--- a/CakeMail.RestClient.UnitTests/Utilities/CakeMailArrayConverter.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json;
-using System.Dynamic;
-using System.IO;
-using System.Linq;
-
-namespace CakeMail.RestCLient.UnitTests.Utilities
-{
- [TestClass]
- public class CakeMailArrayConverterTests
- {
- [TestMethod]
- public void Successfully_parse_json_containing_array()
- {
- // Arrange
- var json = "{ \"tests\": [ { \"Name\" : \"First\", \"Value\" : \"123\" }, { \"FirstName\" : \"Bob\", \"LastName\" : \"Smith\", \"Phone\" : \"888-555-1212\" } ] }";
-
- var converter = new CakeMailArrayConverter("tests");
- var reader = new JsonTextReader(new StringReader(json));
- reader.Read();
-
- // Act
- var result = (ExpandoObject[])converter.ReadJson(reader, typeof(ExpandoObject[]), null, null);
-
- // Assert
- Assert.AreEqual(2, result.Length);
-
- CollectionAssert.AreEqual(new[] { "Name", "Value" }, result[0].Select(x => x.Key).ToArray());
- CollectionAssert.AreEqual(new[] { "First", "123" }, result[0].Select(x => x.Value).ToArray());
-
- CollectionAssert.AreEqual(new[] { "FirstName", "LastName", "Phone" }, result[1].Select(x => x.Key).ToArray());
- CollectionAssert.AreEqual(new[] { "Bob", "Smith", "888-555-1212" }, result[1].Select(x => x.Value).ToArray());
- }
-
- [TestMethod]
- public void Successfully_parse_json_containing_empty_array()
- {
- // Arrange
- var json = "{ \"tests\": [ ] }";
-
- var converter = new CakeMailArrayConverter("tests");
- var reader = new JsonTextReader(new StringReader(json));
- reader.Read();
-
- // Act
- var result = (ExpandoObject[])converter.ReadJson(reader, typeof(ExpandoObject[]), null, null);
-
- // Assert
- Assert.AreEqual(0, result.Length);
- }
-
- [TestMethod]
- public void Successfully_parse_json_containing_empty_cakemail_array()
- {
- // Arrange
- var json = "{[]}";
-
- var converter = new CakeMailArrayConverter("tests");
- var reader = new JsonTextReader(new StringReader(json));
- reader.Read();
-
- // Act
- var result = (ExpandoObject[])converter.ReadJson(reader, typeof(ExpandoObject[]), null, null);
-
- // Assert
- Assert.AreEqual(0, result.Length);
- }
- }
-}
diff --git a/CakeMail.RestClient.UnitTests/packages.config b/CakeMail.RestClient.UnitTests/packages.config
deleted file mode 100644
index 0c76fd1..0000000
--- a/CakeMail.RestClient.UnitTests/packages.config
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient.sln b/CakeMail.RestClient.sln
deleted file mode 100644
index 0f63c9b..0000000
--- a/CakeMail.RestClient.sln
+++ /dev/null
@@ -1,57 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25123.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16A48337-42CC-443A-B850-775D196B31E0}"
- ProjectSection(SolutionItems) = preProject
- .editorconfig = .editorconfig
- appveyor.yml = appveyor.yml
- CakeMail.RestClient\CakeMail.RestClient.nuspec = CakeMail.RestClient\CakeMail.RestClient.nuspec
- LICENSE = LICENSE
- README.md = README.md
- EndProjectSection
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{F7E19221-12B8-4C6E-B87A-167A1E95EBA1}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient", "CakeMail.RestClient\CakeMail.RestClient.csproj", "{86C4AFC4-0C39-42C5-86A3-68462EA966DF}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6DE42E48-C1B4-41DF-830E-DF7A2E03E0EA}"
- ProjectSection(SolutionItems) = preProject
- .nuget\packages.config = .nuget\packages.config
- EndProjectSection
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient.IntegrationTests", "CakeMail.RestClient.IntegrationTests\CakeMail.RestClient.IntegrationTests.csproj", "{677D93C3-10C8-47AC-B196-60CA28F57A84}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CakeMail.RestClient.UnitTests", "CakeMail.RestClient.UnitTests\CakeMail.RestClient.UnitTests.csproj", "{B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF}.Release|Any CPU.Build.0 = Release|Any CPU
- {677D93C3-10C8-47AC-B196-60CA28F57A84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {677D93C3-10C8-47AC-B196-60CA28F57A84}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {677D93C3-10C8-47AC-B196-60CA28F57A84}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {677D93C3-10C8-47AC-B196-60CA28F57A84}.Release|Any CPU.Build.0 = Release|Any CPU
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF} = {F7E19221-12B8-4C6E-B87A-167A1E95EBA1}
- {677D93C3-10C8-47AC-B196-60CA28F57A84} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}
- {B481EE0F-4D2F-40AB-B2B1-7329AFC330DF} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}
- EndGlobalSection
-EndGlobal
diff --git a/CakeMail.RestClient/CakeMail.RestClient.csproj b/CakeMail.RestClient/CakeMail.RestClient.csproj
deleted file mode 100644
index 9922c67..0000000
--- a/CakeMail.RestClient/CakeMail.RestClient.csproj
+++ /dev/null
@@ -1,143 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {86C4AFC4-0C39-42C5-86A3-68462EA966DF}
- Library
- Properties
- CakeMail.RestClient
- CakeMail.RestClient
- v4.5.2
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- bin\Debug\CakeMail.RestClient.XML
- v4.5.2
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
- bin\Release\CakeMail.RestClient.XML
- v4.5.2
-
-
-
- ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll
- True
-
-
- ..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CakeMail.RestClient/CakeMail.RestClient.nuspec b/CakeMail.RestClient/CakeMail.RestClient.nuspec
deleted file mode 100644
index 2029261..0000000
--- a/CakeMail.RestClient/CakeMail.RestClient.nuspec
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
- $id$
- 5.1.0
- $title$
- $author$
- $author$
- http://jericho.mit-license.org
- https://github.com/Jericho/CakeMail.RestClient
- https://github.com/identicons/jericho.png
- false
- $description$
-
- - Add a missing value to the ListMemberStatus enum
-
- Copyright 2016
- CakeMail API REST
-
-
-
-
-
-
diff --git a/CakeMail.RestClient/CakeMailRestClient.cs b/CakeMail.RestClient/CakeMailRestClient.cs
deleted file mode 100644
index 873a3b8..0000000
--- a/CakeMail.RestClient/CakeMailRestClient.cs
+++ /dev/null
@@ -1,395 +0,0 @@
-using CakeMail.RestClient.Exceptions;
-using CakeMail.RestClient.Resources;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using RestSharp;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.Net;
-using System.Reflection;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace CakeMail.RestClient
-{
- ///
- /// Core class for using the CakeMail Api
- ///
- public class CakeMailRestClient : ICakeMailRestClient
- {
- #region Fields
-
- private static readonly string _version = GetVersion();
- private readonly IRestClient _client;
-
- #endregion
-
- #region Properties
-
- ///
- /// The API key provided by CakeMail
- ///
- public string ApiKey { get; private set; }
-
- ///
- /// The web proxy
- ///
- public IWebProxy Proxy
- {
- get { return _client.Proxy; }
- }
-
- ///
- /// The user agent
- ///
- public string UserAgent
- {
- get { return _client.UserAgent; }
- }
-
- ///
- /// The timeout
- ///
- public int Timeout
- {
- get { return _client.Timeout; }
- }
-
- ///
- /// The URL where all API requests are sent
- ///
- public Uri BaseUrl
- {
- get { return _client.BaseUrl; }
- }
-
- ///
- /// The Campaigns resource
- ///
- public Campaigns Campaigns { get; private set; }
-
- ///
- /// The Clients resource
- ///
- public Clients Clients { get; private set; }
-
- ///
- /// The Countries resource
- ///
- public Countries Countries { get; private set; }
-
- ///
- /// The Permissions resource
- ///
- public Permissions Permissions { get; private set; }
-
- ///
- /// The Lists resource
- ///
- public Lists Lists { get; private set; }
-
- ///
- /// The Timezones resource
- ///
- public Timezones Timezones { get; private set; }
-
- ///
- /// The Mailings resource
- ///
- public Mailings Mailings { get; private set; }
-
- ///
- /// The Relays resource
- ///
- public Relays Relays { get; private set; }
-
- ///
- /// The Segments resource
- ///
- public Segments Segments { get; private set; }
-
- ///
- /// The Users resource
- ///
- public Users Users { get; private set; }
-
- ///
- /// The SuppressionLists resource
- ///
- public SuppressionLists SuppressionLists { get; private set; }
-
- ///
- /// The Templates resource
- ///
- public Templates Templates { get; private set; }
-
- ///
- /// The Triggers resource
- ///
- public Triggers Triggers { get; private set; }
-
- #endregion
-
- #region Constructors and Destructors
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The API Key received from CakeMail
- /// The rest client
- public CakeMailRestClient(string apiKey, IRestClient restClient)
- {
- this.ApiKey = apiKey;
- _client = restClient;
-
- InitializeResources();
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The API Key received from CakeMail
- /// The host where the API is hosted. The default is api.wbsrvc.com
- /// Timeout in milliseconds for connection to web service. The default is 5000.
- /// The web proxy
- public CakeMailRestClient(string apiKey, string host = "api.wbsrvc.com", int timeout = 5000, IWebProxy webProxy = null)
- {
- this.ApiKey = apiKey;
-
- _client = new RestSharp.RestClient("https://" + host)
- {
- Timeout = timeout,
- UserAgent = string.Format("CakeMail .NET REST Client;{0}", _version),
- Proxy = webProxy
- };
-
- InitializeResources();
- }
-
- #endregion
-
- #region Internal Methods
-
- internal Task ExecuteCountRequestAsync(string urlPath, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken))
- {
- return ExecuteRequestAsync(urlPath, parameters, "count", cancellationToken);
- }
-
- internal Task> ExecuteArrayRequestAsync(string urlPath, IEnumerable> parameters, string propertyName = null, CancellationToken cancellationToken = default(CancellationToken))
- {
- return ExecuteRequestAsync>(urlPath, parameters, propertyName, cancellationToken);
- }
-
- internal async Task ExecuteRequestAsync(string urlPath, IEnumerable> parameters, string propertyName = null, CancellationToken cancellationToken = default(CancellationToken))
- {
- // Execute the API call
- var response = await ExecuteRequestAsync(urlPath, parameters, cancellationToken).ConfigureAwait(false);
-
- // Parse the response
- var data = ParseCakeMailResponse(response);
-
- // Check if the response is a well-known object type (JArray, of JValue)
- if (data is JArray) return (data as JArray).ToObject();
- else if (data is JValue) return (data as JValue).ToObject();
-
- // The response contains a JObject which we can return is a specific property was not requested
- if (string.IsNullOrEmpty(propertyName)) return (data as JObject).ToObject();
-
- // The response contains a JObject but we only want a specific property. We must ensure the desired property is present
- var properties = (data as JObject).Properties().Where(p => p.Name.Equals(propertyName));
- if (!properties.Any()) throw new CakeMailException(string.Format("Json does not contain property {0}", propertyName));
-
- // Convert the property to the appropriate object type (JArray, JValue or JObject)
- var property = properties.First();
- if (property.Value is JArray) return (property.Value as JArray).ToObject();
- else if (property.Value is JValue) return (property.Value as JValue).ToObject();
- return (property.Value as JObject).ToObject();
- }
-
- internal async Task ExecuteRequestAsync(string urlPath, IEnumerable> parameters, CancellationToken cancellationToken = default(CancellationToken))
- {
- var request = new RestRequest(urlPath, Method.POST) { RequestFormat = DataFormat.Json };
-
- request.AddHeader("apikey", this.ApiKey);
-
- if (parameters != null)
- {
- foreach (var parameter in parameters)
- {
- request.AddParameter(parameter.Key, parameter.Value);
- }
- }
-
- var response = await _client.ExecuteTaskAsync(request, cancellationToken).ConfigureAwait(false);
- ValidateResponse(request, response);
-
-#if DEBUG
- var debugRequestMsg = string.Format("Request sent to CakeMail: {0}/{1}", _client.BaseUrl.ToString().TrimEnd('/'), urlPath.TrimStart('/'));
- var debugHeadersMsg = string.Format("Request headers: {0}", string.Join("&", request.Parameters.Where(p => p.Type == ParameterType.HttpHeader).Select(p => string.Concat(p.Name, "=", p.Value))));
- var debugParametersMsg = string.Format("Request parameters: {0}", string.Join("&", request.Parameters.Where(p => p.Type != ParameterType.HttpHeader).Select(p => string.Concat(p.Name, "=", p.Value))));
- var debugResponseMsg = string.Format("Response received from CakeMail: {0}", response.Content);
- Debug.WriteLine("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{0}", new string('=', 25), debugRequestMsg, debugHeadersMsg, debugParametersMsg, debugResponseMsg);
-#endif
-
- return response;
- }
-
- #endregion
-
- #region Private Methods
-
- private void InitializeResources()
- {
- this.Campaigns = new Campaigns(this);
- this.Clients = new Clients(this);
- this.Countries = new Countries(this);
- this.Permissions = new Permissions(this);
- this.Lists = new Lists(this);
- this.Timezones = new Timezones(this);
- this.Mailings = new Mailings(this);
- this.Relays = new Relays(this);
- this.Segments = new Segments(this);
- this.Users = new Users(this);
- this.SuppressionLists = new SuppressionLists(this);
- this.Templates = new Templates(this);
- this.Triggers = new Triggers(this);
- }
-
- private static string GetVersion()
- {
- try
- {
- // The following may throw 'System.Security.Permissions.FileIOPermission' under some circumpstances
- //var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
-
- // Here's an alternative suggested by Phil Haack: http://haacked.com/archive/2010/11/04/assembly-location-and-medium-trust.aspx
- var assemblyVersion = new AssemblyName(typeof(CakeMailRestClient).Assembly.FullName).Version;
- var version = string.Format("{0}.{1}.{2}", assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Build);
-
- return version;
- }
- catch
- {
- return "0.0.0";
- }
- }
-
- private JToken ParseCakeMailResponse(IRestResponse response)
- {
- try
- {
- /* A typical response from the CakeMail API looks like this:
- * {
- * "status" : "success",
- * "data" : { ... data for the API call ... }
- * }
- *
- * In case of an error, the response looks like this:
- * {
- * "status" : "failed",
- * "data" : "An error has occured"
- * }
- */
- var cakeResponse = JObject.Parse(response.Content);
- var status = cakeResponse["status"].ToString();
- var data = cakeResponse["data"];
- var postData = cakeResponse["post"];
-
- if (status != "success")
- {
- if (postData != null) throw new CakeMailPostException(data.ToString(), postData.ToString());
- else throw new CakeMailException(data.ToString());
- }
-
- return data;
- }
- catch (JsonReaderException ex)
- {
- throw new CakeMailException(string.Format("Unable to decode response from CakeMail as JSON: {0}", response.Content), ex);
- }
- }
-
- private void ValidateResponse(IRestRequest request, IRestResponse response)
- {
- var responseUri = GetResponseUri(request, response);
- if (response.ResponseStatus == ResponseStatus.Error)
- {
- var errorMessage = string.Format("Error received while making request: {0}", response.ErrorMessage);
- throw new HttpException(errorMessage, response.StatusCode, responseUri);
- }
- else if (response.ResponseStatus == ResponseStatus.TimedOut)
- {
- throw new HttpException("Request timed out", response.StatusCode, responseUri, response.ErrorException);
- }
-
- var statusCode = (int)response.StatusCode;
- if (statusCode == 200)
- {
- Validate200Response(request, response);
- }
- else if (statusCode >= 400 && statusCode < 500)
- {
- Validate400Response(request, response);
- }
- else if (statusCode >= 500 && statusCode < 600)
- {
- Validate500Response(request, response);
- }
- else if (!string.IsNullOrEmpty(response.ErrorMessage))
- {
- var errorMessage = string.Format("Received an error message from {0} (status code: {1}) (error message: {2})", request.Resource, (int)response.StatusCode, response.ErrorMessage);
- throw new HttpException(errorMessage, response.StatusCode, responseUri);
- }
- else
- {
- var errorMessage = string.Format("Received an unexpected response from {0} (status code: {1})", request.Resource, (int)response.StatusCode);
- throw new HttpException(errorMessage, response.StatusCode, responseUri);
- }
- }
-
- private void Validate200Response(IRestRequest request, IRestResponse response)
- {
- var responseUri = GetResponseUri(request, response);
- if (string.IsNullOrEmpty(response.Content))
- {
- var missingBodyMessage = string.Format("Received a 200 response from {0} but there was no message body.", request.Resource);
- throw new HttpException(missingBodyMessage, response.StatusCode, responseUri);
- }
- else if (response.ContentType == null || !response.ContentType.Contains("json"))
- {
- var unsupportedContentTypeMessage = string.Format("Received a 200 response from {0} but the content type is not JSON: {1}", request.Resource, response.ContentType ?? "NULL");
- throw new CakeMailException(unsupportedContentTypeMessage);
- }
- }
-
- private void Validate400Response(IRestRequest request, IRestResponse response)
- {
- var responseUri = GetResponseUri(request, response);
- if (string.IsNullOrEmpty(response.Content))
- {
- var missingBodyMessage = string.Format("Received a {0} error from {1} with no body", response.StatusCode, request.Resource);
- throw new HttpException(missingBodyMessage, response.StatusCode, responseUri);
- }
-
- var errorMessage = string.Format("Received a {0} error from {1} with the following content: {2}", response.StatusCode, request.Resource, response.Content);
- throw new HttpException(errorMessage, response.StatusCode, responseUri);
- }
-
- private void Validate500Response(IRestRequest request, IRestResponse response)
- {
- var responseUri = GetResponseUri(request, response);
- var errorMessage = string.Format("Received a server ({0}) error from {1}", (int)response.StatusCode, request.Resource);
- throw new HttpException(errorMessage, response.StatusCode, responseUri);
- }
-
- private Uri GetResponseUri(IRestRequest request, IRestResponse response)
- {
- var responseUri = response.ResponseUri ?? new Uri(string.Format("{0}/{1}", _client.BaseUrl.ToString().TrimEnd('/'), request.Resource.TrimStart('/')));
- return responseUri;
- }
-
- #endregion
- }
-}
diff --git a/CakeMail.RestClient/Exceptions/CakeMailException.cs b/CakeMail.RestClient/Exceptions/CakeMailException.cs
deleted file mode 100644
index 07f78f5..0000000
--- a/CakeMail.RestClient/Exceptions/CakeMailException.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System;
-using System.Runtime.Serialization;
-using System.Security.Permissions;
-
-namespace CakeMail.RestClient.Exceptions
-{
- ///
- /// This class represents a generic CakeMail error. All other exceptions thrown by
- /// the CakeMail API subclass this exception
- ///
- [Serializable]
- public class CakeMailException : ApplicationException
- {
- ///
- /// Initializes a new instance of the class.
- ///
- /// A message that describes the error.
- public CakeMailException(string message)
- : base(message)
- {
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// A message that describes the error.
- /// The inner exception.
- public CakeMailException(string message, Exception innerException)
- : base(message, innerException)
- {
- }
-
- ///
- /// Deserialization constructor
- ///
- /// Constructor should be protected for unsealed classes, private for sealed classes.
- /// (The Serializer invokes this constructor through reflection, so it can be private)
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- protected CakeMailException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- }
-
- ///
- /// Populates a SerializationInfo with the data needed to serialize the target object.
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- base.GetObjectData(info, context);
- }
- }
-}
diff --git a/CakeMail.RestClient/Properties/AssemblyInfo.cs b/CakeMail.RestClient/Properties/AssemblyInfo.cs
deleted file mode 100644
index fbc4195..0000000
--- a/CakeMail.RestClient/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using System.Reflection;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("CakeMail.RestClient")]
-[assembly: AssemblyDescription("CakeMail.RestClient is a .NET wrapper for the CakeMail API")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Jeremie Desautels")]
-[assembly: AssemblyProduct("CakeMail.RestClient")]
-[assembly: AssemblyCopyright("Copyright Jeremie Desautels © 2016")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
-[assembly: AssemblyInformationalVersion("1.0.0.0")]
diff --git a/CakeMail.RestClient/Utilities/ExtensionMethods.cs b/CakeMail.RestClient/Utilities/ExtensionMethods.cs
deleted file mode 100644
index 2338b8c..0000000
--- a/CakeMail.RestClient/Utilities/ExtensionMethods.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using System;
-using System.Linq;
-using System.Runtime.Serialization;
-
-namespace CakeMail.RestClient.Utilities
-{
- ///
- /// Various extension methods
- ///
- public static class ExtensionMethods
- {
- ///
- /// Convert a DateTime into a string that can be accepted by the CakeMail API.
- ///
- ///
- ///
- public static string ToCakeMailString(this DateTime value)
- {
- if (value == DateTime.MinValue) return Constants.EMPTY_CAKEMAIL_DATE;
- return value.ToString(Constants.CAKEMAIL_DATE_FORMAT);
- }
-
- ///
- /// Get the value of the 'EnumMember' attribute associated with the value.
- ///
- /// The enum value
- /// The string value of the 'EnumMember' attribute associated with the value
- public static string GetEnumMemberValue(this Enum value)
- {
- var type = value.GetType();
- var name = Enum.GetName(type, value);
- var attrib = type.GetField(name)
- .GetCustomAttributes(false)
- .OfType()
- .SingleOrDefault();
- return attrib == null ? "" : attrib.Value;
- }
-
- ///
- /// Get the enum value associated with the 'EnumMember' attribute string value
- ///
- /// The Enum type
- /// The value of the 'EnumMember' attribute
- /// The Enum value associated with the 'EnumMember' attribute
- public static T GetValueFromEnumMember(this string enumMember) where T : struct, IConvertible
- {
- var type = typeof(T);
- if (!type.IsEnum) throw new NotSupportedException("Type given must be an Enum");
- foreach (var field in type.GetFields())
- {
- var attribute = Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) as EnumMemberAttribute;
- if (attribute != null)
- {
- if (attribute.Value == enumMember) return (T)field.GetValue(null);
- }
- else
- {
- if (field.Name == enumMember) return (T)field.GetValue(null);
- }
- }
- throw new ArgumentException(string.Format("{0} does not have an element with value {1}", typeof(T), enumMember));
- }
- }
-}
diff --git a/CakeMail.RestClient/packages.config b/CakeMail.RestClient/packages.config
deleted file mode 100644
index ef6a3d4..0000000
--- a/CakeMail.RestClient/packages.config
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/Code Coverage Report.bat b/Code Coverage Report.bat
deleted file mode 100644
index 25405b4..0000000
--- a/Code Coverage Report.bat
+++ /dev/null
@@ -1,26 +0,0 @@
-rmdir /s /q "TestResults"
-rmdir /s /q "CodeCoverageData"
-rmdir /s /q "CodeCoverageReport"
-
-mkdir "CodeCoverageData"
-mkdir "CodeCoverageReport"
-
-
-packages\OpenCover.4.6.519\tools\OpenCover.Console.exe^
- -register:user^
- -target:"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"^
- -targetargs:"""CakeMail.RestClient.UnitTests\bin\Debug\CakeMail.RestClient.UnitTests.dll"""^
- -filter:"+[CakeMail.RestClient]* -[CakeMail.RestClient]CakeMail.RestClient.Models.* -[CakeMail.RestClient]CakeMail.RestClient.Properties.*"^
- -excludebyattribute:*.ExcludeFromCodeCoverage*^
- -hideskipped:All^
- -output:.\CodecoverageData\CakeMail.RestClient_coverage.xml
-
-
-packages\ReportGenerator.2.4.4.0\tools\ReportGenerator.exe^
- -reports:.\CodeCoverageData\*.xml^
- -targetdir:.\CodeCoverageReport^
- -reporttypes:Html^
- -filters:-CakeMail.RestClient.UnitTests*
-
-
-start CodeCoverageReport\index.htm
\ No newline at end of file
diff --git a/GitReleaseManager.yaml b/GitReleaseManager.yaml
new file mode 100644
index 0000000..8ffa102
--- /dev/null
+++ b/GitReleaseManager.yaml
@@ -0,0 +1,27 @@
+create:
+ include-footer: true
+ footer-heading: Where to get it
+ footer-content: You can download this release from [nuget.org](https://www.nuget.org/packages/Picton/{milestone})
+ footer-includes-milestone: true
+ milestone-replace-text: '{milestone}'
+export:
+ include-created-date-in-title: true
+ created-date-string-format: MMMM dd, yyyy
+ perform-regex-removal: true
+ regex-text: '### Where to get it(\r\n)*You can .*\)'
+ multiline-regex: true
+issue-labels-include:
+- Breaking change
+- Bug
+- New Feature
+- Improvement
+- Documentation
+issue-labels-exclude:
+- Question
+- Duplicate
+- Invalid
+- Wontfix
+issue-labels-alias:
+ - name: Documentation
+ header: Documentation
+ plural: Documentation
diff --git a/GitVersion.yml b/GitVersion.yml
new file mode 100644
index 0000000..c778400
--- /dev/null
+++ b/GitVersion.yml
@@ -0,0 +1,12 @@
+mode: ContinuousDelivery
+branches:
+ develop:
+ regex: dev(elop)?(ment)?$
+ mode: ContinuousDeployment
+ tag: alpha
+ hotfix:
+ regex: hotfix(es)?[/-]
+ mode: ContinuousDeployment
+ tag: beta
+ignore:
+ sha: []
diff --git a/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.xproj b/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.xproj
new file mode 100644
index 0000000..33f1366
--- /dev/null
+++ b/Source/CakeMail.RestClient.IntegrationTests/CakeMail.RestClient.IntegrationTests.xproj
@@ -0,0 +1,19 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ b19e7e01-717a-4d0e-b3bc-6d6f26a457a8
+ CakeMail.RestClient.IntegrationTests
+ .\obj
+ .\bin\
+ v4.5.2
+
+
+ 2.0
+
+
+
\ No newline at end of file
diff --git a/CakeMail.RestClient.IntegrationTests/Campaigns.cs b/Source/CakeMail.RestClient.IntegrationTests/Campaigns.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Campaigns.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Campaigns.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Clients.cs b/Source/CakeMail.RestClient.IntegrationTests/Clients.cs
similarity index 89%
rename from CakeMail.RestClient.IntegrationTests/Clients.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Clients.cs
index a5c5250..d41aa54 100644
--- a/CakeMail.RestClient.IntegrationTests/Clients.cs
+++ b/Source/CakeMail.RestClient.IntegrationTests/Clients.cs
@@ -15,7 +15,11 @@ public static async Task ExecuteAllMethods(CakeMailRestClient api, string userKe
Console.WriteLine(new string('-', 25));
Console.WriteLine("Executing CLIENTS methods...");
- var confirmation = await api.Clients.CreateAsync(clientId, "_Integration Testing", "123 1st Street", "Suite 123", "Atlanta", "GA", "12345", "us", "www.company.com", "1-888-myphone", "1-888myfax", "admin3@integrationtesting.com", "Admin", "Integration Testing", "Super Administrator", "1-888-AdminPhone", "1-888-AdminMobile", "en_US", UTC_TIMEZONE_ID, "adminpassword", true).ConfigureAwait(false);
+ var clientsCount = await api.Clients.GetCountAsync(userKey, null, null, clientId).ConfigureAwait(false);
+ Console.WriteLine("Clients count = {0}", clientsCount);
+
+ var adminEmail = string.Format("admin{0:00}+{1:0000}@integrationtesting.com", clientsCount, (new Random()).Next(9999));
+ var confirmation = await api.Clients.CreateAsync(clientId, "_Integration Testing", "123 1st Street", "Suite 123", "Atlanta", "GA", "12345", "us", "www.company.com", "1-888-myphone", "1-888myfax", adminEmail, "Admin", "Integration Testing", "Super Administrator", "1-888-AdminPhone", "1-888-AdminMobile", "en_US", UTC_TIMEZONE_ID, "adminpassword", true).ConfigureAwait(false);
Console.WriteLine("New client created. Confirmation code: {0}", confirmation);
var unconfirmedClient = await api.Clients.GetAsync(userKey, confirmation).ConfigureAwait(false);
@@ -27,9 +31,6 @@ public static async Task ExecuteAllMethods(CakeMailRestClient api, string userKe
var clients = await api.Clients.GetListAsync(userKey, null, null, ClientsSortBy.CompanyName, SortDirection.Ascending, null, null, clientId).ConfigureAwait(false);
Console.WriteLine("All clients retrieved. Count = {0}", clients.Count());
- var clientsCount = await api.Clients.GetCountAsync(userKey, null, null, clientId).ConfigureAwait(false);
- Console.WriteLine("Clients count = {0}", clientsCount);
-
var updated = await api.Clients.UpdateAsync(userKey, registrationInfo.ClientId, name: "Fictitious Company").ConfigureAwait(false);
Console.WriteLine("Client updated: {0}", updated ? "success" : "failed");
diff --git a/CakeMail.RestClient.IntegrationTests/Countries.cs b/Source/CakeMail.RestClient.IntegrationTests/Countries.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Countries.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Countries.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Lists.cs b/Source/CakeMail.RestClient.IntegrationTests/Lists.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Lists.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Lists.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Mailings.cs b/Source/CakeMail.RestClient.IntegrationTests/Mailings.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Mailings.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Mailings.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Permissions.cs b/Source/CakeMail.RestClient.IntegrationTests/Permissions.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Permissions.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Permissions.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Program.cs b/Source/CakeMail.RestClient.IntegrationTests/Program.cs
similarity index 66%
rename from CakeMail.RestClient.IntegrationTests/Program.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Program.cs
index f302af4..821142b 100644
--- a/CakeMail.RestClient.IntegrationTests/Program.cs
+++ b/Source/CakeMail.RestClient.IntegrationTests/Program.cs
@@ -1,13 +1,10 @@
using System;
-using System.Configuration;
namespace CakeMail.RestClient.IntegrationTests
{
- class Program
+ public class Program
{
-#pragma warning disable RECS0154 // Parameter is never used
- static void Main(string[] args)
-#pragma warning restore RECS0154 // Parameter is never used
+ public static void Main()
{
Console.WriteLine("{0} Executing all CakeMail API methods ... {0}", new string('=', 10));
@@ -35,14 +32,23 @@ static void Main(string[] args)
}
}
- static void ExecuteAllMethods()
+ private static void ExecuteAllMethods()
{
- var apiKey = ConfigurationManager.AppSettings["ApiKey"];
- var userName = ConfigurationManager.AppSettings["UserName"];
- var password = ConfigurationManager.AppSettings["Password"];
- var overrideClientId = ConfigurationManager.AppSettings["OverrideClientId"];
+ // -----------------------------------------------------------------------------
- var api = new CakeMailRestClient(apiKey);
+ // Do you want to proxy requests through Fiddler (useful for debugging)?
+ var useFiddler = false;
+
+ // -----------------------------------------------------------------------------
+
+
+ var proxy = useFiddler ? new WebProxy("http://localhost:8888") : null;
+ var apiKey = Environment.GetEnvironmentVariable("CAKEMAIL_APIKEY");
+ var userName = Environment.GetEnvironmentVariable("CAKEMAIL_USERNAME");
+ var password = Environment.GetEnvironmentVariable("CAKEMAIL_PASSWORD");
+ var overrideClientId = Environment.GetEnvironmentVariable("CAKEMAIL_OVERRIDECLIENTID");
+
+ var api = new CakeMailRestClient(apiKey, proxy);
var loginInfo = api.Users.LoginAsync(userName, password).Result;
var clientId = string.IsNullOrEmpty(overrideClientId) ? loginInfo.ClientId : long.Parse(overrideClientId);
var userKey = loginInfo.UserKey;
diff --git a/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs
similarity index 71%
rename from CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs
index 71b2445..c67efce 100644
--- a/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs
+++ b/Source/CakeMail.RestClient.IntegrationTests/Properties/AssemblyInfo.cs
@@ -21,15 +21,3 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6e64ef85-e9b2-4a6c-863f-f049c90a45cf")]
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/CakeMail.RestClient.IntegrationTests/Relays.cs b/Source/CakeMail.RestClient.IntegrationTests/Relays.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Relays.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Relays.cs
diff --git a/CakeMail.RestClient.IntegrationTests/SuppressionLists.cs b/Source/CakeMail.RestClient.IntegrationTests/SuppressionLists.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/SuppressionLists.cs
rename to Source/CakeMail.RestClient.IntegrationTests/SuppressionLists.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Templates.cs b/Source/CakeMail.RestClient.IntegrationTests/Templates.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Templates.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Templates.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Timezones.cs b/Source/CakeMail.RestClient.IntegrationTests/Timezones.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Timezones.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Timezones.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Triggers.cs b/Source/CakeMail.RestClient.IntegrationTests/Triggers.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Triggers.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Triggers.cs
diff --git a/CakeMail.RestClient.IntegrationTests/Users.cs b/Source/CakeMail.RestClient.IntegrationTests/Users.cs
similarity index 100%
rename from CakeMail.RestClient.IntegrationTests/Users.cs
rename to Source/CakeMail.RestClient.IntegrationTests/Users.cs
diff --git a/Source/CakeMail.RestClient.IntegrationTests/WebProxy.cs b/Source/CakeMail.RestClient.IntegrationTests/WebProxy.cs
new file mode 100644
index 0000000..c0dfe8b
--- /dev/null
+++ b/Source/CakeMail.RestClient.IntegrationTests/WebProxy.cs
@@ -0,0 +1,211 @@
+using System.Collections;
+using System.Globalization;
+using System.Net.NetworkInformation;
+using System.Text.RegularExpressions;
+using System;
+using System.Net;
+
+namespace CakeMail.RestClient.IntegrationTests
+{
+ ///
+ /// Microsoft is working on a nuget package for .NETSTANDARD 1.7
+ /// but in the mean time we have to implement our own concrete
+ /// IWebProxy class. The following was taken from
+ /// https://github.com/dotnet/corefx/blob/71de1aac5cf3e5dc87714ae0cc829e1fa98f7c5d/src/System.Net.WebProxy/src/System/Net/WebProxy.cs
+ ///
+ public class WebProxy : IWebProxy
+ {
+ private ArrayList _bypassList;
+ private Regex[] _regExBypassList;
+
+ public WebProxy() : this((Uri)null, false, null, null) { }
+
+ public WebProxy(Uri Address) : this(Address, false, null, null) { }
+
+ public WebProxy(Uri Address, bool BypassOnLocal) : this(Address, BypassOnLocal, null, null) { }
+
+ public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList) : this(Address, BypassOnLocal, BypassList, null) { }
+
+ public WebProxy(Uri Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)
+ {
+ this.Address = Address;
+ this.Credentials = Credentials;
+ this.BypassProxyOnLocal = BypassOnLocal;
+ if (BypassList != null)
+ {
+ _bypassList = new ArrayList(BypassList);
+ UpdateRegExList(true);
+ }
+ }
+
+ public WebProxy(string Host, int Port)
+ : this(new Uri("http://" + Host + ":" + Port.ToString(CultureInfo.InvariantCulture)), false, null, null)
+ {
+ }
+
+ public WebProxy(string Address)
+ : this(CreateProxyUri(Address), false, null, null)
+ {
+ }
+
+ public WebProxy(string Address, bool BypassOnLocal)
+ : this(CreateProxyUri(Address), BypassOnLocal, null, null)
+ {
+ }
+
+ public WebProxy(string Address, bool BypassOnLocal, string[] BypassList)
+ : this(CreateProxyUri(Address), BypassOnLocal, BypassList, null)
+ {
+ }
+
+ public WebProxy(string Address, bool BypassOnLocal, string[] BypassList, ICredentials Credentials)
+ : this(CreateProxyUri(Address), BypassOnLocal, BypassList, Credentials)
+ {
+ }
+
+ public Uri Address { get; set; }
+
+ public bool BypassProxyOnLocal { get; set; }
+
+ public string[] BypassList
+ {
+ get { return _bypassList != null ? (string[])_bypassList.ToArray(typeof(string)) : Array.Empty(); }
+ set
+ {
+ _bypassList = new ArrayList(value);
+ UpdateRegExList(true);
+ }
+ }
+
+ public ArrayList BypassArrayList => _bypassList ?? (_bypassList = new ArrayList());
+
+ public ICredentials Credentials { get; set; }
+
+ public bool UseDefaultCredentials
+ {
+ get { return Credentials == CredentialCache.DefaultCredentials; }
+ set { Credentials = value ? CredentialCache.DefaultCredentials : null; }
+ }
+
+ public Uri GetProxy(Uri destination)
+ {
+ if (destination == null)
+ {
+ throw new ArgumentNullException(nameof(destination));
+ }
+
+ return IsBypassed(destination) ? destination : Address;
+ }
+
+ private static Uri CreateProxyUri(string address) =>
+ address == null ? null :
+ address.IndexOf("://", StringComparison.Ordinal) == -1 ? new Uri("http://" + address) :
+ new Uri(address);
+
+ private void UpdateRegExList(bool canThrow)
+ {
+ Regex[] regExBypassList = null;
+ ArrayList bypassList = _bypassList;
+ try
+ {
+ if (bypassList != null && bypassList.Count > 0)
+ {
+ regExBypassList = new Regex[bypassList.Count];
+ for (int i = 0; i < bypassList.Count; i++)
+ {
+ regExBypassList[i] = new Regex((string)bypassList[i], RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
+ }
+ }
+ }
+ catch
+ {
+ if (!canThrow)
+ {
+ _regExBypassList = null;
+ return;
+ }
+ throw;
+ }
+
+ // Update field here, as it could throw earlier in the loop
+ _regExBypassList = regExBypassList;
+ }
+
+ private bool IsMatchInBypassList(Uri input)
+ {
+ UpdateRegExList(false);
+
+ if (_regExBypassList != null)
+ {
+ string matchUriString = input.IsDefaultPort ?
+ input.Scheme + "://" + input.Host :
+ input.Scheme + "://" + input.Host + ":" + input.Port.ToString();
+
+ foreach (Regex r in _regExBypassList)
+ {
+ if (r.IsMatch(matchUriString))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private bool IsLocal(Uri host)
+ {
+ string hostString = host.Host;
+
+ IPAddress hostAddress;
+ if (IPAddress.TryParse(hostString, out hostAddress))
+ {
+ return IPAddress.IsLoopback(hostAddress) || IsAddressLocal(hostAddress);
+ }
+
+ // No dot? Local.
+ int dot = hostString.IndexOf('.');
+ if (dot == -1)
+ {
+ return true;
+ }
+
+ // If it matches the primary domain, it's local. (Whether or not the hostname matches.)
+ string local = "." + IPGlobalProperties.GetIPGlobalProperties().DomainName;
+ return
+ local.Length == (hostString.Length - dot) &&
+ string.Compare(local, 0, hostString, dot, local.Length, StringComparison.OrdinalIgnoreCase) == 0;
+ }
+
+ private static bool IsAddressLocal(IPAddress ipAddress)
+ {
+ // Perf note: The .NET Framework caches this and then uses network change notifications to track
+ // whether the set should be recomputed. We could consider doing the same if this is observed as
+ // a bottleneck, but that tracking has its own costs.
+ IPAddress[] localAddresses = Dns.GetHostEntryAsync(Dns.GetHostName()).GetAwaiter().GetResult().AddressList; // TODO: Use synchronous GetHostEntry when available
+ for (int i = 0; i < localAddresses.Length; i++)
+ {
+ if (ipAddress.Equals(localAddresses[i]))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public bool IsBypassed(Uri host)
+ {
+ if (host == null)
+ {
+ throw new ArgumentNullException(nameof(host));
+ }
+
+ return
+ Address == null ||
+ host.IsLoopback ||
+ (BypassProxyOnLocal && IsLocal(host)) ||
+ IsMatchInBypassList(host);
+ }
+ }
+}
diff --git a/Source/CakeMail.RestClient.IntegrationTests/project.json b/Source/CakeMail.RestClient.IntegrationTests/project.json
new file mode 100644
index 0000000..22958b5
--- /dev/null
+++ b/Source/CakeMail.RestClient.IntegrationTests/project.json
@@ -0,0 +1,20 @@
+{
+ "buildOptions": {
+ "emitEntryPoint": true
+ },
+ "dependencies": {
+ "CakeMail.RestClient": { "target": "project" },
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.1.0"
+ },
+ "System.Collections.NonGeneric": "4.3.0",
+ "System.Net.NetworkInformation": "4.3.0"
+ },
+ "frameworks": {
+ "netcoreapp1.0": {
+ "imports": "dnxcore50"
+ }
+ },
+ "version": "1.0.0-*"
+}
diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj
new file mode 100644
index 0000000..a8c6a69
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/CakeMail.RestClient.UnitTests.xproj
@@ -0,0 +1,22 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ 964d6bc3-6daa-4878-bbae-839ae9942baf
+ CakeMail.RestClient.UnitTests
+ .\obj
+ .\bin\
+ v4.5.2
+
+
+ 2.0
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs
new file mode 100644
index 0000000..25928ae
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/CakeMailRestClientTests.cs
@@ -0,0 +1,279 @@
+using CakeMail.RestClient.Exceptions;
+using Moq;
+using Newtonsoft.Json;
+using RichardSzalay.MockHttp;
+using Shouldly;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Reflection.Metadata;
+using System.Text;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CakeMail.RestClient.UnitTests
+{
+ public class CakeMailRestClientTests
+ {
+ private const string API_KEY = "...dummy API key...";
+ private const string USER_KEY = "...dummy USER key...";
+ private const long CLIENT_ID = 999;
+
+ [Fact]
+ public void Version_is_not_empty()
+ {
+ // Arrange
+ var client = new CakeMailRestClient(API_KEY);
+
+ // Act
+ var result = client.Version;
+
+ // Assert
+ result.ShouldNotBeNullOrEmpty();
+ }
+
+ [Fact]
+ public void RestClient_constructor_with_ApiKey()
+ {
+ // Arrange
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY);
+ var userAgent = client.UserAgent;
+ var baseUrl = client.BaseUrl;
+
+ // Assert
+ userAgent.Split(new[] { '/' })[0].ShouldBe("CakeMail .NET REST Client");
+ userAgent.Split(new[] { '+' })[1].Trim(new[] { '(', ')' }).ShouldBe("https://github.com/Jericho/CakeMail.RestClient");
+ baseUrl.ShouldBe(new Uri("https://api.wbsrvc.com"));
+ }
+
+ [Fact]
+ public void RestClient_constructor_with_IWebProxy()
+ {
+ // Arrange
+ var mockProxy = new Mock(MockBehavior.Strict);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, mockProxy.Object);
+ var baseUrl = client.BaseUrl;
+
+ // Assert
+ baseUrl.ShouldBe(new Uri("https://api.wbsrvc.com"));
+ }
+
+ [Fact]
+ public void RestClient_constructor_with_HttpClient()
+ {
+ // Arrange
+ var mockHost = "my.apiserver.com";
+
+ var mockHttp = new MockHttpMessageHandler();
+ var httpClient = new HttpClient(mockHttp);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, mockHost, httpClient);
+ var baseUrl = client.BaseUrl;
+
+ // Assert
+ mockHttp.VerifyNoOutstandingExpectation();
+ mockHttp.VerifyNoOutstandingRequest();
+ baseUrl.ShouldBe(new Uri($"https://{mockHost}"));
+ }
+
+ [Fact]
+ public void RestClient_dispose()
+ {
+ var client = new CakeMailRestClient(API_KEY);
+ client.Dispose();
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsestatus_is_error()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond(HttpStatusCode.BadRequest);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsestatus_is_timeout()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond(HttpStatusCode.RequestTimeout);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_request_is_successful_but_response_content_is_empty()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond(HttpStatusCode.OK, new StringContent(""));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsescode_is_between_400_and_499_and_content_is_empty()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)450);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsescode_is_between_400_and_499_and_content_is_not_empty()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)450, new StringContent("dummy content", Encoding.UTF8, "application/json"));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsescode_is_between_500_and_599()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)550);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsescode_is_greater_than_599()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond((HttpStatusCode)600);
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_responsecode_is_greater_than_599_and_custom_errormessage()
+ {
+ // Arrange
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp
+ .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList"))
+ .Respond((HttpStatusCode)600, new StringContent("This is a bogus error message", Encoding.UTF8, "application/json"));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Countries.GetListAsync().ConfigureAwait(false);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_cakemail_api_returns_failure_with_post_details()
+ {
+ // Arrange
+ var campaignId = 123L;
+ var jsonResponse = string.Format("{{\"status\":\"failed\",\"data\":\"There is no campaign with the id {0} and client id {1}!\",\"post\":{{\"user_key\":\"{2}\",\"campaign_id\":\"{0}\",\"client_id\":\"{1}\"}}}}", campaignId, CLIENT_ID, USER_KEY);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp
+ .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete"))
+ .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json"));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_reponse_contains_invalid_json()
+ {
+ // Arrange
+ var campaignId = 123L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"{This content is not valid json (missing closing brackets)\"";
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp
+ .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete"))
+ .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json"));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID);
+ });
+ }
+
+ [Fact]
+ public async Task RestClient_Throws_exception_when_reponse_does_not_contain_expected_property()
+ {
+ // Arrange
+ var categoryId = 123;
+ var labels = new Dictionary
+ {
+ { "en_US", "My Category" }
+ };
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"we_expected_a_property_named_id_but_instead_we_received_this_bogus_property\":\"{0}\"}}}}", categoryId);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp
+ .Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory"))
+ .Respond((HttpStatusCode)200, new StringContent(jsonResponse, Encoding.UTF8, "application/json"));
+
+ // Act
+ var client = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ await Should.ThrowAsync(async () =>
+ {
+ var result = await client.Templates.CreateCategoryAsync(USER_KEY, labels);
+ });
+ }
+ }
+}
diff --git a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs
similarity index 85%
rename from CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs
rename to Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs
index de5d1c3..fc2e795 100644
--- a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailException.cs
@@ -1,14 +1,13 @@
using CakeMail.RestClient.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System;
using Shouldly;
+using System;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests.Utilities
+namespace CakeMail.RestClient.UnitTests.Exceptions
{
- [TestClass]
public class CakeMailExceptionTests
{
- [TestMethod]
+ [Fact]
public void CakeMailException_Constructor_with_message()
{
// Arrange
@@ -22,7 +21,7 @@ public void CakeMailException_Constructor_with_message()
exception.InnerException.ShouldBeNull();
}
- [TestMethod]
+ [Fact]
public void CakeMailException_Constructor_with_message_and_innerexception()
{
// Arrange
diff --git a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs
similarity index 88%
rename from CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs
rename to Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs
index f78da92..3ab74a4 100644
--- a/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/CakeMailPostException.cs
@@ -1,14 +1,13 @@
using CakeMail.RestClient.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests.Utilities
+namespace CakeMail.RestClient.UnitTests.Exceptions
{
- [TestClass]
public class CakeMailPostExceptionTests
{
- [TestMethod]
+ [Fact]
public void CakeMailPostException_Constructor_with_message_and_postdata()
{
// Arrange
@@ -24,7 +23,7 @@ public void CakeMailPostException_Constructor_with_message_and_postdata()
exception.InnerException.ShouldBeNull();
}
- [TestMethod]
+ [Fact]
public void CakeMailPostException_Constructor_with_message_and_postdata_and_innerexception()
{
// Arrange
diff --git a/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs
similarity index 89%
rename from CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs
rename to Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs
index f7b9fe5..05c5120 100644
--- a/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Exceptions/HttpException.cs
@@ -1,15 +1,14 @@
using CakeMail.RestClient.Exceptions;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
using System.Net;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests.Utilities
+namespace CakeMail.RestClient.UnitTests.Exceptions
{
- [TestClass]
public class HttpExceptionTests
{
- [TestMethod]
+ [Fact]
public void HttpException_Constructor_with_message_and_status_and_uri()
{
// Arrange
@@ -27,7 +26,7 @@ public void HttpException_Constructor_with_message_and_status_and_uri()
exception.InnerException.ShouldBeNull();
}
- [TestMethod]
+ [Fact]
public void HttpException_Constructor_with_message_and_status_and_uri_and_innerexception()
{
// Arrange
diff --git a/CakeMail.RestClient.UnitTests/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient.UnitTests/Properties/AssemblyInfo.cs
similarity index 100%
rename from CakeMail.RestClient.UnitTests/Properties/AssemblyInfo.cs
rename to Source/CakeMail.RestClient.UnitTests/Properties/AssemblyInfo.cs
diff --git a/CakeMail.RestClient.UnitTests/Campaigns.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs
similarity index 63%
rename from CakeMail.RestClient.UnitTests/Campaigns.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs
index ec2553a..39d18dd 100644
--- a/CakeMail.RestClient.UnitTests/Campaigns.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Campaigns.cs
@@ -1,118 +1,105 @@
using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
+using Shouldly;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
-using Shouldly;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class CampaignsTests
{
private const string API_KEY = "...dummy API key...";
private const string USER_KEY = "...dummy USER key...";
private const long CLIENT_ID = 999;
- [TestMethod]
+ [Fact]
public async Task CreateCampaign_with_minimal_parameters()
{
// Arrange
var campaignName = "My Campaign";
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = campaignName }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", campaignId);
- var mockRestClient = new MockRestClient("/Campaign/Create/", parameters, jsonResponse);
+ var jsonResponse = $"{{\"status\":\"success\",\"data\":\"{campaignId}\"}}";
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Campaigns.CreateAsync(USER_KEY, campaignName);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Campaigns.CreateAsync(USER_KEY, campaignName).ConfigureAwait(false);
// Assert
- result.ShouldNotBeNull();
+ result.ShouldBe(campaignId);
}
- [TestMethod]
+ [Fact]
public async Task CreateCampaign_with_clientid()
{
// Arrange
var campaignName = "My Campaign";
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = campaignName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", campaignId);
- var mockRestClient = new MockRestClient("/Campaign/Create/", parameters, jsonResponse);
+ var jsonResponse = $"{{\"status\":\"success\",\"data\":\"{campaignId}\"}}";
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
- var result = await apiClient.Campaigns.CreateAsync(USER_KEY, campaignName, CLIENT_ID);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Campaigns.CreateAsync(USER_KEY, campaignName).ConfigureAwait(false);
// Assert
- result.ShouldNotBeNull();
+ result.ShouldBe(campaignId);
}
- [TestMethod]
+ [Fact]
public async Task DeleteCampaign_with_minimal_parameters()
{
// Arrange
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Campaign/Delete/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteCampaign_with_clientid()
{
// Arrange
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Campaign/Delete/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/Delete")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.DeleteAsync(USER_KEY, campaignId, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_minimal_parameters()
{
// Arrange
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"client_id\":\"{1}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-22 04:38:46\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}}}", campaignId, CLIENT_ID);
- var mockRestClient = new MockRestClient("/Campaign/GetInfo/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetAsync(USER_KEY, campaignId, null);
// Assert
@@ -120,21 +107,18 @@ public async Task GetCampaign_with_minimal_parameters()
result.Id.ShouldBe(campaignId);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_clientid()
{
// Arrange
var campaignId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"client_id\":\"{1}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-22 04:38:46\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}}}", campaignId, CLIENT_ID);
- var mockRestClient = new MockRestClient("/Campaign/GetInfo/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetAsync(USER_KEY, campaignId, CLIENT_ID);
// Assert
@@ -142,21 +126,19 @@ public async Task GetCampaign_with_clientid()
result.Id.ShouldBe(campaignId);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaigns_with_minimal_parameters()
{
// Arrange
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY);
// Assert
@@ -166,23 +148,20 @@ public async Task GetCampaigns_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_status()
{
// Arrange
var status = CampaignStatus.Ongoing;
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, status: status);
// Assert
@@ -192,23 +171,20 @@ public async Task GetCampaign_with_status()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_name()
{
// Arrange
var name = "Dummy campaign";
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, name: name);
// Assert
@@ -218,23 +194,20 @@ public async Task GetCampaign_with_name()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_sortby()
{
// Arrange
var sortBy = CampaignsSortBy.Name;
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sort_by", Value = sortBy.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, sortBy: sortBy);
// Assert
@@ -244,23 +217,20 @@ public async Task GetCampaign_with_sortby()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_sortdirection()
{
// Arrange
var sortDirection = SortDirection.Ascending;
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "direction", Value = sortDirection.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, sortDirection: sortDirection);
// Assert
@@ -270,23 +240,20 @@ public async Task GetCampaign_with_sortdirection()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_limit()
{
// Arrange
var limit = 50;
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, limit: limit);
// Assert
@@ -296,23 +263,20 @@ public async Task GetCampaign_with_limit()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaign_with_offset()
{
// Arrange
var offset = 25;
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, offset: offset);
// Assert
@@ -322,22 +286,19 @@ public async Task GetCampaign_with_offset()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaigns_with_clientid()
{
// Arrange
var jsonCampaign1 = string.Format("{{\"id\":\"123\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
var jsonCampaign2 = string.Format("{{\"id\":\"456\",\"client_id\":\"{0}\",\"name\":\"Dummy campaign\",\"status\":\"ongoing\",\"created_on\":\"2015-03-23 13:29:45\",\"closed_on\":\"0000-00-00 00:00:00\",\"sent\":\"0\",\"open_pct\":\"0.0000\",\"click_pct\":\"0.0000\",\"bounce_pct\":\"0.0000\",\"unsubscribes_pct\":\"0.0000\",\"fbl_pct\":\"0.0000\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"campaigns\":[{0},{1}]}}}}", jsonCampaign1, jsonCampaign2);
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetListAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -347,126 +308,108 @@ public async Task GetCampaigns_with_clientid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaignCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaignCount_with_status()
{
// Arrange
var status = CampaignStatus.Ongoing;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetCountAsync(USER_KEY, status: status);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaignCount_with_name()
{
// Arrange
var name = "Dummy campaign";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetCountAsync(USER_KEY, name: name);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetCampaignCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Campaign/GetList/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateCampaign_with_minimal_parameters()
{
// Arrange
var campaignId = 123L;
var name = "New name";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Campaign/SetInfo/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.UpdateAsync(USER_KEY, campaignId, name);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateCampaign_with_clientid()
{
// Arrange
var campaignId = 123L;
var name = "New name";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Campaign/SetInfo/", parameters, jsonResponse);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Campaign/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Campaigns.UpdateAsync(USER_KEY, campaignId, name, CLIENT_ID);
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Clients.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs
similarity index 57%
rename from CakeMail.RestClient.UnitTests/Clients.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs
index 95e97dc..8f6e3a8 100644
--- a/CakeMail.RestClient.UnitTests/Clients.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Clients.cs
@@ -1,15 +1,14 @@
using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class ClientsTests
{
private const string API_KEY = "...dummy API key...";
@@ -45,163 +44,86 @@ public class ClientsTests
private const string PRIMARY_CONTACT_PASSOWRD = "SuperSecretPassword";
private const string CONFIRMATION_CODE = "... dummy confirmation code ...";
- [TestMethod]
+ [Fact]
public async Task CreateClient_with_minimal_parameters()
{
// Arrange
string name = "Fictitious Inc";
string confirmationCode = "... dummy confirmation code ...";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "parent_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_same_as_admin", Value = "1" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", confirmationCode);
- var mockRestClient = new MockRestClient("/Client/Create/", parameters, jsonResponse, false);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.CreateAsync(CLIENT_ID, name);
// Assert
result.ShouldBe(confirmationCode);
}
- [TestMethod]
+ [Fact]
public async Task CreateClient_with_minimal_parameters_and_contactsameasadmin_false()
{
// Arrange
string name = "Fictitious Inc";
string confirmationCode = "... dummy confirmation code ...";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "parent_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_same_as_admin", Value = "0" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", confirmationCode);
- var mockRestClient = new MockRestClient("/Client/Create/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.CreateAsync(CLIENT_ID, name, primaryContactSameAsAdmin: false);
// Assert
result.ShouldBe(confirmationCode);
}
- [TestMethod]
+ [Fact]
public async Task CreateClient_with_all_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "parent_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = NAME },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "address1", Value = ADDRESS1 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "address2", Value = ADDRESS2 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "city", Value = CITY },
- new Parameter { Type = ParameterType.GetOrPost, Name = "province_id", Value = PROVINCE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "postal_code", Value = POSTALCODE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "country_id", Value = COUNTRY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "website", Value = WEBSITE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "phone", Value = PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "fax", Value = FAX },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_email", Value = ADMIN_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_first_name", Value = ADMIN_FIRST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_last_name", Value = ADMIN_LAST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_password", Value = ADMIN_PASSWORD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_password_confirmation", Value = ADMIN_PASSWORD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_title", Value = ADMIN_TITLE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_office_phone", Value = ADMIN_OFFICE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_mobile_phone", Value = ADMIN_MOBILE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_language", Value = ADMIN_LANGUAGE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_timezone_id", Value = ADMIN_TIMEZONE_ID },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_same_as_admin", Value = "0" },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_email", Value = PRIMARY_CONTACT_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_first_name", Value = PRIMARY_CONTACT_FIRST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_last_name", Value = PRIMARE_CONTACT_LAST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_password", Value = PRIMARY_CONTACT_PASSOWRD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_password_confirmation", Value = PRIMARY_CONTACT_PASSOWRD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_title", Value = PRIMARY_CONTACT_TITLE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_office_phone", Value = PRIMARY_CONTACT_OFFICE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_mobile_phone", Value = PRIMARY_CONTACT_MOBILE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_language", Value = PRIMARY_CONTACT_LANGUAGE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_timezone_id", Value = PRIMARY_CONTACT_TIMEZONE_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", CONFIRMATION_CODE);
- var mockRestClient = new MockRestClient("/Client/Create/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.CreateAsync(CLIENT_ID, NAME, ADDRESS1, ADDRESS2, CITY, PROVINCE, POSTALCODE, COUNTRY_ID, WEBSITE, PHONE, FAX, ADMIN_EMAIL, ADMIN_FIRST_NAME, ADMIN_LAST_NAME, ADMIN_TITLE, ADMIN_OFFICE_PHONE, ADMIN_MOBILE_PHONE, ADMIN_LANGUAGE, ADMIN_TIMEZONE_ID, ADMIN_PASSWORD, false, PRIMARY_CONTACT_EMAIL, PRIMARY_CONTACT_FIRST_NAME, PRIMARE_CONTACT_LAST_NAME, PRIMARY_CONTACT_TITLE, PRIMARY_CONTACT_OFFICE_PHONE, PRIMARY_CONTACT_MOBILE_PHONE, PRIMARY_CONTACT_LANGUAGE, PRIMARY_CONTACT_TIMEZONE_ID, PRIMARY_CONTACT_PASSOWRD);
// Assert
result.ShouldBe(CONFIRMATION_CODE);
}
- [TestMethod]
+ [Fact]
public async Task CreateClient_admin_same_as_contact()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "parent_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = NAME },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "address1", Value = ADDRESS1 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "address2", Value = ADDRESS2 },
- new Parameter { Type = ParameterType.GetOrPost, Name = "city", Value = CITY },
- new Parameter { Type = ParameterType.GetOrPost, Name = "province_id", Value = PROVINCE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "postal_code", Value = POSTALCODE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "country_id", Value = COUNTRY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "website", Value = WEBSITE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "phone", Value = PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "fax", Value = FAX },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_email", Value = ADMIN_EMAIL },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_first_name", Value = ADMIN_FIRST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_last_name", Value = ADMIN_LAST_NAME },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_password", Value = ADMIN_PASSWORD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_password_confirmation", Value = ADMIN_PASSWORD },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_title", Value = ADMIN_TITLE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_office_phone", Value = ADMIN_OFFICE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_mobile_phone", Value = ADMIN_MOBILE_PHONE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_language", Value = ADMIN_LANGUAGE },
- new Parameter { Type = ParameterType.GetOrPost, Name = "admin_timezone_id", Value = ADMIN_TIMEZONE_ID },
-
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_same_as_admin", Value = "1" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", CONFIRMATION_CODE);
- var mockRestClient = new MockRestClient("/Client/Create/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.CreateAsync(CLIENT_ID, NAME, ADDRESS1, ADDRESS2, CITY, PROVINCE, POSTALCODE, COUNTRY_ID, WEBSITE, PHONE, FAX, ADMIN_EMAIL, ADMIN_FIRST_NAME, ADMIN_LAST_NAME, ADMIN_TITLE, ADMIN_OFFICE_PHONE, ADMIN_MOBILE_PHONE, ADMIN_LANGUAGE, ADMIN_TIMEZONE_ID, ADMIN_PASSWORD, true, PRIMARY_CONTACT_EMAIL, PRIMARY_CONTACT_FIRST_NAME, PRIMARE_CONTACT_LAST_NAME, PRIMARY_CONTACT_TITLE, PRIMARY_CONTACT_OFFICE_PHONE, PRIMARY_CONTACT_MOBILE_PHONE, PRIMARY_CONTACT_LANGUAGE, PRIMARY_CONTACT_TIMEZONE_ID, PRIMARY_CONTACT_PASSOWRD);
// Assert
result.ShouldBe(CONFIRMATION_CODE);
}
- [TestMethod]
+ [Fact]
public async Task ConfirmClient()
{
// Arrange
var confirmationId = "... dummy confirmation id ...";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "confirmation", Value = confirmationId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"client_id\":\"{0}\",\"client_key\":\"...dummy client key...\",\"admin_id\":\"123\",\"admin_key\":\"...dummy admin key...\",\"contact_id\":\"456\",\"contact_key\":\"...dummy contact key...\"}}}}", CLIENT_ID);
- var mockRestClient = new MockRestClient("/Client/Activate/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/Activate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.ConfirmAsync(confirmationId);
// Assert
@@ -209,20 +131,17 @@ public async Task ConfirmClient()
result.ClientId.ShouldBe(CLIENT_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetClient_by_confirmationcode()
{
// Arrange
var confirmationCode = "...dummy confirmation code...";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "confirmation", Value = confirmationCode }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"city\":\"Mock City\",\"company_name\":\"Fictitious Inc\",\"confirmation\":\"{0}\",\"address1\":\"123 1st Avenue\",\"address2\":\"Suite 1000\",\"country_id\":\"us\",\"currency\":\"USD\",\"fax\":\"222-222-2222\",\"parent_id\":\"1\",\"phone\":\"111-111-1111\",\"postal_code\":\"12345\",\"province_id\":\"FL\",\"status\":\"pending\",\"contact_same_as_admin\":\"1\",\"admin_email\":\"bobsmith@fictitiouscompany.com\",\"admin_password\":\"7cad97840d5b8e175870b1245a5fe9d8\",\"admin_first_name\":\"Bob\",\"admin_last_name\":\"Smith\",\"admin_language\":\"en_US\",\"admin_mobile_phone\":\"444-444-4444\",\"admin_office_phone\":\"333-333-3333\",\"admin_timezone_id\":\"542\",\"admin_title\":\"Administrator\",\"contact_email\":null,\"contact_password\":null,\"contact_first_name\":null,\"contact_last_name\":null,\"contact_language\":\"en_US\",\"contact_mobile_phone\":null,\"contact_office_phone\":null,\"contact_timezone_id\":\"152\",\"contact_title\":null,\"time\":\"2015-03-25 17:07:03\",\"last_confirmation\":\"2015-03-25 17:07:03\",\"expire\":\"2015-04-24 17:07:03\",\"website\":\"www.fictitiouscompany.com\",\"industry_id\":\"0\"}}}}", confirmationCode);
- var mockRestClient = new MockRestClient("/Client/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetAsync(USER_KEY, confirmationCode);
// Assert
@@ -230,19 +149,16 @@ public async Task GetClient_by_confirmationcode()
result.ConfirmationCode.ShouldBe(confirmationCode);
}
- [TestMethod]
+ [Fact]
public async Task GetClient_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lineage\":\"1-{0}\",\"address1\":\"123 1st Avenue\",\"address2\":\"Suite 1000\",\"config_id\":\"55\",\"auth_domain\":\"md02.com\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"parent_bounce_domain\":\"bounce.fictitiouscompany.com\",\"city\":\"Mock City\",\"company_name\":\"Fictitious Inc\",\"contact_id\":\"0\",\"country\":\"United States\",\"country_id\":\"us\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"dkim_domain\":\"md02.com\",\"doptin_ip\":\"192.168.77.1\",\"fax\":null,\"force_unsub\":\"false\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"parent_forward_domain\":\"http://forward.fictitiouscompany.com/\",\"forward_ip\":\"192.168.77.2\",\"id\":\"{0}\",\"key\":\"...dummy key...\",\"last_activity\":\"2015-03-25 14:20:54\",\"mailing_limit\":\"900000\",\"manager_id\":\"0\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"parent_md_domain\":\"http://link.fictitiouscompany.com/\",\"month_limit\":\"900000\",\"default_contact_limit\":\"0\",\"contact_limit\":\"0\",\"mta_id\":\"1\",\"parent_id\":\"1\",\"phone\":null,\"plan_min_vol\":null,\"plan_period\":null,\"plan_price\":null,\"plan_start_date\":null,\"plan_type\":null,\"postal_code\":null,\"pricing_plan\":\"courrielleur-demo\",\"province\":\"Florida\",\"province_id\":\"FL\",\"registered_date\":\"2015-03-01 00:00:00\",\"reseller\":\"false\",\"status\":\"active\",\"lineage_status\":\"active\",\"default_trial\":\"false\",\"default_reseller\":\"false\",\"billing_bundle_id\":\"0\",\"billing_package_id\":\"0\",\"billing_discount_percent\":\"0.000\",\"callback\":null,\"trigger_info\":\"false\",\"website\":null,\"industry_id\":null}}}}", CLIENT_ID);
- var mockRestClient = new MockRestClient("/Client/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetAsync(USER_KEY, CLIENT_ID);
// Assert
@@ -250,22 +166,18 @@ public async Task GetClient_with_minimal_parameters()
result.Id.ShouldBe(CLIENT_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetClient_with_startdate()
{
// Arrange
var startDate = new DateTime(2014, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
var endDate = (DateTime?)null;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_date", Value = startDate.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lineage\":\"1-{0}\",\"address1\":\"123 1st Avenue\",\"address2\":\"Suite 1000\",\"config_id\":\"55\",\"auth_domain\":\"md02.com\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"parent_bounce_domain\":\"bounce.fictitiouscompany.com\",\"city\":\"Mock City\",\"company_name\":\"Fictitious Inc\",\"contact_id\":\"0\",\"country\":\"United States\",\"country_id\":\"us\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"dkim_domain\":\"md02.com\",\"doptin_ip\":\"192.168.77.1\",\"fax\":null,\"force_unsub\":\"false\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"parent_forward_domain\":\"http://forward.fictitiouscompany.com/\",\"forward_ip\":\"192.168.77.2\",\"id\":\"{0}\",\"key\":\"...dummy key...\",\"last_activity\":\"2015-03-25 14:20:54\",\"mailing_limit\":\"900000\",\"manager_id\":\"0\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"parent_md_domain\":\"http://link.fictitiouscompany.com/\",\"month_limit\":\"900000\",\"default_contact_limit\":\"0\",\"contact_limit\":\"0\",\"mta_id\":\"1\",\"parent_id\":\"1\",\"phone\":null,\"plan_min_vol\":null,\"plan_period\":null,\"plan_price\":null,\"plan_start_date\":null,\"plan_type\":null,\"postal_code\":null,\"pricing_plan\":\"courrielleur-demo\",\"province\":\"Florida\",\"province_id\":\"FL\",\"registered_date\":\"2015-03-01 00:00:00\",\"reseller\":\"false\",\"status\":\"active\",\"lineage_status\":\"active\",\"default_trial\":\"false\",\"default_reseller\":\"false\",\"billing_bundle_id\":\"0\",\"billing_package_id\":\"0\",\"billing_discount_percent\":\"0.000\",\"callback\":null,\"trigger_info\":\"false\",\"website\":null,\"industry_id\":null}}}}", CLIENT_ID);
- var mockRestClient = new MockRestClient("/Client/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetAsync(USER_KEY, CLIENT_ID, startDate, endDate);
// Assert
@@ -273,22 +185,18 @@ public async Task GetClient_with_startdate()
result.Id.ShouldBe(CLIENT_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetClient_with_enddate()
{
// Arrange
var startDate = (DateTime?)null;
var endDate = new DateTime(2014, 12, 31, 23, 59, 59, 999, DateTimeKind.Utc);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_date", Value = endDate.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lineage\":\"1-{0}\",\"address1\":\"123 1st Avenue\",\"address2\":\"Suite 1000\",\"config_id\":\"55\",\"auth_domain\":\"md02.com\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"parent_bounce_domain\":\"bounce.fictitiouscompany.com\",\"city\":\"Mock City\",\"company_name\":\"Fictitious Inc\",\"contact_id\":\"0\",\"country\":\"United States\",\"country_id\":\"us\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"dkim_domain\":\"md02.com\",\"doptin_ip\":\"192.168.77.1\",\"fax\":null,\"force_unsub\":\"false\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"parent_forward_domain\":\"http://forward.fictitiouscompany.com/\",\"forward_ip\":\"192.168.77.2\",\"id\":\"{0}\",\"key\":\"...dummy key...\",\"last_activity\":\"2015-03-25 14:20:54\",\"mailing_limit\":\"900000\",\"manager_id\":\"0\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"parent_md_domain\":\"http://link.fictitiouscompany.com/\",\"month_limit\":\"900000\",\"default_contact_limit\":\"0\",\"contact_limit\":\"0\",\"mta_id\":\"1\",\"parent_id\":\"1\",\"phone\":null,\"plan_min_vol\":null,\"plan_period\":null,\"plan_price\":null,\"plan_start_date\":null,\"plan_type\":null,\"postal_code\":null,\"pricing_plan\":\"courrielleur-demo\",\"province\":\"Florida\",\"province_id\":\"FL\",\"registered_date\":\"2015-03-01 00:00:00\",\"reseller\":\"false\",\"status\":\"active\",\"lineage_status\":\"active\",\"default_trial\":\"false\",\"default_reseller\":\"false\",\"billing_bundle_id\":\"0\",\"billing_package_id\":\"0\",\"billing_discount_percent\":\"0.000\",\"callback\":null,\"trigger_info\":\"false\",\"website\":null,\"industry_id\":null}}}}", CLIENT_ID);
- var mockRestClient = new MockRestClient("/Client/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetAsync(USER_KEY, CLIENT_ID, startDate, endDate);
// Assert
@@ -296,23 +204,19 @@ public async Task GetClient_with_enddate()
result.Id.ShouldBe(CLIENT_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_status()
{
// Arrange
var status = ClientStatus.Active;
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, status: status);
// Assert
@@ -320,23 +224,19 @@ public async Task GetClients_with_status()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_name()
{
// Arrange
var name = "Dummy Client";
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = name }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, name: name);
// Assert
@@ -344,23 +244,19 @@ public async Task GetClients_with_name()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_sortBy()
{
// Arrange
var sortBy = ClientsSortBy.CompanyName;
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sort_by", Value = sortBy.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, sortBy: sortBy);
// Assert
@@ -368,23 +264,19 @@ public async Task GetClients_with_sortBy()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_sortdirection()
{
// Arrange
var sortDirection = SortDirection.Ascending;
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "direction", Value = sortDirection.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, sortDirection: sortDirection);
// Assert
@@ -392,23 +284,19 @@ public async Task GetClients_with_sortdirection()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_limit()
{
// Arrange
var limit = 11;
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, limit: limit);
// Assert
@@ -416,23 +304,19 @@ public async Task GetClients_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_offset()
{
// Arrange
var offset = 33;
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, offset: offset);
// Assert
@@ -440,22 +324,18 @@ public async Task GetClients_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClients_with_clientid()
{
// Arrange
var jsonClient1 = "{\"company_name\":\"Dummy Client #1\",\"contact_id\":\"123\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"111\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-09 14:34:48\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
var jsonClient2 = "{\"company_name\":\"Dummy Client #2\",\"contact_id\":\"456\",\"currency\":\"USD\",\"default_mailing_limit\":\"25\",\"default_month_limit\":\"250\",\"default_contact_limit\":\"0\",\"id\":\"222\",\"reseller\":\"false\",\"mailing_limit\":\"25\",\"contact_limit\":\"0\",\"manager_id\":\"0\",\"month_limit\":\"250\",\"parent_id\":\"1\",\"registered_date\":\"2015-03-24 22:36:40\",\"status\":\"active\",\"md_domain\":\"http://link.fictitiouscompany.com/\",\"bounce_domain\":\"bounce.fictitiouscompany.com\",\"forward_domain\":\"http://forward.fictitiouscompany.com/\",\"lineage\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonClient1, jsonClient2);
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetListAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -463,21 +343,17 @@ public async Task GetClients_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClientsCount_with_status()
{
// Arrange
var status = ClientStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetCountAsync(USER_KEY, status: status);
// Assert
@@ -485,21 +361,17 @@ public async Task GetClientsCount_with_status()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClientsCount_with_name()
{
// Arrange
var name = "Dummy Client";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetCountAsync(USER_KEY, name: name);
// Assert
@@ -507,20 +379,16 @@ public async Task GetClientsCount_with_name()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetClientsCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Client/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -528,690 +396,558 @@ public async Task GetClientsCount_with_clientid()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_name()
{
// Arrange
var name = "Fictitious Inc";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "company_name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, name: name);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_status()
{
// Arrange
var status = ClientStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, status: status);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_parentid()
{
// Arrange
var parentId = 1L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "parent_id", Value = parentId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, parentId: parentId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_address1()
{
// Arrange
var address1 = "123 1st Avenue";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "address1", Value = address1 }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, address1: address1);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_address2()
{
// Arrange
var address2 = "Suite 1000";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "address2", Value = address2 }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, address2: address2);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_city()
{
// Arrange
var city = "Mock City";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "city", Value = city }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, city: city);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_provinceid()
{
// Arrange
var provinceId = "FL";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "province_id", Value = provinceId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, provinceId: provinceId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_postalcode()
{
// Arrange
var postalCode = "12345";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "postal_code", Value = postalCode }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, postalCode: postalCode);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_countryid()
{
// Arrange
var countryId = "us";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "country_id", Value = countryId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, countryId: countryId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_website()
{
// Arrange
var website = "www.fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "website", Value = website }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, website: website);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_phone()
{
// Arrange
var phone = "111-111-1111";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "phone", Value = phone }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, phone: phone);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_fax()
{
// Arrange
var fax = "222-222-2222";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "fax", Value = fax }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, fax: fax);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_autdomain()
{
// Arrange
var authDomain = "md02.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "auth_domain", Value = authDomain }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, authDomain: authDomain);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_bouncedomain()
{
// Arrange
var bounceDomain = "bounce.fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "bounce_domain", Value = bounceDomain }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, bounceDomain: bounceDomain);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_dkimdomain()
{
// Arrange
var dkimDomain = "md02.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "dkim_domain", Value = dkimDomain }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, dkimDomain: dkimDomain);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_doptinip()
{
// Arrange
var doptinIp = "192.168.77.1";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "doptin_ip", Value = doptinIp }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, doptinIp: doptinIp);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_forwarddomain()
{
// Arrange
var forwardDomain = "http://forward.fictitiouscompany.com/";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "forward_domain", Value = forwardDomain }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, forwardDomain: forwardDomain);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_forwardip()
{
// Arrange
var forwardIp = "192.168.77.2";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "forward_ip", Value = forwardIp }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, forwardIp: forwardIp);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_ippool()
{
// Arrange
var ipPool = "dummy";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "ip_pool", Value = ipPool }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, ipPool: ipPool);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_mddomain()
{
// Arrange
var mdDomain = "http://link.fictitiouscompany.com/";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "md_domain", Value = mdDomain }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, mdDomain: mdDomain);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_isreseller_true()
{
// Arrange
var isReseller = true;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "reseller", Value = "1" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, isReseller: isReseller);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_isreseller_false()
{
// Arrange
var isReseller = false;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "reseller", Value = "0" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, isReseller: isReseller);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_currency()
{
// Arrange
var currency = "USD";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "currency", Value = currency }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, currency: currency);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_plantype()
{
// Arrange
var planType = "dummy plan";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "plan_type", Value = planType }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, planType: planType);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_mailinglimit()
{
// Arrange
var mailingLimit = 10;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_limit", Value = mailingLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, mailingLimit: mailingLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_monthlimit()
{
// Arrange
var monthLimit = 100;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "month_limit", Value = monthLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, monthLimit: monthLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_contactlimit()
{
// Arrange
var contactLimit = 1000;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "contact_limit", Value = contactLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, contactLimit: contactLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_defaultmailinglimit()
{
// Arrange
var defaultMailingLimit = 10;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default_mailing_limit", Value = defaultMailingLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, defaultMailingLimit: defaultMailingLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_defaultmonthlimit()
{
// Arrange
var defaultMonthLimit = 100;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default_month_limit", Value = defaultMonthLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, defaultMonthLimit: defaultMonthLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateClient_defaultcontactlimit()
{
// Arrange
var defaultContactLimit = 1000;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default_contact_limit", Value = defaultContactLimit }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.UpdateAsync(USER_KEY, CLIENT_ID, defaultContactLimit: defaultContactLimit);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task ActivateClient()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = "active" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.ActivateAsync(USER_KEY, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SuspendClient()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = "suspended_by_reseller" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.SuspendAsync(USER_KEY, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteClient()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = "deleted" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Client/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Clients.DeleteAsync(USER_KEY, CLIENT_ID);
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Countries.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs
similarity index 67%
rename from CakeMail.RestClient.UnitTests/Countries.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs
index a971434..b5b69d8 100644
--- a/CakeMail.RestClient.UnitTests/Countries.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Countries.cs
@@ -1,29 +1,27 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class CountriesTests
{
private const string API_KEY = "...dummy API key...";
- [TestMethod]
+ [Fact]
public async Task GetCountries()
{
// Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"countries\":[{\"id\":\"f1\",\"en_name\":\"Fictitious Country 1\",\"fr_name\":\"Pays fictif 1\"},{\"id\":\"f2\",\"en_name\":\"Fictitious Country 2\",\"fr_name\":\"Pays fictif 2\"}]}}";
- var mockRestClient = new MockRestClient("/Country/GetList/", parameters, jsonResponse, false);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Countries.GetListAsync();
// Assert
@@ -33,20 +31,18 @@ public async Task GetCountries()
result.Any(tz => tz.Id == "f2" && tz.EnglishName.Equals("Fictitious Country 2")).ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetProvinces()
{
// Arrange
var countryId = "f1";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "country_id", Value = countryId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"provinces\":[{\"id\":\"p1\",\"en_name\":\"Fictitious Province 1\",\"fr_name\":\"Province fictive 1\"},{\"id\":\"p2\",\"en_name\":\"Fictitious Province 2\",\"fr_name\":\"Province fictive 2\"}]}}";
- var mockRestClient = new MockRestClient("/Country/GetProvinces/", parameters, jsonResponse, false);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Country/GetProvinces")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Countries.GetProvincesAsync(countryId);
// Assert
diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs
new file mode 100644
index 0000000..0d9706f
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Lists.cs
@@ -0,0 +1,1855 @@
+using CakeMail.RestClient.Models;
+using RichardSzalay.MockHttp;
+using Shouldly;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CakeMail.RestClient.UnitTests.Resources
+{
+ public class ListsTests
+ {
+ private const string API_KEY = "...dummy API key...";
+ private const string USER_KEY = "...dummy USER key...";
+ private const long CLIENT_ID = 999;
+
+ [Fact]
+ public async Task CreateList_with_minimal_parameters()
+ {
+ // Arrange
+ var name = "My new list";
+ var defaultSenderName = "Bob Smith";
+ var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress);
+
+ // Assert
+ result.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task CreateList_with_spampolicyaccepted()
+ {
+ // Arrange
+ var name = "My new list";
+ var defaultSenderName = "Bob Smith";
+ var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress, spamPolicyAccepted: true);
+
+ // Assert
+ result.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task CreateList_with_clientid()
+ {
+ // Arrange
+ var name = "My new list";
+ var defaultSenderName = "Bob Smith";
+ var defaultSenderAddress = "bobsmith@fictitiouscompany.com";
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Create")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.CreateAsync(USER_KEY, name, defaultSenderName, defaultSenderAddress, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task DeleteList_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Delete")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteAsync(USER_KEY, listId, null);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteList_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Delete")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteAsync(USER_KEY, listId, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetList_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
+
+ // Actt
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task GetList_with_includestatistics_true()
+ {
+ await GetList_with_includestatistics(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task GetList_with_includestatistics_false()
+ {
+ await GetList_with_includestatistics(false).ConfigureAwait(false);
+ }
+
+ private async Task GetList_with_includestatistics(bool includeStatistics)
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetAsync(USER_KEY, listId, includeStatistics: includeStatistics);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task GetList_with_calculateengagement_true()
+ {
+ await GetList_with_calculateengagement(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task GetList_with_calculateengagement_false()
+ {
+ await GetList_with_calculateengagement(false).ConfigureAwait(false);
+ }
+
+ private async Task GetList_with_calculateengagement(bool calculateEngagement)
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetAsync(USER_KEY, listId, calculateEngagement: calculateEngagement);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task GetList_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"name\":\"Dummy list\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}}}}", listId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetAsync(USER_KEY, listId, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(listId);
+ }
+
+ [Fact]
+ public async Task GetLists_with_status()
+ {
+ // Arrange
+ var status = ListStatus.Active;
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, status: status);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_name()
+ {
+ // Arrange
+ var name = "Dummy List";
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, name: name);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_sortby()
+ {
+ // Arrange
+ var sortBy = ListsSortBy.Name;
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, sortBy: sortBy);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_sortdirection()
+ {
+ // Arrange
+ var sortDirection = SortDirection.Ascending;
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, sortDirection: sortDirection);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_limit()
+ {
+ // Arrange
+ var limit = 5;
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_offset()
+ {
+ // Arrange
+ var offset = 25;
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetLists_with_clientid()
+ {
+ // Arrange
+ var jsonList1 = "{\"id\":\"123\",\"name\":\"Dummy list 1\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonList2 = "{\"id\":\"456\",\"name\":\"Dummy list 2\",\"status\":\"active\",\"policy\":\"declined\",\"language\":\"en_US\",\"created_on\":\"2015-03-26 22:02:45\",\"sender_name\":\"Bob Smith\",\"sender_email\":\"bobsmith@fictitiouscomapny.com\",\"forward_page\":null,\"goto_oi\":null,\"goto_di\":null,\"goto_oo\":null,\"b_ac_limit\":\"3\",\"b_cr_limit\":\"3\",\"b_df_limit\":\"3\",\"b_fm_limit\":\"3\",\"b_hb_limit\":\"0\",\"b_mb_limit\":\"3\",\"b_sb_limit\":\"3\",\"b_tr_limit\":\"3\",\"di_trig_cnt\":\"0\",\"oi_trig_cnt\":\"0\",\"oo_trig_cnt\":\"0\",\"oi_url\":\"http://link.fictitiouscompany.com/oi/1/2b494468e2a377f39751ff716103fd49\",\"subscribe_url\":\"http://link.fictitiouscompany.com/s/1/2b494468e2a377f39751ff716103fd49\",\"oo_url\":\"http://link.fictitiouscompany.com/oo/1/2b494468e2a377f39751ff716103fd49\",\"webhook\":null,\"engagement\":null,\"pending\":\"0\",\"active\":\"0\",\"bounced\":\"0\",\"invalid\":\"0\",\"unsubscribed\":\"0\",\"spam\":\"0\",\"deleted\":\"0\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"lists\":[{0},{1}]}}}}", jsonList1, jsonList2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetListsAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(123);
+ result.ToArray()[1].Id.ShouldBe(456);
+ }
+
+ [Fact]
+ public async Task GetListsCount_with_status()
+ {
+ // Arrange
+ var status = ListStatus.Active;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetCountAsync(USER_KEY, status: status);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListsCount_with_name()
+ {
+ // Arrange
+ var name = "Dummy List";
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetCountAsync(USER_KEY, name: name);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListsCount_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task UpdateList_name()
+ {
+ // Arrange
+ var listId = 12345L;
+ var name = "My list";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, name: name);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_language()
+ {
+ // Arrange
+ var listId = 12345L;
+ var language = "fr-FR";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, language: language);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_spampolicy_accepted()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, spamPolicyAccepted: true);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_spampolicy_declined()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, spamPolicyAccepted: false);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_status()
+ {
+ // Arrange
+ var listId = 12345L;
+ var status = ListStatus.Archived;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, status: status);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_sendername()
+ {
+ // Arrange
+ var listId = 12345L;
+ var senderName = "Bob Smith";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, senderName: senderName);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_senderemail()
+ {
+ // Arrange
+ var listId = 12345L;
+ var senderEmail = "bobsmith@fictitiouscompany.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, senderEmail: senderEmail);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_gotooi()
+ {
+ // Arrange
+ var listId = 12345L;
+ var goto_oi = "???";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_oi: goto_oi);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_gotodi()
+ {
+ // Arrange
+ var listId = 12345L;
+ var goto_di = "???";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_di: goto_di);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_gotooo()
+ {
+ // Arrange
+ var listId = 12345L;
+ var goto_oo = "???";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, goto_oo: goto_oo);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_webhook()
+ {
+ // Arrange
+ var listId = 12345L;
+ var webhook = "???";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, webhook: webhook);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateList_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateAsync(USER_KEY, listId, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task AddListField_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var name = "My field";
+ var fieldType = FieldType.Text;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.AddFieldAsync(USER_KEY, listId, name, fieldType);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task AddListField_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var name = "My field";
+ var fieldType = FieldType.Integer;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.AddFieldAsync(USER_KEY, listId, name, fieldType, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteListField_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var name = "My field";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteFieldAsync(USER_KEY, listId, name);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteListField_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var name = "My field";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/EditStructure")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteFieldAsync(USER_KEY, listId, name, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetListFields_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"id\":\"integer\",\"email\":\"text\",\"registered\":\"timestamp\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task GetListFields_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"id\":\"integer\",\"email\":\"text\",\"registered\":\"timestamp\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task GetListFields_returns_null()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":null}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetFields")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetFieldsAsync(USER_KEY, listId, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task AddTestEmail_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/AddTestEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.AddTestEmailAsync(USER_KEY, listId, email);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task AddTestEmail_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/AddTestEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.AddTestEmailAsync(USER_KEY, listId, email, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteTestEmail_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteTestEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteTestEmailAsync(USER_KEY, listId, email);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteTestEmail_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteTestEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteTestEmailAsync(USER_KEY, listId, email, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetTestEmails_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var testEmail1 = "aaa@aaa.com";
+ var testEmail2 = "bbb@bbb.com";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"testemails\":[\"{0}\",\"{1}\"]}}}}", testEmail1, testEmail2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetTestEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetTestEmailsAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].ShouldBe(testEmail1);
+ result.ToArray()[1].ShouldBe(testEmail2);
+ }
+
+ [Fact]
+ public async Task GetTestEmails_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var testEmail1 = "aaa@aaa.com";
+ var testEmail2 = "bbb@bbb.com";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"testemails\":[\"{0}\",\"{1}\"]}}}}", testEmail1, testEmail2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetTestEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetTestEmailsAsync(USER_KEY, listId, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].ShouldBe(testEmail1);
+ result.ToArray()[1].ShouldBe(testEmail2);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_autoresponders_true()
+ {
+ await Subscribe_with_autoresponders(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_autoresponders_false()
+ {
+ await Subscribe_with_autoresponders(false).ConfigureAwait(false);
+ }
+
+ private async Task Subscribe_with_autoresponders(bool autoResponder)
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "aaa@aaa.com";
+ var subscriberId = 777L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, autoResponders: autoResponder);
+
+ // Assert
+ result.ShouldBe(subscriberId);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_triggers_true()
+ {
+ await Subscribe_with_triggers(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_triggers_false()
+ {
+ await Subscribe_with_triggers(false).ConfigureAwait(false);
+ }
+
+ private async Task Subscribe_with_triggers(bool triggers)
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "aaa@aaa.com";
+ var subscriberId = 777;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, triggers: triggers);
+
+ // Assert
+ result.ShouldBe(subscriberId);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_customfields()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "aaa@aaa.com";
+ var subscriberId = 777;
+ var firstName = "Bob";
+ var lastName = "Smith";
+ var customFields = new[]
+ {
+ new KeyValuePair("firstname", firstName),
+ new KeyValuePair("lastname", lastName),
+ new KeyValuePair("birthday", new DateTime(1973, 1, 1))
+ };
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, customFields: customFields);
+
+ // Assert
+ result.ShouldBe(subscriberId);
+ }
+
+ [Fact]
+ public async Task Subscribe_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "aaa@aaa.com";
+ var subscriberId = 777;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{0}}}", subscriberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.SubscribeAsync(USER_KEY, listId, email, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(subscriberId);
+ }
+
+ [Fact]
+ public async Task Import_with_autoresponders_true()
+ {
+ await Import_with_autoresponders(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task Import_with_autoresponders_false()
+ {
+ await Import_with_autoresponders(false).ConfigureAwait(false);
+ }
+
+ private async Task Import_with_autoresponders(bool autoResponder)
+ {
+ // Arrange
+ var listId = 12345L;
+ var listMembers = new[]
+ {
+ new ListMember { Email = "aaa@aaa.com" },
+ new ListMember { Email = "bbb@bbb.com" }
+ };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, autoResponders: autoResponder);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task Import_with_triggers_true()
+ {
+ await Import_with_triggers(true).ConfigureAwait(false);
+ }
+
+ [Fact]
+ public async Task Import_with_triggers_false()
+ {
+ await Import_with_triggers(false).ConfigureAwait(false);
+ }
+
+ private async Task Import_with_triggers(bool triggers)
+ {
+ // Arrange
+ var listId = 12345L;
+ var listMembers = new[]
+ {
+ new ListMember { Email = "aaa@aaa.com" },
+ new ListMember { Email = "bbb@bbb.com" }
+ };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, triggers: triggers);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task Import_with_customfields()
+ {
+ // Arrange
+ var listId = 12345L;
+ var listMembers = new[]
+ {
+ new ListMember { Email = "aaa@aaa.com", CustomFields = new Dictionary { { "firstname", "Bob" }, { "lastname", "Smith" }, { "age", 41 }, { "birthday", new DateTime(1973, 1, 1) } } },
+ new ListMember { Email = "bbb@bbb.com", CustomFields = new Dictionary { { "firstname", "Jane" }, { "lastname", "Doe" }, { "age", 50 }, { "birthday", new DateTime(1964, 1, 1) } } }
+ };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, autoResponders: true);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task Import_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var listMembers = new[]
+ {
+ new ListMember { Email = "aaa@aaa.com" },
+ new ListMember { Email = "bbb@bbb.com" }
+ };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task Import_zero_subscribers()
+ {
+ // Arrange
+ var listId = 12345L;
+ var listMembers = (ListMember[])null;
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\",\"id\":\"1\"},{\"email\":\"bbb@bbb.com\",\"id\":\"2\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Import")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.ImportAsync(USER_KEY, listId, listMembers);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task Unsubscribe_by_email()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, email, null);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task Unsubscribe_by_email_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var email = "test@test.com";
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, email, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task Unsubscribe_by_memberid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, memberId, null);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task Unsubscribe_by_memberid_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UnsubscribeEmail")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UnsubscribeAsync(USER_KEY, listId, memberId, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteListMember()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteMemberAsync(USER_KEY, listId, memberId, null);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DeleteListMember_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.DeleteMemberAsync(USER_KEY, listId, memberId, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetListMember()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}}}", memberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMemberAsync(USER_KEY, listId, memberId, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(memberId);
+ }
+
+ [Fact]
+ public async Task GetListMember_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 555L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}}}", memberId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMemberAsync(USER_KEY, listId, memberId, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Id.ShouldBe(memberId);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_status()
+ {
+ // Arrange
+ var listId = 12345L;
+ var status = ListMemberStatus.Active;
+ var jsonMember1 = string.Format("{{\"id\":\"1\",\"status\":\"{0}\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}}", status);
+ var jsonMember2 = string.Format("{{\"id\":\"2\",\"status\":\"{0}\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}}", status);
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, status: status);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_query()
+ {
+ // Arrange
+ var listId = 12345L;
+ var query = "(... this is a bogus query ...)";
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, query: query);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_sortby()
+ {
+ // Arrange
+ var listId = 12345L;
+ var sortBy = ListMembersSortBy.EmailAddress;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, sortBy: sortBy);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_sortdirection()
+ {
+ // Arrange
+ var listId = 12345L;
+ var sortDirection = SortDirection.Ascending;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, sortDirection: sortDirection);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_limit()
+ {
+ // Arrange
+ var listId = 12345L;
+ var limit = 5;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_offset()
+ {
+ // Arrange
+ var listId = 12345L;
+ var offset = 25;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembers_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonMember1 = "{\"id\":\"1\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"aaa@aaa.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonMember2 = "{\"id\":\"2\",\"status\":\"active\",\"bounce_type\":\"none\",\"bounce_count\":\"0\",\"email\":\"bb@bb.com\",\"registered\":\"2015-04-01 15:08:22\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"records\":[{0},{1}]}}}}", jsonMember1, jsonMember2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersAsync(USER_KEY, listId, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ result.ToArray()[0].Id.ShouldBe(1);
+ result.ToArray()[1].Id.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembersCount_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembersCount_with_status()
+ {
+ // Arrange
+ var listId = 12345L;
+ var status = ListMemberStatus.Active;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId, status: status);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListMembersCount_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/Show")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetMembersCountAsync(USER_KEY, listId, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task UpdateMember_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 456L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateMember_with_customfields()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 456L;
+ var customFields = new[]
+ {
+ new KeyValuePair("fullname", "Bob Smith"),
+ new KeyValuePair("birthday", new DateTime(1973, 1, 1))
+ };
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId, customFields: customFields);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UpdateMember_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var memberId = 456L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/UpdateRecord")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.UpdateMemberAsync(USER_KEY, listId, memberId, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_logtype()
+ {
+ // Arrange
+ var listId = 12345L;
+ var logType = LogType.Subscribe;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", subscribeLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, logType: logType);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(1);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_startdate()
+ {
+ // Arrange
+ var listId = 12345L;
+ var start = new DateTime(2015, 1, 1);
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, start: start);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_enddate()
+ {
+ // Arrange
+ var listId = 12345L;
+ var end = new DateTime(2015, 12, 31);
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, end: end);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_limit()
+ {
+ // Arrange
+ var listId = 12345L;
+ var limit = 5;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_offset()
+ {
+ // Arrange
+ var listId = 12345L;
+ var offset = 25;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: false, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_uniques_true()
+ {
+ // Arrange
+ var listId = 12345L;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: true, totals: false);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogs_with_totals_true()
+ {
+ // Arrange
+ var listId = 12345L;
+ var subscribeLog = "{\"log_id\":\"70\",\"id\":\"70\",\"record_id\":\"70\",\"email\":\"aaa@aaa.com\",\"action\":\"subscribe\",\"total\":\"1\",\"time\":\"2015-03-06 16:25:40\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"insert\",\"l_registered\":\"2015-03-06 16:25:40\"}";
+ var sentLog = "{\"log_id\":\"249\",\"id\":\"124\",\"record_id\":\"124\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-06 16:27:00\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"mailing_id = 12345\",\"l_registered\":\"2015-03-06 16:25:44\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", subscribeLog, sentLog);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsAsync(USER_KEY, listId, uniques: false, totals: true);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_minimal_parameters()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_logtype()
+ {
+ // Arrange
+ var listId = 12345L;
+ var logType = LogType.Click;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, logType: logType);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_startdate()
+ {
+ // Arrange
+ var listId = 12345L;
+ var start = new DateTime(2015, 1, 1);
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: false, totals: false, start: start);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_enddate()
+ {
+ // Arrange
+ var listId = 12345L;
+ var end = new DateTime(2015, 12, 31);
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: false, totals: false, end: end);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_clientid()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: false, totals: false, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_uniques_true()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: true, totals: false);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetListLogsCount_with_totals_true()
+ {
+ // Arrange
+ var listId = 12345L;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetLog")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Lists.GetLogsCountAsync(USER_KEY, listId, uniques: false, totals: true);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+ }
+}
diff --git a/CakeMail.RestClient.UnitTests/Mailings.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs
similarity index 62%
rename from CakeMail.RestClient.UnitTests/Mailings.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs
index 27ba7bd..149da31 100644
--- a/CakeMail.RestClient.UnitTests/Mailings.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Mailings.cs
@@ -1,67 +1,57 @@
using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class MailingsTests
{
private const string API_KEY = "...dummy API key...";
private const string USER_KEY = "...dummy USER key...";
private const long CLIENT_ID = 999;
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_minimal_parameters()
{
// Arrange
var name = "My new mailing";
var mailingId = 123L;
-
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_without_type()
{
// Arrange
var name = "My new mailing";
var mailingId = 123L;
-
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, type: null);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_campaignid()
{
// Arrange
@@ -69,24 +59,19 @@ public async Task CreateMailing_with_campaignid()
var mailingId = 123L;
var campaignId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, campaignId: campaignId);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_type()
{
// Arrange
@@ -94,23 +79,19 @@ public async Task CreateMailing_with_type()
var mailingId = 123L;
var type = MailingType.Recurring;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = type.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, type: type);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_recurringid()
{
// Arrange
@@ -118,24 +99,19 @@ public async Task CreateMailing_with_recurringid()
var mailingId = 123L;
var recurringId = 222L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "recurring_id", Value = recurringId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, recurringId: recurringId);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_encoding()
{
// Arrange
@@ -143,24 +119,19 @@ public async Task CreateMailing_with_encoding()
var mailingId = 123L;
var encoding = MessageEncoding.Iso8859;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, encoding: encoding);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_trasnferencoding()
{
// Arrange
@@ -168,105 +139,85 @@ public async Task CreateMailing_with_trasnferencoding()
var mailingId = 123L;
var transferEncoding = TransferEncoding.Base64;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "transfer_encoding", Value = transferEncoding.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, transferEncoding: transferEncoding);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task CreateMailing_with_clientid()
{
// Arrange
var name = "My new mailing";
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = MailingType.Standard.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.CreateAsync(USER_KEY, name, clientId: CLIENT_ID);
// Assert
result.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task DeleteMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Delete/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Delete")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.DeleteAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Delete/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Delete")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.DeleteAsync(USER_KEY, mailingId, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"id\":\"{0}\",\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}}}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetAsync(USER_KEY, mailingId);
// Assert
@@ -274,22 +225,18 @@ public async Task GetMailing_with_minimal_parameters()
result.Id.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task GetMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"id\":\"{0}\",\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}}}}", mailingId);
- var mockRestClient = new MockRestClient("/Mailing/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetAsync(USER_KEY, mailingId, CLIENT_ID);
// Assert
@@ -297,22 +244,19 @@ public async Task GetMailing_with_clientid()
result.Id.ShouldBe(mailingId);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_minimal_parameters()
{
// Arrange
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY);
// Assert
@@ -322,7 +266,7 @@ public async Task GetMailings_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_status()
{
// Arrange
@@ -330,16 +274,12 @@ public async Task GetMailings_with_status()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, status: status);
// Assert
@@ -349,7 +289,7 @@ public async Task GetMailings_with_status()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_type()
{
// Arrange
@@ -357,16 +297,12 @@ public async Task GetMailings_with_type()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = type.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, type: type);
// Assert
@@ -376,7 +312,7 @@ public async Task GetMailings_with_type()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_name()
{
// Arrange
@@ -384,16 +320,12 @@ public async Task GetMailings_with_name()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, name: name);
// Assert
@@ -403,7 +335,7 @@ public async Task GetMailings_with_name()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_listid()
{
// Arrange
@@ -411,16 +343,12 @@ public async Task GetMailings_with_listid()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, listId: listId);
// Assert
@@ -430,7 +358,7 @@ public async Task GetMailings_with_listid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_campaignid()
{
// Arrange
@@ -438,16 +366,12 @@ public async Task GetMailings_with_campaignid()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, campaignId: campaignId);
// Assert
@@ -457,7 +381,7 @@ public async Task GetMailings_with_campaignid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_recurringid()
{
// Arrange
@@ -465,16 +389,12 @@ public async Task GetMailings_with_recurringid()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "recurring_id", Value = recurringId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, recurringId: recurringId);
// Assert
@@ -484,7 +404,7 @@ public async Task GetMailings_with_recurringid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_start()
{
// Arrange
@@ -492,16 +412,12 @@ public async Task GetMailings_with_start()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_date", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, start: start);
// Assert
@@ -511,7 +427,7 @@ public async Task GetMailings_with_start()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_end()
{
// Arrange
@@ -519,16 +435,12 @@ public async Task GetMailings_with_end()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_date", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, end: end);
// Assert
@@ -538,7 +450,7 @@ public async Task GetMailings_with_end()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_sortby()
{
// Arrange
@@ -546,16 +458,12 @@ public async Task GetMailings_with_sortby()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sort_by", Value = sortBy.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, sortBy: sortBy);
// Assert
@@ -565,7 +473,7 @@ public async Task GetMailings_with_sortby()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_sortdirection()
{
// Arrange
@@ -573,16 +481,12 @@ public async Task GetMailings_with_sortdirection()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "direction", Value = sortDirection.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, sortDirection: sortDirection);
// Assert
@@ -592,7 +496,7 @@ public async Task GetMailings_with_sortdirection()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_limit()
{
// Arrange
@@ -600,16 +504,12 @@ public async Task GetMailings_with_limit()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, limit: limit);
// Assert
@@ -619,7 +519,7 @@ public async Task GetMailings_with_limit()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_offset()
{
// Arrange
@@ -627,16 +527,12 @@ public async Task GetMailings_with_offset()
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, offset: offset);
// Assert
@@ -646,23 +542,19 @@ public async Task GetMailings_with_offset()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailings_with_clientid()
{
// Arrange
var jsonMailing1 = "{\"id\":\"123\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
var jsonMailing2 = "{\"id\":\"456\",\"active_emails\":\"0\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/b020262b548e2ea3bdb540616ca2503cc19cbe3b3585224b\",\"share_email_link\":\"http://link.fictitiouscompany.com/share/443/b020262b548e2ea3af1ffc84f9135bef\",\"campaign_id\":\"0\",\"clickthru_html\":\"true\",\"clickthru_text\":\"true\",\"created_on\":\"2015-04-03 16:01:30\",\"encoding\":\"utf-8\",\"content_last_updated\":\"0000-00-00 00:00:00\",\"content_hash\":null,\"html_message\":null,\"list_id\":\"0\",\"name\":\"My mailing\",\"next_step\":\"recipients\",\"list_name\":null,\"opening_stats\":\"true\",\"scheduled_for\":\"0000-00-00 00:00:00\",\"scheduled_on\":\"0000-00-00 00:00:00\",\"sender_email\":null,\"sender_name\":null,\"bcc\":null,\"cc\":null,\"reply_to\":null,\"social_bar\":\"false\",\"footer\":null,\"status\":\"incomplete\",\"subject\":null,\"sublist_id\":\"0\",\"suspended\":\"false\",\"text_message\":null,\"tracking_params\":null,\"transfer_encoding\":\"quoted-printable\",\"type\":\"standard\",\"unsub_bottom_link\":\"true\",\"unsubscribes\":null}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"mailings\":[{0},{1}]}}}}", jsonMailing1, jsonMailing2);
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetMailingsAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -672,875 +564,718 @@ public async Task GetMailings_with_clientid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_status()
{
// Arrange
var status = MailingStatus.Scheduled;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, status: status);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_type()
{
// Arrange
var type = MailingType.Standard;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = type.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, type: type);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_name()
{
// Arrange
var name = "My mailing";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, name: name);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_listid()
{
// Arrange
var listId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, listId: listId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_campaignid()
{
// Arrange
var campaignId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, campaignId: campaignId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_recurringid()
{
// Arrange
var recurringId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "recurring_id", Value = recurringId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, recurringId: recurringId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_start()
{
// Arrange
var start = new DateTime(2015, 1, 1);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_date", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, start: start);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_end()
{
// Arrange
var end = new DateTime(2015, 12, 31, 23, 59, 59);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_date", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, end: end);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingsCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_campaignid()
{
// Arrange
var mailingId = 123L;
var campaignId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, campaignId: campaignId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_listid()
{
// Arrange
var mailingId = 123L;
var listId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, listId: listId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_sublistid()
{
// Arrange
var mailingId = 123L;
var sublistId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = sublistId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, sublistId: sublistId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_name()
{
// Arrange
var mailingId = 123L;
var name = "My mailing";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, name: name);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_type()
{
// Arrange
var mailingId = 123L;
var type = MailingType.Standard;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "type", Value = type.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, type: type);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_encoding()
{
// Arrange
var mailingId = 123L;
var encoding = MessageEncoding.Utf8;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, encoding: encoding);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_transferencoding()
{
// Arrange
var mailingId = 123L;
var transferEncoding = TransferEncoding.Base64;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "transfer_encoding", Value = transferEncoding.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, transferEncoding: transferEncoding);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_subject()
{
// Arrange
var mailingId = 123L;
var subject = "My mailing subject";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = subject }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, subject: subject);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_senderemail()
{
// Arrange
var mailingId = 123L;
var senderEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = senderEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, senderEmail: senderEmail);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_sendername()
{
// Arrange
var mailingId = 123L;
var senderName = "Bob Smith";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = senderName }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, senderName: senderName);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_replyto()
{
// Arrange
var mailingId = 123L;
var replyTo = "marketing@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "reply_to", Value = replyTo }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, replyTo: replyTo);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_htmlcontent()
{
// Arrange
var mailingId = 123L;
var htmlContent = "Hello world";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = htmlContent }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, htmlContent: htmlContent);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_textcontent()
{
// Arrange
var mailingId = 123L;
var textContent = "Hello world";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = textContent }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, textContent: textContent);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackopens_true()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "opening_stats", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackOpens: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackopens_false()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "opening_stats", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackOpens: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackclicksinhtml_true()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_html", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackClicksInHtml: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackclicksinhtml_false()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_html", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackClicksInHtml: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackclicksintext_true()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_text", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackClicksInText: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackclicksintext_false()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_text", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackClicksInText: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_trackingparameters()
{
// Arrange
var mailingId = 123L;
var trackingParameters = "param1=abc¶m2=123";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_params", Value = trackingParameters }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, trackingParameters: trackingParameters);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_endingon()
{
// Arrange
var mailingId = 123L;
var endingOn = new DateTime(2015, 7, 10);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "ending_on", Value = endingOn.ToCakeMailString() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, endingOn: endingOn);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_maxrecurrences()
{
// Arrange
var mailingId = 123L;
var maxRecurrences = 99;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "max_recurrences", Value = maxRecurrences }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, maxRecurrences: maxRecurrences);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_recurringconditions()
{
// Arrange
var mailingId = 123L;
var recurringConditions = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "recurring_conditions", Value = recurringConditions }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, recurringConditions: recurringConditions);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateMailing_with_clientid()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UpdateAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SendMailingTestEmail_with_minimal_parameters()
{
// Arrange
var mailingId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "merged" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.SendTestEmailAsync(USER_KEY, mailingId, recipientEmail);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SendMailingTestEmail_with_separated_true()
{
// Arrange
var mailingId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "separated" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.SendTestEmailAsync(USER_KEY, mailingId, recipientEmail, separated: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SendMailingTestEmail_with_clientid()
{
// Arrange
var mailingId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "merged" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.SendTestEmailAsync(USER_KEY, mailingId, recipientEmail, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawEmailMessage_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetEmailMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetEmailMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawEmailMessageAsync(USER_KEY, mailingId);
// Assert
@@ -1548,22 +1283,18 @@ public async Task GetMailingRawEmailMessage_with_minimal_parameters()
result.Subject.ShouldBe("This is a simple message");
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawEmailMessage_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetEmailMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetEmailMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawEmailMessageAsync(USER_KEY, mailingId, CLIENT_ID);
// Assert
@@ -1571,288 +1302,242 @@ public async Task GetMailingRawEmailMessage_with_clientid()
result.Subject.ShouldBe("This is a simple message");
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawHtml_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Mailing/GetHtmlMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetHtmlMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawHtmlAsync(USER_KEY, mailingId);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawHtml_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Mailing/GetHtmlMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetHtmlMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawHtmlAsync(USER_KEY, mailingId, CLIENT_ID);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawText_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Mailing/GetTextMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetTextMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawTextAsync(USER_KEY, mailingId);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetMailingRawText_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Mailing/GetTextMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetTextMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetRawTextAsync(USER_KEY, mailingId, CLIENT_ID);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task ScheduleMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Schedule/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.ScheduleAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task ScheduleMailing_with_date()
{
// Arrange
var mailingId = 12345L;
var date = new DateTime(2015, 4, 3, 17, 0, 0);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "date", Value = date.ToCakeMailString() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Schedule/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.ScheduleAsync(USER_KEY, mailingId, date: date);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task ScheduleMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Schedule/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Schedule")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.ScheduleAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UnscheduleMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Unschedule/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Unschedule")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UnscheduleAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UnscheduleMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Unschedule/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Unschedule")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.UnscheduleAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SuspendMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Suspend/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Suspend")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.SuspendAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SuspendMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Suspend/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Suspend")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.SuspendAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task ResumeMailing_with_minimal_parameters()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Resume/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Resume")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.ResumeAsync(USER_KEY, mailingId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task ResumeMailing_with_clientid()
{
// Arrange
var mailingId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Mailing/Resume/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/Resume")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.ResumeAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_minimal_parameters()
{
// Arrange
@@ -1861,18 +1546,12 @@ public async Task GetMailingLogs_with_minimal_parameters()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId);
// Assert
@@ -1880,7 +1559,7 @@ public async Task GetMailingLogs_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_logtype()
{
// Arrange
@@ -1889,19 +1568,12 @@ public async Task GetMailingLogs_with_logtype()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, logType: logType);
// Assert
@@ -1909,7 +1581,7 @@ public async Task GetMailingLogs_with_logtype()
result.Count().ShouldBe(1);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_listmemberid()
{
// Arrange
@@ -1918,19 +1590,12 @@ public async Task GetMailingLogs_with_listmemberid()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, listMemberId: listMemberId);
// Assert
@@ -1938,7 +1603,7 @@ public async Task GetMailingLogs_with_listmemberid()
result.Count().ShouldBe(1);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_startdate()
{
// Arrange
@@ -1948,19 +1613,12 @@ public async Task GetMailingLogs_with_startdate()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, start: start);
// Assert
@@ -1968,7 +1626,7 @@ public async Task GetMailingLogs_with_startdate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_enddate()
{
// Arrange
@@ -1978,19 +1636,12 @@ public async Task GetMailingLogs_with_enddate()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: false, totals: false, end: end);
// Assert
@@ -1998,7 +1649,7 @@ public async Task GetMailingLogs_with_enddate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_limit()
{
// Arrange
@@ -2008,19 +1659,12 @@ public async Task GetMailingLogs_with_limit()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: false, totals: false, limit: limit);
// Assert
@@ -2028,7 +1672,7 @@ public async Task GetMailingLogs_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_offset()
{
// Arrange
@@ -2038,19 +1682,12 @@ public async Task GetMailingLogs_with_offset()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: false, totals: false, offset: offset);
// Assert
@@ -2058,7 +1695,7 @@ public async Task GetMailingLogs_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_clientid()
{
// Arrange
@@ -2067,19 +1704,12 @@ public async Task GetMailingLogs_with_clientid()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: false, totals: false, clientId: CLIENT_ID);
// Assert
@@ -2087,7 +1717,7 @@ public async Task GetMailingLogs_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_uniques_true()
{
// Arrange
@@ -2096,18 +1726,12 @@ public async Task GetMailingLogs_with_uniques_true()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: true, totals: false);
// Assert
@@ -2115,7 +1739,7 @@ public async Task GetMailingLogs_with_uniques_true()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogs_with_totals_true()
{
// Arrange
@@ -2124,18 +1748,12 @@ public async Task GetMailingLogs_with_totals_true()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsAsync(USER_KEY, mailingId, uniques: false, totals: true);
// Assert
@@ -2143,24 +1761,18 @@ public async Task GetMailingLogs_with_totals_true()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_minimal_parameters()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId);
// Assert
@@ -2168,26 +1780,19 @@ public async Task GetMailingLogsCount_with_minimal_parameters()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_logtype()
{
// Arrange
var mailingId = 123L;
var logType = LogType.Sent;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, logType: logType);
// Assert
@@ -2195,26 +1800,19 @@ public async Task GetMailingLogsCount_with_logtype()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_listmemberid()
{
// Arrange
var mailingId = 123L;
var listMemberId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, listMemberId: listMemberId);
// Assert
@@ -2222,24 +1820,18 @@ public async Task GetMailingLogsCount_with_listmemberid()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_uniques_true()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, uniques: true);
// Assert
@@ -2247,24 +1839,18 @@ public async Task GetMailingLogsCount_with_uniques_true()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_totals_true()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, totals: true);
// Assert
@@ -2272,26 +1858,19 @@ public async Task GetMailingLogsCount_with_totals_true()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_startdate()
{
// Arrange
var mailingId = 123L;
var start = new DateTime(2015, 1, 1, 0, 0, 0);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, start: start);
// Assert
@@ -2299,26 +1878,19 @@ public async Task GetMailingLogsCount_with_startdate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_enddate()
{
// Arrange
var mailingId = 123L;
var end = new DateTime(2015, 12, 31, 23, 59, 59);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, end: end);
// Assert
@@ -2326,25 +1898,18 @@ public async Task GetMailingLogsCount_with_enddate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLogsCount_with_clientid()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLogsCountAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
@@ -2352,7 +1917,7 @@ public async Task GetMailingLogsCount_with_clientid()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinks_with_minimal_parameters()
{
// Arrange
@@ -2361,16 +1926,12 @@ public async Task GetMailingLinks_with_minimal_parameters()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksAsync(USER_KEY, mailingId);
// Assert
@@ -2378,7 +1939,7 @@ public async Task GetMailingLinks_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinks_with_limit()
{
// Arrange
@@ -2388,17 +1949,12 @@ public async Task GetMailingLinks_with_limit()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksAsync(USER_KEY, mailingId, limit: limit);
// Assert
@@ -2406,7 +1962,7 @@ public async Task GetMailingLinks_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinks_with_offset()
{
// Arrange
@@ -2416,17 +1972,12 @@ public async Task GetMailingLinks_with_offset()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksAsync(USER_KEY, mailingId, offset: offset);
// Assert
@@ -2434,7 +1985,7 @@ public async Task GetMailingLinks_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinks_with_clientid()
{
// Arrange
@@ -2443,17 +1994,12 @@ public async Task GetMailingLinks_with_clientid()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
@@ -2461,66 +2007,54 @@ public async Task GetMailingLinks_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksCount_with_minimal_parameters()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksCountAsync(USER_KEY, mailingId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksCount_with_clientid()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksCountAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLink_with_minimal_parameters()
{
// Arrange
var linkId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "link_id", Value = linkId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId);
- var mockRestClient = new MockRestClient("/Mailing/GetLinkInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinkInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinkAsync(USER_KEY, linkId);
// Assert
@@ -2528,22 +2062,18 @@ public async Task GetMailingLink_with_minimal_parameters()
result.Id.ShouldBe(linkId);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLink_with_clientid()
{
// Arrange
var linkId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "link_id", Value = linkId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId);
- var mockRestClient = new MockRestClient("/Mailing/GetLinkInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinkInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinkAsync(USER_KEY, linkId, CLIENT_ID);
// Assert
@@ -2551,7 +2081,7 @@ public async Task GetMailingLink_with_clientid()
result.Id.ShouldBe(linkId);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_minimal_parameters()
{
// Arrange
@@ -2560,16 +2090,12 @@ public async Task GetMailingLinksWithStats_with_minimal_parameters()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId);
// Assert
@@ -2577,7 +2103,7 @@ public async Task GetMailingLinksWithStats_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_start()
{
// Arrange
@@ -2587,17 +2113,12 @@ public async Task GetMailingLinksWithStats_with_start()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId, start: start);
// Assert
@@ -2605,7 +2126,7 @@ public async Task GetMailingLinksWithStats_with_start()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_end()
{
// Arrange
@@ -2615,17 +2136,12 @@ public async Task GetMailingLinksWithStats_with_end()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId, end: end);
// Assert
@@ -2633,7 +2149,7 @@ public async Task GetMailingLinksWithStats_with_end()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_limit()
{
// Arrange
@@ -2643,17 +2159,12 @@ public async Task GetMailingLinksWithStats_with_limit()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId, limit: limit);
// Assert
@@ -2661,7 +2172,7 @@ public async Task GetMailingLinksWithStats_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_offset()
{
// Arrange
@@ -2671,17 +2182,12 @@ public async Task GetMailingLinksWithStats_with_offset()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId, offset: offset);
// Assert
@@ -2689,7 +2195,7 @@ public async Task GetMailingLinksWithStats_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStats_with_clientid()
{
// Arrange
@@ -2698,17 +2204,12 @@ public async Task GetMailingLinksWithStats_with_clientid()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
@@ -2716,29 +2217,25 @@ public async Task GetMailingLinksWithStats_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_minimal_parameters()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId);
// Assert
result.ShouldBe(3);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_start()
{
// Arrange
@@ -2748,112 +2245,87 @@ public async Task GetMailingLinksWithStatsCount_with_start()
var jsonLink1 = string.Format("{{\"id\":\"111111\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\",\"mailing_id\":\"{0}\",\"unique\":\"3\",\"total\":\"10\",\"unique_rate\":\"2\",\"total_rate\":\"1\"}}", mailingId);
var jsonLink2 = string.Format("{{\"id\":\"222222\",\"link_to\":\"http://www.fictitiouscompany.com.com/\",\"mailing_id\":\"{0}\",\"unique\":\"1\",\"total\":\"2\",\"unique_rate\":\"1\",\"total_rate\":\"2\"}}", mailingId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId, start: start);
// Assert
result.ShouldBe(3);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_end()
{
// Arrange
var mailingId = 123L;
var end = new DateTime(2015, 12, 31);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId, end: end);
// Assert
result.ShouldBe(3);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_limit()
{
// Arrange
var mailingId = 123L;
var limit = 5;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId, limit: limit);
// Assert
result.ShouldBe(3);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_offset()
{
// Arrange
var mailingId = 123L;
var offset = 25;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId, offset: offset);
// Assert
result.ShouldBe(3);
}
- [TestMethod]
+ [Fact]
public async Task GetMailingLinksWithStatsCount_with_clientid()
{
// Arrange
var mailingId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "mailing_id", Value = mailingId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"links\":[],\"count\":\"3\"}}";
- var mockRestClient = new MockRestClient("/Mailing/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Mailing/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Mailings.GetLinksWithStatsCountAsync(USER_KEY, mailingId, clientId: CLIENT_ID);
// Assert
diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs
new file mode 100644
index 0000000..8ab6dc1
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Permissions.cs
@@ -0,0 +1,88 @@
+using RichardSzalay.MockHttp;
+using Shouldly;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CakeMail.RestClient.UnitTests.Resources
+{
+ public class PermissionsTests
+ {
+ private const string API_KEY = "...dummy API key...";
+ private const string USER_KEY = "...dummy USER key...";
+ private const long CLIENT_ID = 999;
+
+ [Fact]
+ public async Task SetPermissions_with_minimal_parameters()
+ {
+ // Arrange
+ var userId = 1234L;
+ var permissions = new string[] { "FirstPermission", "SecondPermission", "ThirdPermission" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/SetPermissions")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, null);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SetPermissions_with_customerid()
+ {
+ // Arrange
+ var userId = 1234L;
+ var permissions = new string[] { "FirstPermission", "SecondPermission", "ThirdPermission" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/SetPermissions")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Permissions.SetUserPermissionsAsync(USER_KEY, userId, permissions, CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetPermissions_with_minimal_parameters()
+ {
+ // Arrange
+ var userId = 1234L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"FirstPermission\",\"SecondPermission\",\"ThirdPermission\"],\"user_id\":\"{0}\"}}}}", userId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/GetPermissions")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task GetPermissions_with_clientid()
+ {
+ // Arrange
+ var userId = 1234L;
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"FirstPermission\",\"SecondPermission\",\"ThirdPermission\"],\"user_id\":\"{0}\"}}}}", userId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Permission/GetPermissions")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Permissions.GetUserPermissionsAsync(USER_KEY, userId, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+ }
+}
diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs
new file mode 100644
index 0000000..c1c7539
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Relays.cs
@@ -0,0 +1,349 @@
+using CakeMail.RestClient.Models;
+using RichardSzalay.MockHttp;
+using Shouldly;
+using System;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CakeMail.RestClient.UnitTests.Resources
+{
+ public class RelaysTests
+ {
+ private const string API_KEY = "...dummy API key...";
+ private const string USER_KEY = "...dummy USER key...";
+ private const long CLIENT_ID = 999;
+ private const long TRACKING_ID = 123;
+ private const string RECIPIENT_EMAIL = "bobsmith@fictitiouscompany.com";
+ private const string SENDER_EMAIL = "marketing@marketingcompany.com";
+ private const string SENDER_NAME = "The Marketing Group";
+ private const string HTML_CONTENT = "Hello World";
+ private const string TEXT_CONTENT = "Hello Wolrd";
+ private const string SUBJECT = "Hello!";
+
+ [Fact]
+ public async Task SendRelay_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendRelay_with_SENDER_NAME()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, SENDER_NAME);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendRelay_with_encoding()
+ {
+ // Arrange
+ var encoding = MessageEncoding.Utf8;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, encoding: encoding);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendRelay_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithoutTrackingAsync(USER_KEY, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendTrackedRelay_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendTrackedRelay_with_SENDER_NAME()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, SENDER_NAME);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendTrackedRelay_with_encoding()
+ {
+ // Arrange
+ var encoding = MessageEncoding.Utf8;
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, encoding: encoding);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SendTrackedRelay_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/Send")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.SendWithTrackingAsync(USER_KEY, TRACKING_ID, RECIPIENT_EMAIL, SUBJECT, HTML_CONTENT, TEXT_CONTENT, SENDER_EMAIL, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task GetRelaySentLogs_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayOpenLogs_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonOpenLog1 = "{\"email\":\"aaa@aaa.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"relay_id\":\"88258598\",\"sent_id\":\"8280816\",\"time\":\"2015-04-06 00:06:17\",\"tracking_id\":\"722823822\",\"user_agent\":\"Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)\"}";
+ var jsonOpenLog2 = "{\"email\":\"bbb@bbb.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"relay_id\":\"88249402\",\"sent_id\":\"8271692\",\"time\":\"2015-04-06 00:13:41\",\"tracking_id\":\"1457837189\",\"user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko)\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"open_logs\":[{0},{1}]}}}}", jsonOpenLog1, jsonOpenLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetOpenLogsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayClickLogs_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonClickLog1 = "{\"email\":\"aaa@aaa.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"link_to\":\"http://www.fictitiouscompany.com\",\"relay_id\":\"88750676\",\"sent_id\":\"8356550\",\"time\":\"2015-04-06 00:17:52\",\"tracking_id\":\"1744041192\",\"user_agent\":\"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53\"}";
+ var jsonClickLog2 = "{\"email\":\"bbb@bbb.com\",\"host\":null,\"ip\":\"127.0.0.1\",\"link_to\":\"http://www.fictitiouscompany.com\",\"relay_id\":\"86668371\",\"sent_id\":\"8013252\",\"time\":\"2015-04-06 00:47:14\",\"tracking_id\":\"1558835933\",\"user_agent\":\"Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B440 Safari/600.1.4\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clickthru_logs\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetClickLogsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayBounceLogs_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonBounceLog1 = "{\"bounce_type\":\"bounce_sb\",\"email\":\"aaa@aaa.com\",\"relay_id\":\"88935339\",\"sent_id\":\"0\",\"time\":\"2015-04-06 08:08:25\",\"tracking_id\":\"251364339\"}";
+ var jsonBounceLog2 = "{\"bounce_type\":\"bounce_fm\",\"email\":\"bbb@bbb.com\",\"relay_id\":\"88240001\",\"sent_id\":\"0\",\"time\":\"2015-04-06 09:27:13\",\"tracking_id\":\"412676746\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"bounce_logs\":[{0},{1}]}}}}", jsonBounceLog1, jsonBounceLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetBounceLogsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_TRACKING_ID()
+ {
+ // Arrange
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, TRACKING_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_startdate()
+ {
+ // Arrange
+ var start = new DateTime(2015, 1, 1, 0, 0, 0);
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, start: start);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_enddate()
+ {
+ // Arrange
+ var end = new DateTime(2015, 1, 1, 0, 0, 0);
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, end: end);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_limit()
+ {
+ // Arrange
+ var limit = 5;
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_offset()
+ {
+ // Arrange
+ var offset = 25;
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetRelayLogs_with_clientid()
+ {
+ // Arrange
+ var jsonSentLog1 = "{\"email\":\"aaa@aaa.com\",\"relay_id\":\"88934439\",\"sent_id\":\"8398053\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1912196542\"}";
+ var jsonSentLog2 = "{\"email\":\"bbb@bbb.com\",\"relay_id\":\"88934440\",\"sent_id\":\"8398054\",\"time\":\"2015-04-06 08:02:10\",\"tracking_id\":\"1289082963\"}";
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sent_logs\":[{0},{1}]}}}}", jsonSentLog1, jsonSentLog2);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Relay/GetLogs")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.Relays.GetSentLogsAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+ }
+}
diff --git a/CakeMail.RestClient.UnitTests/Segments.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs
similarity index 53%
rename from CakeMail.RestClient.UnitTests/Segments.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs
index eebfb12..d8ff284 100644
--- a/CakeMail.RestClient.UnitTests/Segments.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Segments.cs
@@ -1,19 +1,19 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class SegmentsTests
{
private const string API_KEY = "...dummy API key...";
private const string USER_KEY = "...dummy USER key...";
private const long CLIENT_ID = 999;
- [TestMethod]
+ [Fact]
public async Task CreateSegment_with_query()
{
// Arrange
@@ -21,175 +21,138 @@ public async Task CreateSegment_with_query()
var query = "???";
var listId = 123L;
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "query", Value = query }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", segmentId);
- var mockRestClient = new MockRestClient("/List/CreateSublist/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/CreateSublist")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.CreateAsync(USER_KEY, listId, name, query, null);
// Assert
result.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task CreateSegment_with_clientid()
{
// Arrange
var name = "My Segment";
var listId = 123L;
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", segmentId);
- var mockRestClient = new MockRestClient("/List/CreateSublist/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/CreateSublist")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.CreateAsync(USER_KEY, listId, name, null, CLIENT_ID);
// Assert
result.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task UpdateSegment_name()
{
// Arrange
var listId = 123L;
var segmentId = 456L;
var name = "My list";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.UpdateAsync(USER_KEY, segmentId, listId, name: name);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateSegment_query()
{
// Arrange
var listId = 123L;
var segmentId = 456L;
var query = "???";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "query", Value = query }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.UpdateAsync(USER_KEY, segmentId, listId, query: query);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateSegment_clientid()
{
// Arrange
var listId = 123L;
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.UpdateAsync(USER_KEY, segmentId, listId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteSegment_wit_minimal_parameters()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteSublist/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteSublist")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.DeleteAsync(USER_KEY, segmentId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteSegment_with_clientid()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/List/DeleteSublist/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/DeleteSublist")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.DeleteAsync(USER_KEY, segmentId, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_minimal_parameters()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId);
// Assert
@@ -197,22 +160,17 @@ public async Task GetSegment_with_minimal_parameters()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_includestatistics_true()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId, includeStatistics: true);
// Assert
@@ -220,22 +178,17 @@ public async Task GetSegment_with_includestatistics_true()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_includestatistics_false()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId, includeStatistics: false);
// Assert
@@ -243,22 +196,17 @@ public async Task GetSegment_with_includestatistics_false()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_calculateengagement_true()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "true" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId, calculateEngagement: true);
// Assert
@@ -266,22 +214,17 @@ public async Task GetSegment_with_calculateengagement_true()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_calculateengagement_false()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId, calculateEngagement: false);
// Assert
@@ -289,23 +232,17 @@ public async Task GetSegment_with_calculateengagement_false()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegment_with_clientid()
{
// Arrange
var segmentId = 456L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "sublist_id", Value = segmentId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "with_engagement", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"list_id\":\"111\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}}}", segmentId);
- var mockRestClient = new MockRestClient("/List/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetAsync(USER_KEY, segmentId, clientId: CLIENT_ID);
// Assert
@@ -313,24 +250,19 @@ public async Task GetSegment_with_clientid()
result.Id.ShouldBe(segmentId);
}
- [TestMethod]
+ [Fact]
public async Task GetSegments_with_details_false()
{
// Arrange
var listId = 123L;
var jsonSegment1 = string.Format("{{\"id\":\"123\",\"list_id\":\"{0}\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
var jsonSegment2 = string.Format("{{\"id\":\"456\",\"list_id\":\"{0}\",\"name\":\"Second Segment\",\"query\":\"(`email` LIKE \\\"%bb%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "true" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2);
- var mockRestClient = new MockRestClient("/List/GetSublists/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetSegmentsAsync(USER_KEY, listId, includeDetails: false);
// Assert
@@ -338,7 +270,7 @@ public async Task GetSegments_with_details_false()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetSegments_with_limit()
{
// Arrange
@@ -346,18 +278,12 @@ public async Task GetSegments_with_limit()
var limit = 5;
var jsonSegment1 = string.Format("{{\"id\":\"123\",\"list_id\":\"{0}\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
var jsonSegment2 = string.Format("{{\"id\":\"456\",\"list_id\":\"{0}\",\"name\":\"Second Segment\",\"query\":\"(`email` LIKE \\\"%bb%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2);
- var mockRestClient = new MockRestClient("/List/GetSublists/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetSegmentsAsync(USER_KEY, listId, limit: limit);
// Assert
@@ -365,7 +291,7 @@ public async Task GetSegments_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetSegments_with_offset()
{
// Arrange
@@ -373,18 +299,12 @@ public async Task GetSegments_with_offset()
var offset = 5;
var jsonSegment1 = string.Format("{{\"id\":\"123\",\"list_id\":\"{0}\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
var jsonSegment2 = string.Format("{{\"id\":\"456\",\"list_id\":\"{0}\",\"name\":\"Second Segment\",\"query\":\"(`email` LIKE \\\"%bb%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2);
- var mockRestClient = new MockRestClient("/List/GetSublists/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetSegmentsAsync(USER_KEY, listId, offset: offset);
// Assert
@@ -392,25 +312,19 @@ public async Task GetSegments_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetSegments_with_clientid()
{
// Arrange
var listId = 123L;
var jsonSegment1 = string.Format("{{\"id\":\"123\",\"list_id\":\"{0}\",\"name\":\"First Segment\",\"query\":\"(`email` LIKE \\\"%aa%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
var jsonSegment2 = string.Format("{{\"id\":\"456\",\"list_id\":\"{0}\",\"name\":\"Second Segment\",\"query\":\"(`email` LIKE \\\"%bb%\\\")\",\"mailings_count\":\"0\",\"last_used\":\"0000-00-00 00:00:00\",\"created_on\":\"2015-03-27 21:15:19\",\"engagement\":null,\"count\":\"0\"}}", listId);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "no_details", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"sublists\":[{0},{1}]}}}}", jsonSegment1, jsonSegment2);
- var mockRestClient = new MockRestClient("/List/GetSublists/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetSublists")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetSegmentsAsync(USER_KEY, listId, clientId: CLIENT_ID);
// Assert
@@ -418,43 +332,34 @@ public async Task GetSegments_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetSegmentsCount_with_minimal_parameters()
{
// Arrange
var listId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetCountAsync(USER_KEY, listId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetSegmentsCount_with_clientid()
{
// Arrange
var listId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/List/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("List/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Segments.GetCountAsync(USER_KEY, listId, CLIENT_ID);
// Assert
diff --git a/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs b/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs
new file mode 100644
index 0000000..295cfd4
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/SuppressionLists.cs
@@ -0,0 +1,640 @@
+using RichardSzalay.MockHttp;
+using Shouldly;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CakeMail.RestClient.UnitTests.Resources
+{
+ public class SuppressionListsTests
+ {
+ private const string API_KEY = "...dummy API key...";
+ private const string USER_KEY = "...dummy USER key...";
+ private const long CLIENT_ID = 999;
+
+ [Fact]
+ public async Task AddEmailAddressesToSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddEmailAddressesToSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddEmailAddressesToSuppressionList_with_clientid()
+ {
+ // Arrange
+ var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddDomainsToSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddDomainsToSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task AddDomainsToSuppressionList_with_clientid()
+ {
+ // Arrange
+ var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddDomainsAsync(USER_KEY, domains, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddLocalPartsToSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var localParts = new[] { "administrator", "manager", "info" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task AddLocalPartsToSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task AddLocalPartsToSuppressionList_with_clientid()
+ {
+ // Arrange
+ var localParts = new[] { "administrator", "manager", "info" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ImportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.AddLocalPartsAsync(USER_KEY, localParts, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveEmailAddressesFromSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveEmailAddressesFromSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task RemoveEmailAddressesFromSuppressionList_with_clientid()
+ {
+ // Arrange
+ var emailAddresses = new[] { "aaa@aaa.com", "bbb@bbb.com", "ccc@ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"email\":\"aaa@aaa.com\"},{\"email\":\"bbb@bbb.com\"},{\"email\":\"ccc@ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveEmailAddressesAsync(USER_KEY, emailAddresses, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveDomainsFromSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveDomainsFromSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task RemoveDomainsFromSuppressionList_with_clientid()
+ {
+ // Arrange
+ var domains = new[] { "aaa.com", "bbb.com", "ccc.com" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"domain\":\"aaa.com\"},{\"domain\":\"bbb.com\"},{\"domain\":\"ccc.com\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveDomainsAsync(USER_KEY, domains, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveLocalPartsFromSuppressionList_with_minimal_parameters()
+ {
+ // Arrange
+ var localParts = new[] { "administrator", "manager", "info" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task RemoveLocalPartsFromSuppressionList_with_null_array()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":[]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, null);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(0);
+ }
+
+ [Fact]
+ public async Task RemoveLocalPartsFromSuppressionList_with_clientid()
+ {
+ // Arrange
+ var localParts = new[] { "administrator", "manager", "info" };
+ var jsonResponse = "{\"status\":\"success\",\"data\":[{\"localpart\":\"administrator\"},{\"localpart\":\"manager\"},{\"localpart\":\"info\"}]}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/DeleteLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.RemoveLocalPartsAsync(USER_KEY, localParts, CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(3);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddresses_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddresses_with_limit()
+ {
+ // Arrange
+ var limit = 5;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddresses_with_offset()
+ {
+ // Arrange
+ var offset = 25;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddresses_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"emails\":[{\"email\":\"aaa@aaa.com\",\"source_type\":\"manual\"},{\"email\":\"bbb@bbb.com\",\"source_type\":\"manual\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomains_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomains_with_limit()
+ {
+ // Arrange
+ var limit = 5;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomains_with_offset()
+ {
+ // Arrange
+ var offset = 25;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomains_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"domains\":[{\"domain\":\"aaa.org\"},{\"domain\":\"bbb.com\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalParts_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalParts_with_limit()
+ {
+ // Arrange
+ var limit = 5;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, limit: limit);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalParts_with_offset()
+ {
+ // Arrange
+ var offset = 25;
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, offset: offset);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalParts_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"localparts\":[{\"localpart\":\"administrator\"},{\"localpart\":\"info\"}]}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldNotBeNull();
+ result.Count().ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddressesCount_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedEmailAddressesCount_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportEmails")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetEmailAddressesCountAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomainsCount_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedDomainsCount_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportDomains")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetDomainsCountAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalPartsCount_with_minimal_parameters()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+
+ [Fact]
+ public async Task GetSuppressedLocalPartsCount_with_clientid()
+ {
+ // Arrange
+ var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("SuppressionList/ExportLocalparts")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
+ var result = await apiClient.SuppressionLists.GetLocalPartsCountAsync(USER_KEY, clientId: CLIENT_ID);
+
+ // Assert
+ result.ShouldBe(2);
+ }
+ }
+}
diff --git a/CakeMail.RestClient.UnitTests/Templates.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs
similarity index 51%
rename from CakeMail.RestClient.UnitTests/Templates.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs
index 76c575e..24c3fe9 100644
--- a/CakeMail.RestClient.UnitTests/Templates.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Templates.cs
@@ -1,13 +1,13 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
+using Shouldly;
using System.Collections.Generic;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
-using Shouldly;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class TemplatesTests
{
private const string API_KEY = "...dummy API key...";
@@ -16,7 +16,7 @@ public class TemplatesTests
private const long TEMPLATE_ID = 123;
private const long CATEGORY_ID = 111;
- [TestMethod]
+ [Fact]
public async Task CreateTemplateCategory_with_minimal_parameters()
{
// Arrange
@@ -25,47 +25,35 @@ public async Task CreateTemplateCategory_with_minimal_parameters()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Ma Catégorie" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels);
// Assert
result.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplateCategory_with_no_labels()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, null);
// Assert
result.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplateCategory_with_isvisiblebydefault_false()
{
// Arrange
@@ -74,27 +62,19 @@ public async Task CreateTemplateCategory_with_isvisiblebydefault_false()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "0" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Ma Catégorie" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels, isVisibleByDefault: false);
// Assert
result.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplateCategory_with_templatescanbecopied_false()
{
// Arrange
@@ -103,27 +83,19 @@ public async Task CreateTemplateCategory_with_templatescanbecopied_false()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "0" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Ma Catégorie" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels, templatesCanBeCopied: false);
// Assert
result.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplateCategory_with_clientid()
{
// Arrange
@@ -132,79 +104,60 @@ public async Task CreateTemplateCategory_with_clientid()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Ma Catégorie" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", CATEGORY_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateCategoryAsync(USER_KEY, labels, clientId: CLIENT_ID);
// Assert
result.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task DeleteTemplateCategory_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/DeleteCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.DeleteCategoryAsync(USER_KEY, CATEGORY_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteTemplateCategory_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/DeleteCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.DeleteCategoryAsync(USER_KEY, CATEGORY_ID, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategory_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"owner_client_id\":\"{1}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}}}", CATEGORY_ID, CLIENT_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryAsync(USER_KEY, CATEGORY_ID);
// Assert
@@ -212,20 +165,16 @@ public async Task GetTemplateCategory_with_minimal_parameters()
result.Id.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategory_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"owner_client_id\":\"{1}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}}}", CATEGORY_ID, CLIENT_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryAsync(USER_KEY, CATEGORY_ID, CLIENT_ID);
// Assert
@@ -233,21 +182,18 @@ public async Task GetTemplateCategory_with_clientid()
result.Id.ShouldBe(CATEGORY_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategories_with_minimal_parameters()
{
// Arrange
var jsonCategory1 = string.Format("{{\"id\":\"111\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
var jsonCategory2 = string.Format("{{\"id\":\"222\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #2\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesAsync(USER_KEY);
// Assert
@@ -257,23 +203,19 @@ public async Task GetTemplateCategories_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategories_with_limit()
{
// Arrange
var limit = 5;
var jsonCategory1 = string.Format("{{\"id\":\"111\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
var jsonCategory2 = string.Format("{{\"id\":\"222\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #2\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesAsync(USER_KEY, limit: limit);
// Assert
@@ -283,23 +225,19 @@ public async Task GetTemplateCategories_with_limit()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategories_with_offset()
{
// Arrange
var offset = 25;
var jsonCategory1 = string.Format("{{\"id\":\"111\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
var jsonCategory2 = string.Format("{{\"id\":\"222\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #2\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesAsync(USER_KEY, offset: offset);
// Assert
@@ -309,22 +247,18 @@ public async Task GetTemplateCategories_with_offset()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategories_with_clientid()
{
// Arrange
var jsonCategory1 = string.Format("{{\"id\":\"111\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #1\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
var jsonCategory2 = string.Format("{{\"id\":\"222\",\"status\":\"active\",\"owner_client_id\":\"{0}\",\"templates_copyable\":\"1\",\"default\":\"0\",\"name\":\"Testing #2\",\"amount_templates\":\"1\",\"amount_clients\":\"0\",\"level\":\"1\"}}", CLIENT_ID);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"categories\":[{0},{1}]}}}}", jsonCategory1, jsonCategory2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -334,67 +268,55 @@ public async Task GetTemplateCategories_with_clientid()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoriesCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoriesCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategories/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategories")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoriesCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_labels()
{
// Arrange
@@ -403,147 +325,110 @@ public async Task UpdateTemplateCategory_with_labels()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[en_US]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[fr_FR]", Value = "Ma Catégorie" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, labels);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_default_true()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null, isVisibleByDefault: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_default_false()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "0" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null, isVisibleByDefault: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_copyable_true()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null, templatesCanBeCopied: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_copyable_false()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "0" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null, templatesCanBeCopied: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplateCategory_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "default", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "templates_copyable", Value = "1" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategory/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategory")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateCategoryAsync(USER_KEY, CATEGORY_ID, null, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibility_with_minimal_parameters()
{
// Arrange
var jsonVisibility1 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #1\",\"visible\":\"1\"}";
var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID);
// Assert
@@ -553,24 +438,19 @@ public async Task GetTemplateCategoryVisibility_with_minimal_parameters()
result.ToArray()[1].Visible.ShouldBeFalse();
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibility_with_limit()
{
// Arrange
var limit = 5;
var jsonVisibility1 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #1\",\"visible\":\"1\"}";
var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, limit: limit);
// Assert
@@ -578,24 +458,19 @@ public async Task GetTemplateCategoryVisibility_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibility_with_offset()
{
// Arrange
var offset = 25;
var jsonVisibility1 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #1\",\"visible\":\"1\"}";
var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, offset: offset);
// Assert
@@ -603,23 +478,18 @@ public async Task GetTemplateCategoryVisibility_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibility_with_clientid()
{
// Arrange
var jsonVisibility1 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #1\",\"visible\":\"1\"}";
var jsonVisibility2 = "{\"client_id\":\"111\",\"company_name\":\"Fictitious Company #2\",\"visible\":\"0\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"clients\":[{0},{1}]}}}}", jsonVisibility1, jsonVisibility2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, clientId: CLIENT_ID);
// Assert
@@ -627,48 +497,39 @@ public async Task GetTemplateCategoryVisibility_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibilityCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityCountAsync(USER_KEY, CATEGORY_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplateCategoryVisibilityCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCategoryVisibilityCountAsync(USER_KEY, CATEGORY_ID, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task SetTemplateCategoryVisibility_with_minimal_parameters()
{
// Arrange
@@ -677,46 +538,36 @@ public async Task SetTemplateCategoryVisibility_with_minimal_parameters()
{ 111L, true },
{ 222L, false }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[0][client_id]", Value = 111L },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[0][visible]", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[1][client_id]", Value = 222L },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[1][visible]", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.SetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, clientVisibility);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SetTemplateCategoryVisibility_with_empty_array()
{
// Arrange
var clientVisibility = (IDictionary)null;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.SetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, clientVisibility);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SetTemplateCategoryVisibility_with_clientid()
{
// Arrange
@@ -725,27 +576,19 @@ public async Task SetTemplateCategoryVisibility_with_clientid()
{ 111L, true },
{ 222L, false }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[0][client_id]", Value = 111L },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[0][visible]", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[1][client_id]", Value = 222L },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client[1][visible]", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetCategoryVisibility/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetCategoryVisibility")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.SetCategoryVisibilityAsync(USER_KEY, CATEGORY_ID, clientVisibility, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplate_with_minimal_parameters()
{
// Arrange
@@ -755,27 +598,19 @@ public async Task CreateTemplate_with_minimal_parameters()
{ "en_US", "My Template" },
{ "fr_FR", "Mon Modèle" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Template" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Mon Modèle" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "content", Value = content },
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateTemplate/", parameters, jsonResponse);
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", TEMPLATE_ID);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateAsync(USER_KEY, labels, content, CATEGORY_ID);
// Assert
result.ShouldBe(TEMPLATE_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplate_with_no_labels()
{
// Arrange
@@ -785,23 +620,19 @@ public async Task CreateTemplate_with_no_labels()
{ "en_US", "My Template" },
{ "fr_FR", "Mon modèle" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "content", Value = content },
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateTemplate/", parameters, jsonResponse);
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", TEMPLATE_ID);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateAsync(USER_KEY, null, content, CATEGORY_ID);
// Assert
result.ShouldBe(TEMPLATE_ID);
}
- [TestMethod]
+ [Fact]
public async Task CreateTemplate_with_clientid()
{
// Arrange
@@ -811,79 +642,60 @@ public async Task CreateTemplate_with_clientid()
{ "en_US", "My Template" },
{ "fr_FR", "Mon Modèle" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][language]", Value = "en_US" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[0][name]", Value = "My Template" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][language]", Value = "fr_FR" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[1][name]", Value = "Mon Modèle" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "content", Value = content },
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", TEMPLATE_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/CreateTemplate/", parameters, jsonResponse);
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", TEMPLATE_ID);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/CreateTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.CreateAsync(USER_KEY, labels, content, CATEGORY_ID, clientId: CLIENT_ID);
// Assert
result.ShouldBe(TEMPLATE_ID);
}
- [TestMethod]
+ [Fact]
public async Task DeleteTemplate_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/DeleteTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.DeleteAsync(USER_KEY, TEMPLATE_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteTemplate_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/DeleteTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/DeleteTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.DeleteAsync(USER_KEY, TEMPLATE_ID, CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTemplate_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"labels\":[],\"id\":\"{0}\",\"status\":\"active\",\"category_id\":\"7480\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}}}}", TEMPLATE_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetAsync(USER_KEY, TEMPLATE_ID);
// Assert
@@ -891,20 +703,16 @@ public async Task GetTemplate_with_minimal_parameters()
result.Id.ShouldBe(TEMPLATE_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplate_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"labels\":[],\"id\":\"{0}\",\"status\":\"active\",\"category_id\":\"7480\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}}}}", TEMPLATE_ID);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetAsync(USER_KEY, TEMPLATE_ID, CLIENT_ID);
// Assert
@@ -912,21 +720,18 @@ public async Task GetTemplate_with_clientid()
result.Id.ShouldBe(TEMPLATE_ID);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplates_with_minimal_parameters()
{
// Arrange
var jsonTemplate1 = "{\"labels\":[],\"id\":\"111\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}";
var jsonTemplate2 = "{\"labels\":[],\"id\":\"222\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"bbb\",\"description\":\"bbb\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetTemplatesAsync(USER_KEY);
// Assert
@@ -936,22 +741,18 @@ public async Task GetTemplates_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplates_with_CATEGORY_ID()
{
// Arrange
var jsonTemplate1 = "{\"labels\":[],\"id\":\"111\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}";
var jsonTemplate2 = "{\"labels\":[],\"id\":\"222\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"bbb\",\"description\":\"bbb\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetTemplatesAsync(USER_KEY, categoryId: CATEGORY_ID);
// Assert
@@ -961,23 +762,19 @@ public async Task GetTemplates_with_CATEGORY_ID()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplates_with_limit()
{
// Arrange
var limit = 5;
var jsonTemplate1 = "{\"labels\":[],\"id\":\"111\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}";
var jsonTemplate2 = "{\"labels\":[],\"id\":\"222\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"bbb\",\"description\":\"bbb\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetTemplatesAsync(USER_KEY, limit: limit);
// Assert
@@ -987,23 +784,19 @@ public async Task GetTemplates_with_limit()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplates_with_offset()
{
// Arrange
var offset = 25;
var jsonTemplate1 = "{\"labels\":[],\"id\":\"111\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}";
var jsonTemplate2 = "{\"labels\":[],\"id\":\"222\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"bbb\",\"description\":\"bbb\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetTemplatesAsync(USER_KEY, offset: offset);
// Assert
@@ -1013,22 +806,18 @@ public async Task GetTemplates_with_offset()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplates_with_clientid()
{
// Arrange
var jsonTemplate1 = "{\"labels\":[],\"id\":\"111\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"aaa\",\"description\":\"aaa\"}";
var jsonTemplate2 = "{\"labels\":[],\"id\":\"222\",\"status\":\"active\",\"category_id\":\"123\",\"type\":\"html\",\"content\":\"this is the content\",\"thumbnail\":null,\"last_modified\":\"2012-05-29 14:05:28\",\"editor_version\":\"0\",\"name\":\"bbb\",\"description\":\"bbb\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"templates\":[{0},{1}]}}}}", jsonTemplate1, jsonTemplate2);
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetTemplatesAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -1038,85 +827,71 @@ public async Task GetTemplates_with_clientid()
result.ToArray()[1].Id.ShouldBe(222);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplatesCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplatesCount_with_CATEGORY_ID()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCountAsync(USER_KEY, categoryId: CATEGORY_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTemplatesCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/TemplateV2/GetTemplates/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/GetTemplates")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplate_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateAsync(USER_KEY, TEMPLATE_ID, null);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplate_with_labels()
{
// Arrange
@@ -1125,78 +900,61 @@ public async Task UpdateTemplate_with_labels()
{ "en_US", "My Category" },
{ "fr_FR", "Ma Catégorie" }
};
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[en_US]", Value = "My Category" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "label[fr_FR]", Value = "Ma Catégorie" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateAsync(USER_KEY, TEMPLATE_ID, labels);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplate_with_content()
{
// Arrange
var content = "Sample content 4";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "content", Value = content }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateAsync(USER_KEY, TEMPLATE_ID, null, content: content);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplate_with_CATEGORY_ID()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "category_id", Value = CATEGORY_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateAsync(USER_KEY, TEMPLATE_ID, null, categoryId: CATEGORY_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTemplate_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "template_id", Value = TEMPLATE_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/TemplateV2/SetTemplate/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("TemplateV2/SetTemplate")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Templates.UpdateAsync(USER_KEY, TEMPLATE_ID, null, clientId: CLIENT_ID);
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Timezones.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs
similarity index 66%
rename from CakeMail.RestClient.UnitTests/Timezones.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs
index c607735..b9cac8e 100644
--- a/CakeMail.RestClient.UnitTests/Timezones.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Timezones.cs
@@ -1,29 +1,27 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class TimezonesTests
{
private const string API_KEY = "...dummy API key...";
- [TestMethod]
+ [Fact]
public async Task GetTimezones()
{
// Arrange
- var parameters = new Parameter[]
- {
- // There are no parameters
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"timezones\":[{\"id\":\"152\",\"name\":\"America/Montreal\"},{\"id\":\"532\",\"name\":\"US/Central\"},{\"id\":\"542\",\"name\":\"UTC\"}]}}";
- var mockRestClient = new MockRestClient("/Client/GetTimezones/", parameters, jsonResponse, false);
+
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Client/GetTimezones")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Timezones.GetAllAsync();
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Triggers.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs
similarity index 56%
rename from CakeMail.RestClient.UnitTests/Triggers.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs
index d28131e..a9414b1 100644
--- a/CakeMail.RestClient.UnitTests/Triggers.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Triggers.cs
@@ -1,22 +1,21 @@
using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class TriggersTests
{
private const string API_KEY = "...dummy API key...";
private const string USER_KEY = "...dummy USER key...";
private const long CLIENT_ID = 999;
- [TestMethod]
+ [Fact]
public async Task CreateTrigger_with_minimal_parameters()
{
// Arrange
@@ -24,23 +23,19 @@ public async Task CreateTrigger_with_minimal_parameters()
var triggerId = 123L;
var listId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.CreateAsync(USER_KEY, name, listId);
// Assert
result.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task CreateTrigger_with_campaignid()
{
// Arrange
@@ -49,24 +44,19 @@ public async Task CreateTrigger_with_campaignid()
var listId = 111L;
var campaignId = 222L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.CreateAsync(USER_KEY, name, listId, campaignId: campaignId);
// Assert
result.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task CreateTrigger_with_encoding()
{
// Arrange
@@ -75,24 +65,19 @@ public async Task CreateTrigger_with_encoding()
var listId = 111L;
var encoding = MessageEncoding.Utf8;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.CreateAsync(USER_KEY, name, listId, encoding: encoding);
// Assert
result.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task CreateTrigger_with_transferencoding()
{
// Arrange
@@ -101,24 +86,19 @@ public async Task CreateTrigger_with_transferencoding()
var listId = 111L;
var transferEncoding = TransferEncoding.Base64;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "transfer_encoding", Value = transferEncoding.GetEnumMemberValue() }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.CreateAsync(USER_KEY, name, listId, transferEncoding: transferEncoding);
// Assert
result.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task CreateTrigger_with_clientid()
{
// Arrange
@@ -126,38 +106,30 @@ public async Task CreateTrigger_with_clientid()
var triggerId = 123L;
var listId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name },
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.CreateAsync(USER_KEY, name, listId, clientId: CLIENT_ID);
// Assert
result.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task GetTrigger_with_minimal_parameters()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"action\":\"opt-in\",\"campaign_id\":\"0\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"{0}\",\"list_id\":\"111222333\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/8da92a42e5625ef43112c0ca4237902219935a88319a1349\",\"name\":\"this_is_a_test_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}}}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetAsync(USER_KEY, triggerId);
// Assert
@@ -165,22 +137,18 @@ public async Task GetTrigger_with_minimal_parameters()
result.Id.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task GetTrigger_with_clientid()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"action\":\"opt-in\",\"campaign_id\":\"0\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"{0}\",\"list_id\":\"111222333\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/8da92a42e5625ef43112c0ca4237902219935a88319a1349\",\"name\":\"this_is_a_test_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}}}}", triggerId);
- var mockRestClient = new MockRestClient("/Trigger/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetAsync(USER_KEY, triggerId, CLIENT_ID);
// Assert
@@ -188,542 +156,448 @@ public async Task GetTrigger_with_clientid()
result.Id.ShouldBe(triggerId);
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_campaignid()
{
// Arrange
var triggerId = 123L;
var campaignId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, campaignId: campaignId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_name()
{
// Arrange
var triggerId = 123L;
var name = "My mailing";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "name", Value = name }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, name: name);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_action()
{
// Arrange
var triggerId = 123L;
var action = TriggerAction.OptIn;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = action.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, action: action);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_encoding()
{
// Arrange
var triggerId = 123L;
var encoding = MessageEncoding.Utf8;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "encoding", Value = encoding.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, encoding: encoding);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_transferencoding()
{
// Arrange
var triggerId = 123L;
var transferEncoding = TransferEncoding.Base64;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "transfer_encoding", Value = transferEncoding.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, transferEncoding: transferEncoding);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_subject()
{
// Arrange
var triggerId = 123L;
var subject = "My mailing subject";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "subject", Value = subject }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, subject: subject);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_senderemail()
{
// Arrange
var triggerId = 123L;
var senderEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_email", Value = senderEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, senderEmail: senderEmail);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_sendername()
{
// Arrange
var triggerId = 123L;
var senderName = "Bob Smith";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "sender_name", Value = senderName }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, senderName: senderName);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_replyto()
{
// Arrange
var triggerId = 123L;
var replyTo = "marketing@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "reply_to", Value = replyTo }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, replyTo: replyTo);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_htmlcontent()
{
// Arrange
var triggerId = 123L;
var htmlContent = "Hello world";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "html_message", Value = htmlContent }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, htmlContent: htmlContent);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_textcontent()
{
// Arrange
var triggerId = 123L;
var textContent = "Hello world";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "text_message", Value = textContent }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, textContent: textContent);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackopens_true()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "opening_stats", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackOpens: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackopens_false()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "opening_stats", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackOpens: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackclicksinhtml_true()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_html", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackClicksInHtml: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackclicksinhtml_false()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_html", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackClicksInHtml: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackclicksintext_true()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_text", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackClicksInText: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackclicksintext_false()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "clickthru_text", Value = "false" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackClicksInText: false);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_trackingparameters()
{
// Arrange
var triggerId = 123L;
var trackingParameters = "param1=abc¶m2=123";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "tracking_params", Value = trackingParameters }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, trackingParameters: trackingParameters);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_delay()
{
// Arrange
var triggerId = 123L;
var delay = 60;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "delay", Value = delay }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, delay: delay);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_status()
{
// Arrange
var triggerId = 123L;
var status = TriggerStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, status: status);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_datefield()
{
// Arrange
var triggerId = 123L;
var date = new DateTime(2015, 12, 1, 13, 6, 6);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "date_field", Value = date.ToCakeMailString() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, date: date);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateTrigger_with_clientid()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UpdateAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_minimal_parameters()
{
// Arrange
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY);
// Assert
@@ -733,7 +607,7 @@ public async Task GetTriggers_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_status()
{
// Arrange
@@ -741,16 +615,12 @@ public async Task GetTriggers_with_status()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, status: status);
// Assert
@@ -760,7 +630,7 @@ public async Task GetTriggers_with_status()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_action()
{
// Arrange
@@ -768,16 +638,12 @@ public async Task GetTriggers_with_action()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"222\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_222_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = action.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, action: action);
// Assert
@@ -787,7 +653,7 @@ public async Task GetTriggers_with_action()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_listid()
{
// Arrange
@@ -795,16 +661,12 @@ public async Task GetTriggers_with_listid()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, listId: listId);
// Assert
@@ -814,7 +676,7 @@ public async Task GetTriggers_with_listid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_campaignid()
{
// Arrange
@@ -822,16 +684,12 @@ public async Task GetTriggers_with_campaignid()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, campaignId: campaignId);
// Assert
@@ -841,7 +699,7 @@ public async Task GetTriggers_with_campaignid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_limit()
{
// Arrange
@@ -849,16 +707,12 @@ public async Task GetTriggers_with_limit()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, limit: limit);
// Assert
@@ -868,7 +722,7 @@ public async Task GetTriggers_with_limit()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_offset()
{
// Arrange
@@ -876,16 +730,12 @@ public async Task GetTriggers_with_offset()
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, offset: offset);
// Assert
@@ -895,23 +745,19 @@ public async Task GetTriggers_with_offset()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggers_with_clientid()
{
// Arrange
var jsonTrigger1 = "{\"action\":\"opt-in\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"123\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b99469dc805938e947457d91aa10c4c551\",\"name\":\"list_111_opt_in\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Subscription Confirmed\",\"transfer_encoding\":\"quoted-printable\"}";
var jsonTrigger2 = "{\"action\":\"opt-out\",\"campaign_id\":\"111\",\"delay\":\"0\",\"encoding\":\"utf-8\",\"id\":\"456\",\"list_id\":\"111\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/dff4a336984aa4b9c3ef15863200867f457d91aa10c4c551\",\"name\":\"list_111_opt_out\",\"parent_id\":\"0\",\"send_to\":\"[email]\",\"sender_email\":\"marketing@fictitiouscompany.com\",\"sender_name\":\"Marketing Group\",\"status\":\"active\",\"subject\":\"Unsubscribe Confirmed.\",\"transfer_encoding\":\"quoted-printable\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"triggers\":[{0},{1}]}}}}", jsonTrigger1, jsonTrigger2);
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetTriggersAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -921,221 +767,179 @@ public async Task GetTriggers_with_clientid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_status()
{
// Arrange
var status = TriggerStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY, status: status);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_action()
{
// Arrange
var action = TriggerAction.OptIn;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = action.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY, action: action);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_listid()
{
// Arrange
var listId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "list_id", Value = listId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY, listId: listId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_campaignid()
{
// Arrange
var campaignId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "campaign_id", Value = campaignId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY, campaignId: campaignId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggersCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task SendTriggerTestEmail_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "merged" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.SendTestEmailAsync(USER_KEY, triggerId, recipientEmail);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SendTriggerTestEmail_with_separated_true()
{
// Arrange
var triggerId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "separated" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.SendTestEmailAsync(USER_KEY, triggerId, recipientEmail, separated: true);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task SendTriggerTestEmail_with_clientid()
{
// Arrange
var triggerId = 123L;
var recipientEmail = "bobsmith@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_type", Value = "merged" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "test_email", Value = recipientEmail },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/SendTestEmail/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/SendTestEmail")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.SendTestEmailAsync(USER_KEY, triggerId, recipientEmail, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawEmailMessage_with_minimal_parameters()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetEmailMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetEmailMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawEmailMessageAsync(USER_KEY, triggerId);
// Assert
@@ -1143,22 +947,18 @@ public async Task GetTriggerRawEmailMessage_with_minimal_parameters()
result.Subject.ShouldBe("This is a simple message");
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawEmailMessage_with_clientid()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"subject\":\"This is a simple message\",\"message\":\"...dummy content...\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetEmailMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetEmailMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawEmailMessageAsync(USER_KEY, triggerId, CLIENT_ID);
// Assert
@@ -1166,138 +966,115 @@ public async Task GetTriggerRawEmailMessage_with_clientid()
result.Subject.ShouldBe("This is a simple message");
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawHtml_with_minimal_parameters()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Trigger/GetHtmlMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetHtmlMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawHtmlAsync(USER_KEY, triggerId);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawHtml_with_clientid()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Trigger/GetHtmlMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetHtmlMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawHtmlAsync(USER_KEY, triggerId, CLIENT_ID);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawText_with_minimal_parameters()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Trigger/GetTextMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetTextMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawTextAsync(USER_KEY, triggerId);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerRawText_with_clientid()
{
// Arrange
var triggerId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"...dummy content...\"}";
- var mockRestClient = new MockRestClient("/Trigger/GetTextMessage/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetTextMessage")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetRawTextAsync(USER_KEY, triggerId, CLIENT_ID);
// Assert
result.ShouldBe("...dummy content...");
}
- [TestMethod]
+ [Fact]
public async Task UnleashTrigger_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
var listMemberId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/Unleash/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Unleash")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UnleashAsync(USER_KEY, triggerId, listMemberId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UnleashTrigger_with_clientid()
{
// Arrange
var triggerId = 123L;
var listMemberId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/Trigger/Unleash/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/Unleash")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.UnleashAsync(USER_KEY, triggerId, listMemberId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_minimal_parameters()
{
// Arrange
@@ -1306,18 +1083,12 @@ public async Task GetTriggerLogs_with_minimal_parameters()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId);
// Assert
@@ -1325,7 +1096,7 @@ public async Task GetTriggerLogs_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_logtype()
{
// Arrange
@@ -1334,19 +1105,12 @@ public async Task GetTriggerLogs_with_logtype()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, logType: logType);
// Assert
@@ -1354,7 +1118,7 @@ public async Task GetTriggerLogs_with_logtype()
result.Count().ShouldBe(1);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_listmemberid()
{
// Arrange
@@ -1363,19 +1127,12 @@ public async Task GetTriggerLogs_with_listmemberid()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0}]}}}}", sentLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, listMemberId: listMemberId);
// Assert
@@ -1383,7 +1140,7 @@ public async Task GetTriggerLogs_with_listmemberid()
result.Count().ShouldBe(1);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_startdate()
{
// Arrange
@@ -1393,19 +1150,12 @@ public async Task GetTriggerLogs_with_startdate()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, start: start);
// Assert
@@ -1413,7 +1163,7 @@ public async Task GetTriggerLogs_with_startdate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_enddate()
{
// Arrange
@@ -1423,19 +1173,12 @@ public async Task GetTriggerLogs_with_enddate()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: false, totals: false, end: end);
// Assert
@@ -1443,7 +1186,7 @@ public async Task GetTriggerLogs_with_enddate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_limit()
{
// Arrange
@@ -1453,19 +1196,12 @@ public async Task GetTriggerLogs_with_limit()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: false, totals: false, limit: limit);
// Assert
@@ -1473,7 +1209,7 @@ public async Task GetTriggerLogs_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_offset()
{
// Arrange
@@ -1483,19 +1219,12 @@ public async Task GetTriggerLogs_with_offset()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: false, totals: false, offset: offset);
// Assert
@@ -1503,7 +1232,7 @@ public async Task GetTriggerLogs_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_clientid()
{
// Arrange
@@ -1512,19 +1241,12 @@ public async Task GetTriggerLogs_with_clientid()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: false, totals: false, clientId: CLIENT_ID);
// Assert
@@ -1532,7 +1254,7 @@ public async Task GetTriggerLogs_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_uniques_true()
{
// Arrange
@@ -1541,18 +1263,12 @@ public async Task GetTriggerLogs_with_uniques_true()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: true, totals: false);
// Assert
@@ -1560,7 +1276,7 @@ public async Task GetTriggerLogs_with_uniques_true()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogs_with_totals_true()
{
// Arrange
@@ -1569,18 +1285,12 @@ public async Task GetTriggerLogs_with_totals_true()
var sentLog = "{\"id\":\"1\",\"record_id\":\"1\",\"email\":\"aaa@aaa.com\",\"action\":\"in_queue\",\"total\":\"1\",\"time\":\"2015-03-18 15:27:01\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":null,\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403e139cc9ce93542dea11dc1da82aac3298\",\"l_registered\":\"2015-03-18 15:23:31\"}";
var hardbounceLog = "{\"id\":\"312\",\"record_id\":\"11\",\"email\":\"aaa@aaa.com\",\"action\":\"bounce_hb\",\"total\":\"1\",\"time\":\"2015-03-18 15:29:36\",\"user_agent\":null,\"ip\":null,\"host\":null,\"extra\":\"{dsn} smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found\",\"show_email_link\":\"http://link.fictitiouscompany.com/v/443/f6f02aba584b403ec23295741ba72edcbcfd4b9079f78d8d\",\"l_registered\":\"2015-03-18 15:24:37\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"logs\":[{0},{1}]}}}}", sentLog, hardbounceLog);
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsAsync(USER_KEY, triggerId, uniques: false, totals: true);
// Assert
@@ -1588,24 +1298,18 @@ public async Task GetTriggerLogs_with_totals_true()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId);
// Assert
@@ -1613,26 +1317,19 @@ public async Task GetTriggerLogsCount_with_minimal_parameters()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_logtype()
{
// Arrange
var triggerId = 123L;
var logType = LogType.Sent;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "action", Value = logType.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, logType: logType);
// Assert
@@ -1640,26 +1337,19 @@ public async Task GetTriggerLogsCount_with_logtype()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_listmemberid()
{
// Arrange
var triggerId = 123L;
var listMemberId = 111L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "record_id", Value = listMemberId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, listMemberId: listMemberId);
// Assert
@@ -1667,24 +1357,18 @@ public async Task GetTriggerLogsCount_with_listmemberid()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_uniques_true()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, uniques: true);
// Assert
@@ -1692,24 +1376,18 @@ public async Task GetTriggerLogsCount_with_uniques_true()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_totals_true()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "true" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, totals: true);
// Assert
@@ -1717,26 +1395,19 @@ public async Task GetTriggerLogsCount_with_totals_true()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_startdate()
{
// Arrange
var triggerId = 123L;
var start = new DateTime(2015, 1, 1, 0, 0, 0);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, start: start);
// Assert
@@ -1744,26 +1415,19 @@ public async Task GetTriggerLogsCount_with_startdate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_enddate()
{
// Arrange
var triggerId = 123L;
var end = new DateTime(2015, 12, 31, 23, 59, 59);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, end: end);
// Assert
@@ -1771,25 +1435,18 @@ public async Task GetTriggerLogsCount_with_enddate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLogsCount_with_clientid()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "uniques", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "totals", Value = "false" },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLogsCountAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
@@ -1797,7 +1454,7 @@ public async Task GetTriggerLogsCount_with_clientid()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinks_with_minimal_parameters()
{
// Arrange
@@ -1806,16 +1463,12 @@ public async Task GetTriggerLinks_with_minimal_parameters()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksAsync(USER_KEY, triggerId);
// Assert
@@ -1823,7 +1476,7 @@ public async Task GetTriggerLinks_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinks_with_limit()
{
// Arrange
@@ -1833,17 +1486,12 @@ public async Task GetTriggerLinks_with_limit()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksAsync(USER_KEY, triggerId, limit: limit);
// Assert
@@ -1851,7 +1499,7 @@ public async Task GetTriggerLinks_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinks_with_offset()
{
// Arrange
@@ -1861,17 +1509,12 @@ public async Task GetTriggerLinks_with_offset()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksAsync(USER_KEY, triggerId, offset: offset);
// Assert
@@ -1879,7 +1522,7 @@ public async Task GetTriggerLinks_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinks_with_clientid()
{
// Arrange
@@ -1888,17 +1531,12 @@ public async Task GetTriggerLinks_with_clientid()
var jsonLink1 = "{\"id\":\"2002673788\",\"status\":\"active\",\"link_to\":\"http://fictitiouscompany.com/hello_world.aspx\"}";
var jsonLink2 = "{\"id\":\"2002673787\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonLink1, jsonLink2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
@@ -1906,66 +1544,54 @@ public async Task GetTriggerLinks_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksCount_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksCountAsync(USER_KEY, triggerId);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksCount_with_clientid()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinks/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinks")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksCountAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLink_with_minimal_parameters()
{
// Arrange
var linkId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "link_id", Value = linkId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId);
- var mockRestClient = new MockRestClient("/Trigger/GetLinkInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinkInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinkAsync(USER_KEY, linkId);
// Assert
@@ -1973,22 +1599,18 @@ public async Task GetTriggerLink_with_minimal_parameters()
result.Id.ShouldBe(linkId);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLink_with_clientid()
{
// Arrange
var linkId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "link_id", Value = linkId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"status\":\"active\",\"link_to\":\"http://www.fictitiouscompany.com.com/\"}}}}", linkId);
- var mockRestClient = new MockRestClient("/Trigger/GetLinkInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinkInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinkAsync(USER_KEY, linkId, CLIENT_ID);
// Assert
@@ -1996,7 +1618,7 @@ public async Task GetTriggerLink_with_clientid()
result.Id.ShouldBe(linkId);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_minimal_parameters()
{
// Arrange
@@ -2005,16 +1627,12 @@ public async Task GetTriggerLinksWithStats_with_minimal_parameters()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId);
// Assert
@@ -2022,7 +1640,7 @@ public async Task GetTriggerLinksWithStats_with_minimal_parameters()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_startdate()
{
// Arrange
@@ -2032,17 +1650,12 @@ public async Task GetTriggerLinksWithStats_with_startdate()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId, start: start);
// Assert
@@ -2050,7 +1663,7 @@ public async Task GetTriggerLinksWithStats_with_startdate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_enddate()
{
// Arrange
@@ -2060,17 +1673,12 @@ public async Task GetTriggerLinksWithStats_with_enddate()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId, end: end);
// Assert
@@ -2078,7 +1686,7 @@ public async Task GetTriggerLinksWithStats_with_enddate()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_limit()
{
// Arrange
@@ -2088,17 +1696,12 @@ public async Task GetTriggerLinksWithStats_with_limit()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId, limit: limit);
// Assert
@@ -2106,7 +1709,7 @@ public async Task GetTriggerLinksWithStats_with_limit()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_offset()
{
// Arrange
@@ -2116,17 +1719,12 @@ public async Task GetTriggerLinksWithStats_with_offset()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId, offset: offset);
// Assert
@@ -2134,7 +1732,7 @@ public async Task GetTriggerLinksWithStats_with_offset()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStats_with_clientid()
{
// Arrange
@@ -2143,17 +1741,12 @@ public async Task GetTriggerLinksWithStats_with_clientid()
var jsonClickLog1 = "{\"id\":\"1111\",\"link_to\":\"http://www.fictitiouscompany.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
var jsonClickLog2 = "{\"id\":\"2222\",\"link_to\":\"http://www.cakemail.com\",\"unique\":\"1\",\"total\":\"5\",\"unique_rate\":\"1\",\"total_rate\":\"1\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"links\":[{0},{1}]}}}}", jsonClickLog1, jsonClickLog2);
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
@@ -2161,22 +1754,18 @@ public async Task GetTriggerLinksWithStats_with_clientid()
result.Count().ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStatsCount_with_minimal_parameters()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsCountAsync(USER_KEY, triggerId);
// Assert
@@ -2184,24 +1773,19 @@ public async Task GetTriggerLinksWithStatsCount_with_minimal_parameters()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStatsCount_with_startdate()
{
// Arrange
var triggerId = 123L;
var start = new DateTime(2015, 1, 1, 0, 0, 0);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "start_time", Value = start.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsCountAsync(USER_KEY, triggerId, start: start);
// Assert
@@ -2209,24 +1793,19 @@ public async Task GetTriggerLinksWithStatsCount_with_startdate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStatsCount_with_enddate()
{
// Arrange
var triggerId = 123L;
var end = new DateTime(2015, 12, 31, 23, 59, 59);
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "end_time", Value = end.ToCakeMailString() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsCountAsync(USER_KEY, triggerId, end: end);
// Assert
@@ -2234,23 +1813,18 @@ public async Task GetTriggerLinksWithStatsCount_with_enddate()
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetTriggerLinksWithStatsCount_with_clientid()
{
// Arrange
var triggerId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "trigger_id", Value = triggerId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/Trigger/GetLinksLog/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("Trigger/GetLinksLog")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Triggers.GetLinksWithStatsCountAsync(USER_KEY, triggerId, clientId: CLIENT_ID);
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Users.cs b/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs
similarity index 52%
rename from CakeMail.RestClient.UnitTests/Users.cs
rename to Source/CakeMail.RestClient.UnitTests/Resources/Users.cs
index e921773..48ac210 100644
--- a/CakeMail.RestClient.UnitTests/Users.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Resources/Users.cs
@@ -1,47 +1,39 @@
using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using RestSharp;
+using RichardSzalay.MockHttp;
using Shouldly;
using System.Linq;
+using System.Net.Http;
using System.Threading.Tasks;
+using Xunit;
-namespace CakeMail.RestClient.UnitTests
+namespace CakeMail.RestClient.UnitTests.Resources
{
- [TestClass]
public class UsersTests
{
private const string API_KEY = "...dummy API key...";
private const string USER_KEY = "...dummy USER key...";
private const long CLIENT_ID = 999;
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_minimal_parameters()
{
// Arrange
var userId = 123L;
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
- var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":\"{0}\"}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
-
- // Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\"}}}}", userId);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
+
+ // Act
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_firstname()
{
// Arrange
@@ -49,27 +41,19 @@ public async Task CreateUser_with_firstname()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var firstName = "Bob";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "first_name", Value = firstName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, firstName: firstName);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_lastname()
{
// Arrange
@@ -77,27 +61,19 @@ public async Task CreateUser_with_lastname()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var lastName = "Smith";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "last_name", Value = lastName },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, lastName: lastName);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_title()
{
// Arrange
@@ -105,27 +81,19 @@ public async Task CreateUser_with_title()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var title = "Marketing Director";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "title", Value = title },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, title: title);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_officephone()
{
// Arrange
@@ -133,27 +101,19 @@ public async Task CreateUser_with_officephone()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var officePhone = "555-555-1212";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "office_phone", Value = officePhone },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, officePhone: officePhone);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_mobilephone()
{
// Arrange
@@ -161,27 +121,19 @@ public async Task CreateUser_with_mobilephone()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var mobilePhone = "555-111-2222";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "mobile_phone", Value = mobilePhone },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, mobilePhone: mobilePhone);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_language()
{
// Arrange
@@ -189,27 +141,19 @@ public async Task CreateUser_with_language()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var language = "en-US";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "language", Value = language },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, language: language);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_timezoneid()
{
// Arrange
@@ -217,107 +161,82 @@ public async Task CreateUser_with_timezoneid()
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, timezoneId: timezoneId);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task CreateUser_with_clientid()
{
// Arrange
var userId = 123L;
var email = "bob@fictitiouscompany.com";
var password = "MyPassword";
- var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"id\":\"{0}\",\"key\":\"...user key...\"}}}}", userId);
- var mockRestClient = new MockRestClient("/User/Create/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Create")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.CreateAsync(USER_KEY, email, password, clientId: CLIENT_ID);
// Assert
result.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task DeactivateUser_with_minimal_parameters()
{
// Arrange
var userId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = "suspended" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.DeactivateAsync(USER_KEY, userId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task DeleteUser_with_minimal_parameters()
{
// Arrange
var userId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = "deleted" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.DeleteAsync(USER_KEY, userId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task GetUser_with_minimal_parameters()
{
// Arrange
var userId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"{0}\",\"user_key\":\"{1}\",\"email\":\"admin@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Smith\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}}}}", userId, USER_KEY);
- var mockRestClient = new MockRestClient("/User/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetAsync(USER_KEY, userId);
// Assert
@@ -325,21 +244,17 @@ public async Task GetUser_with_minimal_parameters()
result.Id.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task GetUser_with_clientid()
{
// Arrange
var userId = 12345L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"{0}\",\"user_key\":\"{1}\",\"email\":\"admin@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Smith\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}}}}", userId, USER_KEY);
- var mockRestClient = new MockRestClient("/User/GetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetAsync(USER_KEY, userId, CLIENT_ID);
// Assert
@@ -347,21 +262,18 @@ public async Task GetUser_with_clientid()
result.Id.ShouldBe(userId);
}
- [TestMethod]
+ [Fact]
public async Task GetUsers_with_minimal_parameters()
{
// Arrange
var jsonUser1 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"123\",\"user_key\":\"... user key #1...\",\"email\":\"admin1@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
var jsonUser2 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"456\",\"user_key\":\"... user key #2...\",\"email\":\"admin2@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"Jane\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2);
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetUsersAsync(USER_KEY);
// Assert
@@ -371,23 +283,19 @@ public async Task GetUsers_with_minimal_parameters()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetUsers_with_status()
{
// Arrange
var status = UserStatus.Active;
var jsonUser1 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"123\",\"user_key\":\"... user key #1...\",\"email\":\"admin1@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
var jsonUser2 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"456\",\"user_key\":\"... user key #2...\",\"email\":\"admin2@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"Jane\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2);
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetUsersAsync(USER_KEY, status: status);
// Assert
@@ -397,23 +305,19 @@ public async Task GetUsers_with_status()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetUsers_with_limit()
{
// Arrange
var limit = 5;
var jsonUser1 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"123\",\"user_key\":\"... user key #1...\",\"email\":\"admin1@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
var jsonUser2 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"456\",\"user_key\":\"... user key #2...\",\"email\":\"admin2@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"Jane\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "limit", Value = limit },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2);
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetUsersAsync(USER_KEY, limit: limit);
// Assert
@@ -423,23 +327,19 @@ public async Task GetUsers_with_limit()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetUsers_with_offset()
{
// Arrange
var offset = 25;
var jsonUser1 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"123\",\"user_key\":\"... user key #1...\",\"email\":\"admin1@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
var jsonUser2 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"456\",\"user_key\":\"... user key #2...\",\"email\":\"admin2@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"Jane\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "offset", Value = offset },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2);
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetUsersAsync(USER_KEY, offset: offset);
// Assert
@@ -449,22 +349,18 @@ public async Task GetUsers_with_offset()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetUsers_with_clientid()
{
// Arrange
var jsonUser1 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"123\",\"user_key\":\"... user key #1...\",\"email\":\"admin1@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"John\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
var jsonUser2 = "{\"permissions\":[\"admin_settings\",\"admin_marketplace\",\"admin_campaigns\",\"admin_lists\"],\"id\":\"456\",\"user_key\":\"... user key #2...\",\"email\":\"admin2@fictitiouscompany.com\",\"status\":\"active\",\"first_name\":\"Jane\",\"last_name\":\"Doe\",\"openid\":null,\"last_activity\":\"2015-04-15 19:05:46\",\"timezone_id\":\"542\"}";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "false" }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"users\":[{0},{1}]}}}}", jsonUser1, jsonUser2);
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetUsersAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
@@ -474,344 +370,281 @@ public async Task GetUsers_with_clientid()
result.ToArray()[1].Id.ShouldBe(456);
}
- [TestMethod]
+ [Fact]
public async Task GetUsersCount_with_minimal_parameters()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetCountAsync(USER_KEY);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetUsersCount_with_status()
{
// Arrange
var status = UserStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetCountAsync(USER_KEY, status: status);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task GetUsersCount_with_clientid()
{
// Arrange
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID },
- new Parameter { Type = ParameterType.GetOrPost, Name = "count", Value = "true" }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":{\"count\":\"2\"}}";
- var mockRestClient = new MockRestClient("/User/GetList/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/GetList")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.GetCountAsync(USER_KEY, clientId: CLIENT_ID);
// Assert
result.ShouldBe(2);
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_minimal_parameters()
{
// Arrange
var userId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_email()
{
// Arrange
var userId = 123L;
var email = "bob@fictitiouscompany.com";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, email: email);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_password()
{
// Arrange
var userId = 123L;
var password = "AbCdEfGhIjKlMnOpQrStUvWxYz";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password_confirmation", Value = password }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, password: password);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_firstname()
{
// Arrange
var userId = 123L;
var firstName = "Bob";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "first_name", Value = firstName }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, firstName: firstName);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_lastname()
{
// Arrange
var userId = 123L;
var lastName = "Smith";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "last_name", Value = lastName }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, lastName: lastName);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_title()
{
// Arrange
var userId = 123L;
var title = "Marketing Director";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "title", Value = title }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, title: title);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_officephone()
{
// Arrange
var userId = 123L;
var officePhone = "555-555-1212";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "office_phone", Value = officePhone }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, officePhone: officePhone);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_mobilephone()
{
// Arrange
var userId = 123L;
var mobilePhone = "555-111-2222";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "mobile_phone", Value = mobilePhone }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, mobilePhone: mobilePhone);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_language()
{
// Arrange
var userId = 123L;
var language = "en-US";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "language", Value = language }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, language: language);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_timezoneid()
{
// Arrange
var userId = 123L;
var timezoneId = 542L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "timezone_id", Value = timezoneId }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, timezoneId: timezoneId);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_status()
{
// Arrange
var userId = 123L;
var status = UserStatus.Active;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "status", Value = status.GetEnumMemberValue() }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, status: status);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task UpdateUser_with_clientid()
{
// Arrange
var userId = 123L;
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "user_id", Value = userId },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = "{\"status\":\"success\",\"data\":\"true\"}";
- var mockRestClient = new MockRestClient("/User/SetInfo/", parameters, jsonResponse);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/SetInfo")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.UpdateAsync(USER_KEY, userId, clientId: CLIENT_ID);
// Assert
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public async Task Login_with_minimal_parameters()
{
// Arrange
var email = "admin@fictitiouscompany.com";
var password = "abc123";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"client_id\":\"12345\",\"client_key\":\"... client key ...\",\"user_id\":\"111\",\"user_key\":\"{0}\",\"first_name\":\"Bob\",\"last_name\":\"Smith\",\"language\":\"en_US\",\"timezone\":\"UTC\",\"last_activity\":\"2015-04-15 18:53:32\",\"client_lineage\":\"1-12345\"}}}}", USER_KEY);
- var mockRestClient = new MockRestClient("/User/Login/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Login")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.LoginAsync(email, password);
// Assert
@@ -819,23 +652,18 @@ public async Task Login_with_minimal_parameters()
result.UserKey.ShouldBe(USER_KEY);
}
- [TestMethod]
+ [Fact]
public async Task Login_with_clientid()
{
// Arrange
var email = "admin@fictitiouscompany.com";
var password = "abc123";
- var parameters = new[]
- {
- new Parameter { Type = ParameterType.GetOrPost, Name = "email", Value = email },
- new Parameter { Type = ParameterType.GetOrPost, Name = "password", Value = password },
- new Parameter { Type = ParameterType.GetOrPost, Name = "client_id", Value = CLIENT_ID }
- };
var jsonResponse = string.Format("{{\"status\":\"success\",\"data\":{{\"client_id\":\"12345\",\"client_key\":\"... client key ...\",\"user_id\":\"111\",\"user_key\":\"{0}\",\"first_name\":\"Bob\",\"last_name\":\"Smith\",\"language\":\"en_US\",\"timezone\":\"UTC\",\"last_activity\":\"2015-04-15 18:53:32\",\"client_lineage\":\"1-12345\"}}}}", USER_KEY);
- var mockRestClient = new MockRestClient("/User/Login/", parameters, jsonResponse, false);
+ var mockHttp = new MockHttpMessageHandler();
+ mockHttp.Expect(HttpMethod.Post, Utils.GetCakeMailApiUri("User/Login")).Respond("application/json", jsonResponse);
// Act
- var apiClient = new CakeMailRestClient(API_KEY, mockRestClient.Object);
+ var apiClient = new CakeMailRestClient(API_KEY, httpClient: mockHttp.ToHttpClient());
var result = await apiClient.Users.LoginAsync(email, password, clientId: CLIENT_ID);
// Assert
diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs
similarity index 89%
rename from CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs
rename to Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs
index 682398d..6783925 100644
--- a/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailDateTimeConverter.cs
@@ -1,17 +1,16 @@
using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Shouldly;
using System;
using System.IO;
using System.Text;
+using Xunit;
namespace CakeMail.RestClient.UnitTests.Utilities
{
- [TestClass]
public class CakeMailDateTimeConverterTests
{
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_json()
{
// Arrange
@@ -33,7 +32,7 @@ public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_json()
result.Second.ShouldBe(0);
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_empty_date()
{
// Arrange
@@ -50,7 +49,7 @@ public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_empty_date()
result.ShouldBe(DateTime.MinValue);
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_null_date()
{
// Arrange
@@ -67,8 +66,7 @@ public void CakeMailDateTimeConverter_ReadJson_Successfully_parses_null_date()
result.ShouldBeNull();
}
- [TestMethod]
- [ExpectedException(typeof(Exception))]
+ [Fact]
public void CakeMailDateTimeConverter_ReadJson_Throws_exception_when_content_is_not_a_string()
{
// Arrange
@@ -79,10 +77,13 @@ public void CakeMailDateTimeConverter_ReadJson_Throws_exception_when_content_is_
reader.Read();
// Act
- var result = (DateTime)converter.ReadJson(reader, typeof(DateTime), null, null);
+ Should.Throw(() =>
+ {
+ var result = (DateTime)converter.ReadJson(reader, typeof(DateTime), null, null);
+ });
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_CanConvert_datetime()
{
// Arrange
@@ -97,7 +98,7 @@ public void CakeMailDateTimeConverter_CanConvert_datetime()
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_CanConvert_nullable_datetime()
{
// Arrange
@@ -112,7 +113,7 @@ public void CakeMailDateTimeConverter_CanConvert_nullable_datetime()
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_CanConvert_returns_false()
{
// Arrange
@@ -127,7 +128,7 @@ public void CakeMailDateTimeConverter_CanConvert_returns_false()
result.ShouldBeFalse();
}
- [TestMethod]
+ [Fact]
public void CakeMailDateTimeConverter_WriteJson_Successfully_writes_datetime()
{
// Arrange
@@ -150,8 +151,7 @@ public void CakeMailDateTimeConverter_WriteJson_Successfully_writes_datetime()
}
}
- [TestMethod]
- [ExpectedException(typeof(Exception))]
+ [Fact]
public void CakeMailDateTimeConverter_WriteJson_Throws_exception_when_content_is_not_boolean()
{
// Arrange
@@ -165,7 +165,7 @@ public void CakeMailDateTimeConverter_WriteJson_Throws_exception_when_content_is
using (var jsonWriter = new JsonTextWriter(sw))
{
// Act
- converter.WriteJson(jsonWriter, value, null);
+ Should.Throw(() => converter.WriteJson(jsonWriter, value, null));
// Assert
// Nothing to assert, since 'WriteJson' will throw an exception
diff --git a/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs
similarity index 89%
rename from CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs
rename to Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs
index b05d3b4..33460e3 100644
--- a/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Utilities/CakeMailIntegerBooleanConverter.cs
@@ -1,17 +1,16 @@
using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Shouldly;
using System;
using System.IO;
using System.Text;
+using Xunit;
namespace CakeMail.RestClient.UnitTests.Utilities
{
- [TestClass]
public class CakeMailIntegerBooleanConverterTests
{
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_ReadJson_Successfully_parses_value_representing_true()
{
// Arrange
@@ -28,7 +27,7 @@ public void CakeMailIntegerBooleanConverter_ReadJson_Successfully_parses_value_r
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_ReadJson_Successfully_parses_value_representing_false()
{
// Arrange
@@ -45,8 +44,7 @@ public void CakeMailIntegerBooleanConverter_ReadJson_Successfully_parses_value_r
result.ShouldBeFalse();
}
- [TestMethod]
- [ExpectedException(typeof(Exception))]
+ [Fact]
public void CakeMailIntegerBooleanConverter_ReadJson_Throws_exception_when_content_is_not_a_string()
{
// Arrange
@@ -57,10 +55,13 @@ public void CakeMailIntegerBooleanConverter_ReadJson_Throws_exception_when_conte
reader.Read();
// Act
- var result = (bool)converter.ReadJson(reader, typeof(DateTime), null, null);
+ Should.Throw(() =>
+ {
+ var result = (bool)converter.ReadJson(reader, typeof(DateTime), null, null);
+ });
}
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_CanConvert_returns_true()
{
// Arrange
@@ -75,7 +76,7 @@ public void CakeMailIntegerBooleanConverter_CanConvert_returns_true()
result.ShouldBeTrue();
}
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_CanConvert_returns_false()
{
// Arrange
@@ -90,7 +91,7 @@ public void CakeMailIntegerBooleanConverter_CanConvert_returns_false()
result.ShouldBeFalse();
}
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_WriteJson_Successfully_writes_value_representing_true()
{
// Arrange
@@ -113,7 +114,7 @@ public void CakeMailIntegerBooleanConverter_WriteJson_Successfully_writes_value_
}
}
- [TestMethod]
+ [Fact]
public void CakeMailIntegerBooleanConverter_WriteJson_Successfully_writes_value_representing_false()
{
// Arrange
@@ -136,8 +137,7 @@ public void CakeMailIntegerBooleanConverter_WriteJson_Successfully_writes_value_
}
}
- [TestMethod]
- [ExpectedException(typeof(Exception))]
+ [Fact]
public void CakeMailIntegerBooleanConverter_WriteJson_Throws_exception_when_content_is_not_boolean()
{
// Arrange
@@ -151,7 +151,7 @@ public void CakeMailIntegerBooleanConverter_WriteJson_Throws_exception_when_cont
using (var jsonWriter = new JsonTextWriter(sw))
{
// Act
- converter.WriteJson(jsonWriter, value, null);
+ Should.Throw(() => converter.WriteJson(jsonWriter, value, null));
// Assert
// Nothing to assert, since 'WriteJson' will throw an exception
diff --git a/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs b/Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs
similarity index 82%
rename from CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs
rename to Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs
index dabe442..8c078b0 100644
--- a/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs
+++ b/Source/CakeMail.RestClient.UnitTests/Utilities/ExtensionMethods.cs
@@ -1,12 +1,11 @@
using CakeMail.RestClient.Utilities;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
using System.Runtime.Serialization;
+using Xunit;
namespace CakeMail.RestClient.UnitTests.Utilities
{
- [TestClass]
public class ExtensionMethodsTests
{
private enum UnitTestingEnum
@@ -16,7 +15,7 @@ private enum UnitTestingEnum
BBB
}
- [TestMethod]
+ [Fact]
public void ToCakeMailString_handles_DateTime_MinValue()
{
// Arrange
@@ -29,7 +28,7 @@ public void ToCakeMailString_handles_DateTime_MinValue()
result.ShouldBe(Constants.EMPTY_CAKEMAIL_DATE);
}
- [TestMethod]
+ [Fact]
public void ToCakeMailString_handles_DateTime()
{
// Arrange
@@ -42,7 +41,7 @@ public void ToCakeMailString_handles_DateTime()
result.ShouldBe("2015-03-20 17:41:59");
}
- [TestMethod]
+ [Fact]
public void GetEnumMemberValue_handles_zero_attributes()
{
// Arrange
@@ -52,10 +51,10 @@ public void GetEnumMemberValue_handles_zero_attributes()
var result = value.GetEnumMemberValue();
// Assert
- result.ShouldBe(String.Empty);
+ result.ShouldBe("AAA");
}
- [TestMethod]
+ [Fact]
public void GetEnumMemberValue_handles_attribute()
{
// Arrange
@@ -68,21 +67,23 @@ public void GetEnumMemberValue_handles_attribute()
result.ShouldBe("BBB");
}
- [TestMethod]
- [ExpectedException(typeof(NotSupportedException))]
+ [Fact]
public void GetValueFromEnumMember_thows_exception_when_invalid_type()
{
// Arrange
var enumMember = "BBB";
// Act
- var result = enumMember.GetValueFromEnumMember();
+ Should.Throw(() =>
+ {
+ var result = enumMember.GetValueFromEnumMember();
+ });
// Assert
// Nothing to assert, an exception will be thrown
}
- [TestMethod]
+ [Fact]
public void GetValueFromEnumMember_handles_value_matching_attribute()
{
// Arrange
@@ -95,7 +96,7 @@ public void GetValueFromEnumMember_handles_value_matching_attribute()
result.ShouldBe(UnitTestingEnum.BBB);
}
- [TestMethod]
+ [Fact]
public void GetValueFromEnumMember_handles_value_matching_enum_name()
{
// Arrange
@@ -108,15 +109,17 @@ public void GetValueFromEnumMember_handles_value_matching_enum_name()
result.ShouldBe(UnitTestingEnum.AAA);
}
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
+ [Fact]
public void GetValueFromEnumMember_thows_exception_when_no_match()
{
// Arrange
var enumMember = "CCC";
// Act
- var result = enumMember.GetValueFromEnumMember();
+ Should.Throw(() =>
+ {
+ var result = enumMember.GetValueFromEnumMember();
+ });
// Assert
// Nothing to assert, an exception will be thrown
diff --git a/Source/CakeMail.RestClient.UnitTests/Utils.cs b/Source/CakeMail.RestClient.UnitTests/Utils.cs
new file mode 100644
index 0000000..edefbb7
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/Utils.cs
@@ -0,0 +1,14 @@
+using System.Linq;
+
+namespace CakeMail.RestClient.UnitTests
+{
+ public static class Utils
+ {
+ private const string CAKEMAIL_API_BASE_URI = "https://api.wbsrvc.com";
+
+ public static string GetCakeMailApiUri(params object[] resources)
+ {
+ return resources.Aggregate(CAKEMAIL_API_BASE_URI, (current, path) => $"{current.TrimEnd('/')}/{path.ToString().TrimStart('/')}");
+ }
+ }
+}
diff --git a/Source/CakeMail.RestClient.UnitTests/project.json b/Source/CakeMail.RestClient.UnitTests/project.json
new file mode 100644
index 0000000..d6da276
--- /dev/null
+++ b/Source/CakeMail.RestClient.UnitTests/project.json
@@ -0,0 +1,46 @@
+{
+ "version": "1.0.0-*",
+ "testRunner": "xunit",
+
+ "buildOptions": {
+ "platform": "anycpu"
+ },
+
+ "dependencies": {
+ "CakeMail.RestClient": { "target": "project" },
+ "xunit": "2.2.0-beta5-build3474",
+ "dotnet-test-xunit": "2.2.0-preview2-build1029",
+ "Moq": "4.6.38-alpha",
+ "Shouldly": "2.8.2",
+ "RichardSzalay.MockHttp": "1.4.1"
+ },
+
+ "frameworks": {
+ "netcoreapp1.0": {
+ "buildOptions": {
+ "define": [ "NETCORE" ]
+ },
+ "imports": [
+ "dnxcore50"
+ ],
+ "dependencies": {
+ "Microsoft.NETCore.App": {
+ "type": "platform",
+ "version": "1.1.0"
+ }
+ }
+ },
+ "net452": {
+ "buildOptions": {
+ "define": [ "NETFULL" ]
+ },
+ "dependencies": {
+ },
+ "frameworkAssemblies": {
+ "System.Runtime": {
+ "type": "build"
+ }
+ }
+ }
+ }
+}
diff --git a/Source/CakeMail.RestClient.ruleset b/Source/CakeMail.RestClient.ruleset
new file mode 100644
index 0000000..1541117
--- /dev/null
+++ b/Source/CakeMail.RestClient.ruleset
@@ -0,0 +1,79 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Source/CakeMail.RestClient.sln b/Source/CakeMail.RestClient.sln
new file mode 100644
index 0000000..e8bba72
--- /dev/null
+++ b/Source/CakeMail.RestClient.sln
@@ -0,0 +1,51 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{16A48337-42CC-443A-B850-775D196B31E0}"
+ ProjectSection(SolutionItems) = preProject
+ ..\build.cake = ..\build.cake
+ ..\nuspec\CakeMail.RestClient.nuspec = ..\nuspec\CakeMail.RestClient.nuspec
+ LICENSE = LICENSE
+ README.md = README.md
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{F7E19221-12B8-4C6E-B87A-167A1E95EBA1}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CakeMail.RestClient", "CakeMail.RestClient\CakeMail.RestClient.xproj", "{DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CakeMail.RestClient.IntegrationTests", "CakeMail.RestClient.IntegrationTests\CakeMail.RestClient.IntegrationTests.xproj", "{B19E7E01-717A-4D0E-B3BC-6D6F26A457A8}"
+EndProject
+Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CakeMail.RestClient.UnitTests", "CakeMail.RestClient.UnitTests\CakeMail.RestClient.UnitTests.xproj", "{964D6BC3-6DAA-4878-BBAE-839AE9942BAF}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8}.Release|Any CPU.Build.0 = Release|Any CPU
+ {964D6BC3-6DAA-4878-BBAE-839AE9942BAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {964D6BC3-6DAA-4878-BBAE-839AE9942BAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {964D6BC3-6DAA-4878-BBAE-839AE9942BAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {964D6BC3-6DAA-4878-BBAE-839AE9942BAF}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {DBEFB5D8-8E24-4152-8EFD-EF153FC3A753} = {F7E19221-12B8-4C6E-B87A-167A1E95EBA1}
+ {B19E7E01-717A-4D0E-B3BC-6D6F26A457A8} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}
+ {964D6BC3-6DAA-4878-BBAE-839AE9942BAF} = {9D4FE070-9A1E-4746-BD77-5D81D7FF21FF}
+ EndGlobalSection
+EndGlobal
diff --git a/Source/CakeMail.RestClient/CakeMail.RestClient.xproj b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj
new file mode 100644
index 0000000..7907143
--- /dev/null
+++ b/Source/CakeMail.RestClient/CakeMail.RestClient.xproj
@@ -0,0 +1,19 @@
+
+
+
+ 14.0
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
+
+
+
+ dbefb5d8-8e24-4152-8efd-ef153fc3a753
+ CakeMail.RestClient
+ .\obj
+ .\bin\
+ v4.5.2
+
+
+ 2.0
+
+
+
\ No newline at end of file
diff --git a/Source/CakeMail.RestClient/CakeMailRestClient.cs b/Source/CakeMail.RestClient/CakeMailRestClient.cs
new file mode 100644
index 0000000..5aedf0b
--- /dev/null
+++ b/Source/CakeMail.RestClient/CakeMailRestClient.cs
@@ -0,0 +1,251 @@
+using CakeMail.RestClient.Resources;
+using CakeMail.RestClient.Utilities;
+using Pathoschild.Http.Client;
+using Pathoschild.Http.Client.Extensibility;
+using System;
+using System.Net;
+using System.Net.Http;
+using System.Reflection;
+
+namespace CakeMail.RestClient
+{
+ ///
+ /// Core class for using the CakeMail Api
+ ///
+ public class CakeMailRestClient : ICakeMailRestClient
+ {
+ #region FIELDS
+
+ private const string DEFAULT_HOST = "api.wbsrvc.com";
+
+ private readonly bool _mustDisposeHttpClient;
+
+ private HttpClient _httpClient;
+ private Pathoschild.Http.Client.IClient _fluentClient;
+
+ #endregion
+
+ #region PROPERTIES
+
+ ///
+ /// The API key provided by CakeMail
+ ///
+ public string ApiKey { get; private set; }
+
+ ///
+ /// The user agent
+ ///
+ public string UserAgent { get; private set; }
+
+ ///
+ /// The URL where all API requests are sent
+ ///
+ public Uri BaseUrl { get; private set; }
+
+ ///
+ /// The Campaigns resource
+ ///
+ public Campaigns Campaigns { get; private set; }
+
+ ///
+ /// The Clients resource
+ ///
+ public Clients Clients { get; private set; }
+
+ ///
+ /// The Countries resource
+ ///
+ public Countries Countries { get; private set; }
+
+ ///
+ /// The Permissions resource
+ ///
+ public Permissions Permissions { get; private set; }
+
+ ///
+ /// The Lists resource
+ ///
+ public Lists Lists { get; private set; }
+
+ ///
+ /// The Timezones resource
+ ///
+ public Timezones Timezones { get; private set; }
+
+ ///
+ /// The Mailings resource
+ ///
+ public Mailings Mailings { get; private set; }
+
+ ///
+ /// The Relays resource
+ ///
+ public Relays Relays { get; private set; }
+
+ ///
+ /// The Segments resource
+ ///
+ public Segments Segments { get; private set; }
+
+ ///
+ /// The Users resource
+ ///
+ public Users Users { get; private set; }
+
+ ///
+ /// The SuppressionLists resource
+ ///
+ public SuppressionLists SuppressionLists { get; private set; }
+
+ ///
+ /// The Templates resource
+ ///
+ public Templates Templates { get; private set; }
+
+ ///
+ /// The Triggers resource
+ ///
+ public Triggers Triggers { get; private set; }
+
+ ///
+ /// Gets the Version.
+ ///
+ ///
+ /// The version.
+ ///
+ public string Version { get; private set; }
+
+ #endregion
+
+ #region CONSTRUCTORS AND DESTRUCTORS
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The API Key received from CakeMail
+ public CakeMailRestClient(string apiKey) : this(apiKey, httpClient: (HttpClient)null) { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The API Key received from CakeMail
+ /// Allows you to specify a proxy
+ public CakeMailRestClient(string apiKey, IWebProxy proxy)
+ : this(apiKey, httpClient: new HttpClient(new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }))
+ {
+ _mustDisposeHttpClient = true;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The API Key received from CakeMail
+ /// The host where the API is hosted. The default is api.wbsrvc.com
+ /// Allows you to inject your own HttpClient. This is useful, for example, to setup the HtppClient with a proxy
+ public CakeMailRestClient(string apiKey, string host = DEFAULT_HOST, HttpClient httpClient = null)
+ {
+ _mustDisposeHttpClient = httpClient == null;
+ _httpClient = httpClient;
+
+ ApiKey = apiKey;
+ BaseUrl = new Uri($"https://{host.TrimEnd('/')}/");
+ Version = typeof(CakeMailRestClient).GetTypeInfo().Assembly.GetName().Version.ToString();
+ UserAgent = $"CakeMail .NET REST Client/{Version} (+https://github.com/Jericho/CakeMail.RestClient)";
+
+ _fluentClient = new FluentClient(this.BaseUrl, httpClient)
+ //.SetHeader("apikey", this.ApiKey)
+ .SetUserAgent(this.UserAgent);
+
+ _fluentClient.BaseClient.DefaultRequestHeaders.Add("apikey", this.ApiKey);
+
+ _fluentClient.Filters.Remove();
+ _fluentClient.Filters.Add(new CakeMailErrorHandler());
+
+ Campaigns = new Campaigns(_fluentClient);
+ Clients = new Clients(_fluentClient);
+ Countries = new Countries(_fluentClient);
+ Permissions = new Permissions(_fluentClient);
+ Lists = new Lists(_fluentClient);
+ Timezones = new Timezones(_fluentClient);
+ Mailings = new Mailings(_fluentClient);
+ Relays = new Relays(_fluentClient);
+ Segments = new Segments(_fluentClient);
+ Users = new Users(_fluentClient);
+ SuppressionLists = new SuppressionLists(_fluentClient);
+ Templates = new Templates(_fluentClient);
+ Triggers = new Triggers(_fluentClient);
+ }
+
+ ///
+ /// Finalizes an instance of the class.
+ ///
+ ~CakeMailRestClient()
+ {
+ // The object went out of scope and finalized is called.
+ // Call 'Dispose' to release unmanaged resources
+ // Managed resources will be released when GC runs the next time.
+ Dispose(false);
+ }
+
+ #endregion
+
+ #region PUBLIC METHODS
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ // Call 'Dispose' to release resources
+ Dispose(true);
+
+ // Tell the GC that we have done the cleanup and there is nothing left for the Finalizer to do
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Releases unmanaged and - optionally - managed resources.
+ ///
+ /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ ReleaseManagedResources();
+ }
+ else
+ {
+ // The object went out of scope and the Finalizer has been called.
+ // The GC will take care of releasing managed resources, therefore there is nothing to do here.
+ }
+
+ ReleaseUnmanagedResources();
+ }
+
+ #endregion
+
+ #region PRIVATE METHODS
+
+ private void ReleaseManagedResources()
+ {
+ if (_fluentClient != null)
+ {
+ _fluentClient.Dispose();
+ _fluentClient = null;
+ }
+
+ if (_httpClient != null && _mustDisposeHttpClient)
+ {
+ _httpClient.Dispose();
+ _httpClient = null;
+ }
+ }
+
+ private void ReleaseUnmanagedResources()
+ {
+ // We do not hold references to unmanaged resources
+ }
+
+ #endregion
+ }
+}
diff --git a/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs
new file mode 100644
index 0000000..91c059e
--- /dev/null
+++ b/Source/CakeMail.RestClient/Exceptions/CakeMailException.cs
@@ -0,0 +1,34 @@
+using System;
+
+namespace CakeMail.RestClient.Exceptions
+{
+ ///
+ /// This class represents a generic CakeMail error. All other exceptions thrown by
+ /// the CakeMail API subclass this exception
+ ///
+#if NETSTANDARD
+ public class CakeMailException : Exception
+#else
+ public class CakeMailException : ApplicationException
+#endif
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// A message that describes the error.
+ public CakeMailException(string message)
+ : base(message)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// A message that describes the error.
+ /// The inner exception.
+ public CakeMailException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/CakeMail.RestClient/Exceptions/CakeMailPostException.cs b/Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs
similarity index 50%
rename from CakeMail.RestClient/Exceptions/CakeMailPostException.cs
rename to Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs
index 5e6f8d9..a712798 100644
--- a/CakeMail.RestClient/Exceptions/CakeMailPostException.cs
+++ b/Source/CakeMail.RestClient/Exceptions/CakeMailPostException.cs
@@ -1,13 +1,10 @@
using System;
-using System.Runtime.Serialization;
-using System.Security.Permissions;
namespace CakeMail.RestClient.Exceptions
{
///
/// This class represents an exception thrown by the CakeMail API when the posted data is determined to be invalid.
///
- [Serializable]
public class CakeMailPostException : CakeMailException
{
///
@@ -37,35 +34,5 @@ public CakeMailPostException(string message, string postData, Exception innerExc
{
this.PostData = postData;
}
-
- ///
- /// Deserialization constructor
- ///
- /// Constructor should be protected for unsealed classes, private for sealed classes.
- /// (The Serializer invokes this constructor through reflection, so it can be private)
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- protected CakeMailPostException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- PostData = info.GetString("PostData");
- }
-
- ///
- /// Populates a SerializationInfo with the data needed to serialize the target object.
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null) throw new ArgumentNullException(nameof(info));
-
- info.AddValue("PostData", this.PostData);
-
- base.GetObjectData(info, context);
- }
}
}
diff --git a/CakeMail.RestClient/Exceptions/HttpException.cs b/Source/CakeMail.RestClient/Exceptions/HttpException.cs
similarity index 51%
rename from CakeMail.RestClient/Exceptions/HttpException.cs
rename to Source/CakeMail.RestClient/Exceptions/HttpException.cs
index f55018d..347744a 100644
--- a/CakeMail.RestClient/Exceptions/HttpException.cs
+++ b/Source/CakeMail.RestClient/Exceptions/HttpException.cs
@@ -1,9 +1,6 @@
using System;
-using System.Globalization;
using System.IO;
using System.Net;
-using System.Runtime.Serialization;
-using System.Security.Permissions;
namespace CakeMail.RestClient.Exceptions
{
@@ -11,16 +8,15 @@ namespace CakeMail.RestClient.Exceptions
/// This class represents an HTTP transport error. This is not an error returned
/// by the web service itself. As such, it is a IOException.
///
- [Serializable]
public class HttpException : IOException
{
///
- /// The HTTP status code returned by the web service.
+ /// Gets the HTTP status code returned by the web service.
///
public HttpStatusCode HttpStatus { get; private set; }
///
- /// The URI queried by the web service.
+ /// Gets the URI queried by the web service.
///
public Uri Uri { get; private set; }
@@ -50,37 +46,5 @@ public HttpException(string message, HttpStatusCode httpStatus, Uri uri, Excepti
HttpStatus = httpStatus;
Uri = uri;
}
-
- ///
- /// Deserialization constructor
- ///
- /// Constructor should be protected for unsealed classes, private for sealed classes.
- /// (The Serializer invokes this constructor through reflection, so it can be private)
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- protected HttpException(SerializationInfo info, StreamingContext context)
- : base(info, context)
- {
- HttpStatus = (HttpStatusCode)info.GetInt32("HttpStatus");
- Uri = new Uri(info.GetString("Uri"));
- }
-
- ///
- /// Populates a SerializationInfo with the data needed to serialize the target object.
- ///
- ///
- ///
- [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
- public override void GetObjectData(SerializationInfo info, StreamingContext context)
- {
- if (info == null) throw new ArgumentNullException(nameof(info));
-
- info.AddValue("HttpStatus", ((int)this.HttpStatus).ToString(CultureInfo.InvariantCulture));
- info.AddValue("Uri", this.Uri.PathAndQuery);
-
- base.GetObjectData(info, context);
- }
}
}
diff --git a/CakeMail.RestClient/ICakeMailRestClient.cs b/Source/CakeMail.RestClient/ICakeMailRestClient.cs
similarity index 63%
rename from CakeMail.RestClient/ICakeMailRestClient.cs
rename to Source/CakeMail.RestClient/ICakeMailRestClient.cs
index 8412833..6cb2d29 100644
--- a/CakeMail.RestClient/ICakeMailRestClient.cs
+++ b/Source/CakeMail.RestClient/ICakeMailRestClient.cs
@@ -1,53 +1,52 @@
-using CakeMail.RestClient.Models;
-using CakeMail.RestClient.Resources;
+using CakeMail.RestClient.Resources;
using System;
-using System.Collections.Generic;
-using System.Net;
namespace CakeMail.RestClient
{
///
/// Provides the base interface for implementation of access to the CakeMail API
///
- interface ICakeMailRestClient
+ public interface ICakeMailRestClient
{
///
- /// The API key provided by CakeMail
+ /// Gets the API key provided by CakeMail
///
string ApiKey { get; }
///
- /// The web proxy
- ///
- IWebProxy Proxy { get; }
-
- ///
- /// The user agent
+ /// Gets the user agent
///
string UserAgent { get; }
///
- /// The timeout
- ///
- int Timeout { get; }
-
- ///
- /// The URL where all API requests are sent
+ /// Gets the URL where all API requests are sent
///
Uri BaseUrl { get; }
Campaigns Campaigns { get; }
+
Clients Clients { get; }
+
Countries Countries { get; }
+
Permissions Permissions { get; }
+
Lists Lists { get; }
+
Timezones Timezones { get; }
+
Mailings Mailings { get; }
+
Relays Relays { get; }
+
Segments Segments { get; }
+
Users Users { get; }
+
SuppressionLists SuppressionLists { get; }
+
Templates Templates { get; }
+
Triggers Triggers { get; }
}
-}
\ No newline at end of file
+}
diff --git a/CakeMail.RestClient/Models/Campaign.cs b/Source/CakeMail.RestClient/Models/Campaign.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Campaign.cs
rename to Source/CakeMail.RestClient/Models/Campaign.cs
diff --git a/CakeMail.RestClient/Models/CampaignStatus.cs b/Source/CakeMail.RestClient/Models/CampaignStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/CampaignStatus.cs
rename to Source/CakeMail.RestClient/Models/CampaignStatus.cs
diff --git a/CakeMail.RestClient/Models/CampaignsSortBy.cs b/Source/CakeMail.RestClient/Models/CampaignsSortBy.cs
similarity index 100%
rename from CakeMail.RestClient/Models/CampaignsSortBy.cs
rename to Source/CakeMail.RestClient/Models/CampaignsSortBy.cs
diff --git a/CakeMail.RestClient/Models/Client.cs b/Source/CakeMail.RestClient/Models/Client.cs
similarity index 98%
rename from CakeMail.RestClient/Models/Client.cs
rename to Source/CakeMail.RestClient/Models/Client.cs
index 7812b8b..8c9cdfd 100644
--- a/CakeMail.RestClient/Models/Client.cs
+++ b/Source/CakeMail.RestClient/Models/Client.cs
@@ -84,6 +84,7 @@ public class Client
public string Key { get; set; }
[JsonProperty("last_activity")]
+ [JsonConverter(typeof(CakeMailDateTimeConverter))]
public DateTime LastActivityOn { get; set; }
[JsonProperty("mailing_limit")]
@@ -185,4 +186,4 @@ public class Client
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/CakeMail.RestClient/Models/ClientRegistrationInfo.cs b/Source/CakeMail.RestClient/Models/ClientRegistrationInfo.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ClientRegistrationInfo.cs
rename to Source/CakeMail.RestClient/Models/ClientRegistrationInfo.cs
diff --git a/CakeMail.RestClient/Models/ClientStatus.cs b/Source/CakeMail.RestClient/Models/ClientStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ClientStatus.cs
rename to Source/CakeMail.RestClient/Models/ClientStatus.cs
diff --git a/CakeMail.RestClient/Models/ClientsSortBy.cs b/Source/CakeMail.RestClient/Models/ClientsSortBy.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ClientsSortBy.cs
rename to Source/CakeMail.RestClient/Models/ClientsSortBy.cs
diff --git a/CakeMail.RestClient/Models/Country.cs b/Source/CakeMail.RestClient/Models/Country.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Country.cs
rename to Source/CakeMail.RestClient/Models/Country.cs
diff --git a/CakeMail.RestClient/Models/FieldType.cs b/Source/CakeMail.RestClient/Models/FieldType.cs
similarity index 100%
rename from CakeMail.RestClient/Models/FieldType.cs
rename to Source/CakeMail.RestClient/Models/FieldType.cs
diff --git a/CakeMail.RestClient/Models/ImportResult.cs b/Source/CakeMail.RestClient/Models/ImportResult.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ImportResult.cs
rename to Source/CakeMail.RestClient/Models/ImportResult.cs
diff --git a/CakeMail.RestClient/Models/Link.cs b/Source/CakeMail.RestClient/Models/Link.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Link.cs
rename to Source/CakeMail.RestClient/Models/Link.cs
diff --git a/CakeMail.RestClient/Models/LinkStats.cs b/Source/CakeMail.RestClient/Models/LinkStats.cs
similarity index 100%
rename from CakeMail.RestClient/Models/LinkStats.cs
rename to Source/CakeMail.RestClient/Models/LinkStats.cs
diff --git a/CakeMail.RestClient/Models/List.cs b/Source/CakeMail.RestClient/Models/List.cs
similarity index 97%
rename from CakeMail.RestClient/Models/List.cs
rename to Source/CakeMail.RestClient/Models/List.cs
index c755cb2..9861d64 100644
--- a/CakeMail.RestClient/Models/List.cs
+++ b/Source/CakeMail.RestClient/Models/List.cs
@@ -5,7 +5,7 @@
namespace CakeMail.RestClient.Models
{
///
- /// A List is a collection of subscribers (or List Members, or Records).
+ /// A List is a collection of subscribers (or List Members, or Records).
/// Each subscriber or List Member is uniquely identified by their email address, and may include an limited amount of Fields containing demographic information associated to each email address.
///
public class List
@@ -86,13 +86,13 @@ public class List
public string oi_url { get; set; }
[JsonProperty("subscribe_url")]
- public string subscribe_url { get; set; }
+ public string SubscribeUrl { get; set; }
[JsonProperty("oo_url")]
public string oo_url { get; set; }
[JsonProperty("webhook")]
- public string webhook { get; set; }
+ public string Webhook { get; set; }
/// This value is calculated when retrieving a list only if the 'calculateEngagement' parameter is set to true. Otherwise this value is null.
[JsonProperty("engagement")]
@@ -128,4 +128,4 @@ public class List
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/CakeMail.RestClient/Models/ListField.cs b/Source/CakeMail.RestClient/Models/ListField.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListField.cs
rename to Source/CakeMail.RestClient/Models/ListField.cs
diff --git a/CakeMail.RestClient/Models/ListMember.cs b/Source/CakeMail.RestClient/Models/ListMember.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListMember.cs
rename to Source/CakeMail.RestClient/Models/ListMember.cs
diff --git a/CakeMail.RestClient/Models/ListMemberStatus.cs b/Source/CakeMail.RestClient/Models/ListMemberStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListMemberStatus.cs
rename to Source/CakeMail.RestClient/Models/ListMemberStatus.cs
diff --git a/CakeMail.RestClient/Models/ListMembersSortBy.cs b/Source/CakeMail.RestClient/Models/ListMembersSortBy.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListMembersSortBy.cs
rename to Source/CakeMail.RestClient/Models/ListMembersSortBy.cs
diff --git a/CakeMail.RestClient/Models/ListStatus.cs b/Source/CakeMail.RestClient/Models/ListStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListStatus.cs
rename to Source/CakeMail.RestClient/Models/ListStatus.cs
diff --git a/CakeMail.RestClient/Models/ListsSortBy.cs b/Source/CakeMail.RestClient/Models/ListsSortBy.cs
similarity index 100%
rename from CakeMail.RestClient/Models/ListsSortBy.cs
rename to Source/CakeMail.RestClient/Models/ListsSortBy.cs
diff --git a/CakeMail.RestClient/Models/LogItem.cs b/Source/CakeMail.RestClient/Models/LogItem.cs
similarity index 100%
rename from CakeMail.RestClient/Models/LogItem.cs
rename to Source/CakeMail.RestClient/Models/LogItem.cs
diff --git a/CakeMail.RestClient/Models/LogType.cs b/Source/CakeMail.RestClient/Models/LogType.cs
similarity index 100%
rename from CakeMail.RestClient/Models/LogType.cs
rename to Source/CakeMail.RestClient/Models/LogType.cs
diff --git a/CakeMail.RestClient/Models/LoginInfo.cs b/Source/CakeMail.RestClient/Models/LoginInfo.cs
similarity index 100%
rename from CakeMail.RestClient/Models/LoginInfo.cs
rename to Source/CakeMail.RestClient/Models/LoginInfo.cs
diff --git a/CakeMail.RestClient/Models/Mailing.cs b/Source/CakeMail.RestClient/Models/Mailing.cs
similarity index 99%
rename from CakeMail.RestClient/Models/Mailing.cs
rename to Source/CakeMail.RestClient/Models/Mailing.cs
index fa230c5..6cf6c2a 100644
--- a/CakeMail.RestClient/Models/Mailing.cs
+++ b/Source/CakeMail.RestClient/Models/Mailing.cs
@@ -176,8 +176,8 @@ public class Mailing
public long UniqueOpens { get; set; }
[JsonProperty("unsubscribes")]
- public int? unsubscribes { get; set; }
+ public int? Unsubscribes { get; set; }
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/CakeMail.RestClient/Models/MailingStatus.cs b/Source/CakeMail.RestClient/Models/MailingStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/MailingStatus.cs
rename to Source/CakeMail.RestClient/Models/MailingStatus.cs
diff --git a/CakeMail.RestClient/Models/MailingType.cs b/Source/CakeMail.RestClient/Models/MailingType.cs
similarity index 100%
rename from CakeMail.RestClient/Models/MailingType.cs
rename to Source/CakeMail.RestClient/Models/MailingType.cs
diff --git a/CakeMail.RestClient/Models/MailingsSortBy.cs b/Source/CakeMail.RestClient/Models/MailingsSortBy.cs
similarity index 100%
rename from CakeMail.RestClient/Models/MailingsSortBy.cs
rename to Source/CakeMail.RestClient/Models/MailingsSortBy.cs
diff --git a/CakeMail.RestClient/Models/MessageEncoding.cs b/Source/CakeMail.RestClient/Models/MessageEncoding.cs
similarity index 100%
rename from CakeMail.RestClient/Models/MessageEncoding.cs
rename to Source/CakeMail.RestClient/Models/MessageEncoding.cs
diff --git a/CakeMail.RestClient/Models/Province.cs b/Source/CakeMail.RestClient/Models/Province.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Province.cs
rename to Source/CakeMail.RestClient/Models/Province.cs
diff --git a/CakeMail.RestClient/Models/RawEmailMessage.cs b/Source/CakeMail.RestClient/Models/RawEmailMessage.cs
similarity index 100%
rename from CakeMail.RestClient/Models/RawEmailMessage.cs
rename to Source/CakeMail.RestClient/Models/RawEmailMessage.cs
diff --git a/CakeMail.RestClient/Models/RelayBounceLog.cs b/Source/CakeMail.RestClient/Models/RelayBounceLog.cs
similarity index 100%
rename from CakeMail.RestClient/Models/RelayBounceLog.cs
rename to Source/CakeMail.RestClient/Models/RelayBounceLog.cs
diff --git a/CakeMail.RestClient/Models/RelayClickLog.cs b/Source/CakeMail.RestClient/Models/RelayClickLog.cs
similarity index 100%
rename from CakeMail.RestClient/Models/RelayClickLog.cs
rename to Source/CakeMail.RestClient/Models/RelayClickLog.cs
diff --git a/CakeMail.RestClient/Models/RelayLog.cs b/Source/CakeMail.RestClient/Models/RelayLog.cs
similarity index 100%
rename from CakeMail.RestClient/Models/RelayLog.cs
rename to Source/CakeMail.RestClient/Models/RelayLog.cs
diff --git a/CakeMail.RestClient/Models/RelayOpenLog.cs b/Source/CakeMail.RestClient/Models/RelayOpenLog.cs
similarity index 100%
rename from CakeMail.RestClient/Models/RelayOpenLog.cs
rename to Source/CakeMail.RestClient/Models/RelayOpenLog.cs
diff --git a/CakeMail.RestClient/Models/Segment.cs b/Source/CakeMail.RestClient/Models/Segment.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Segment.cs
rename to Source/CakeMail.RestClient/Models/Segment.cs
diff --git a/CakeMail.RestClient/Models/SortDirection.cs b/Source/CakeMail.RestClient/Models/SortDirection.cs
similarity index 100%
rename from CakeMail.RestClient/Models/SortDirection.cs
rename to Source/CakeMail.RestClient/Models/SortDirection.cs
diff --git a/CakeMail.RestClient/Models/SuppressDomainResult.cs b/Source/CakeMail.RestClient/Models/SuppressDomainResult.cs
similarity index 100%
rename from CakeMail.RestClient/Models/SuppressDomainResult.cs
rename to Source/CakeMail.RestClient/Models/SuppressDomainResult.cs
diff --git a/CakeMail.RestClient/Models/SuppressEmailResult.cs b/Source/CakeMail.RestClient/Models/SuppressEmailResult.cs
similarity index 100%
rename from CakeMail.RestClient/Models/SuppressEmailResult.cs
rename to Source/CakeMail.RestClient/Models/SuppressEmailResult.cs
diff --git a/CakeMail.RestClient/Models/SuppressLocalPartResult.cs b/Source/CakeMail.RestClient/Models/SuppressLocalPartResult.cs
similarity index 100%
rename from CakeMail.RestClient/Models/SuppressLocalPartResult.cs
rename to Source/CakeMail.RestClient/Models/SuppressLocalPartResult.cs
diff --git a/CakeMail.RestClient/Models/SuppressedEmail.cs b/Source/CakeMail.RestClient/Models/SuppressedEmail.cs
similarity index 100%
rename from CakeMail.RestClient/Models/SuppressedEmail.cs
rename to Source/CakeMail.RestClient/Models/SuppressedEmail.cs
diff --git a/CakeMail.RestClient/Models/Template.cs b/Source/CakeMail.RestClient/Models/Template.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Template.cs
rename to Source/CakeMail.RestClient/Models/Template.cs
diff --git a/CakeMail.RestClient/Models/TemplateCategory.cs b/Source/CakeMail.RestClient/Models/TemplateCategory.cs
similarity index 100%
rename from CakeMail.RestClient/Models/TemplateCategory.cs
rename to Source/CakeMail.RestClient/Models/TemplateCategory.cs
diff --git a/CakeMail.RestClient/Models/TemplateCategoryVisibility.cs b/Source/CakeMail.RestClient/Models/TemplateCategoryVisibility.cs
similarity index 100%
rename from CakeMail.RestClient/Models/TemplateCategoryVisibility.cs
rename to Source/CakeMail.RestClient/Models/TemplateCategoryVisibility.cs
diff --git a/CakeMail.RestClient/Models/Timezone.cs b/Source/CakeMail.RestClient/Models/Timezone.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Timezone.cs
rename to Source/CakeMail.RestClient/Models/Timezone.cs
diff --git a/CakeMail.RestClient/Models/TransferEncoding.cs b/Source/CakeMail.RestClient/Models/TransferEncoding.cs
similarity index 100%
rename from CakeMail.RestClient/Models/TransferEncoding.cs
rename to Source/CakeMail.RestClient/Models/TransferEncoding.cs
diff --git a/CakeMail.RestClient/Models/Trigger.cs b/Source/CakeMail.RestClient/Models/Trigger.cs
similarity index 100%
rename from CakeMail.RestClient/Models/Trigger.cs
rename to Source/CakeMail.RestClient/Models/Trigger.cs
diff --git a/CakeMail.RestClient/Models/TriggerAction.cs b/Source/CakeMail.RestClient/Models/TriggerAction.cs
similarity index 100%
rename from CakeMail.RestClient/Models/TriggerAction.cs
rename to Source/CakeMail.RestClient/Models/TriggerAction.cs
diff --git a/CakeMail.RestClient/Models/TriggerStatus.cs b/Source/CakeMail.RestClient/Models/TriggerStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/TriggerStatus.cs
rename to Source/CakeMail.RestClient/Models/TriggerStatus.cs
diff --git a/CakeMail.RestClient/Models/UnConfirmedClient.cs b/Source/CakeMail.RestClient/Models/UnConfirmedClient.cs
similarity index 100%
rename from CakeMail.RestClient/Models/UnConfirmedClient.cs
rename to Source/CakeMail.RestClient/Models/UnConfirmedClient.cs
diff --git a/CakeMail.RestClient/Models/User.cs b/Source/CakeMail.RestClient/Models/User.cs
similarity index 95%
rename from CakeMail.RestClient/Models/User.cs
rename to Source/CakeMail.RestClient/Models/User.cs
index 6dda299..fe1e4cb 100644
--- a/CakeMail.RestClient/Models/User.cs
+++ b/Source/CakeMail.RestClient/Models/User.cs
@@ -54,7 +54,7 @@ public class User
public string Timezone { get; set; }
[JsonProperty("timezone_id")]
- public long timezone_id { get; set; }
+ public long TimezoneId { get; set; }
[JsonProperty("office_phone")]
public string OfficePhone { get; set; }
@@ -75,8 +75,8 @@ public class User
public string CPanel { get; set; }
[JsonProperty("permissions")]
- public string[] permissions { get; set; }
+ public string[] Permissions { get; set; }
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/CakeMail.RestClient/Models/UserStatus.cs b/Source/CakeMail.RestClient/Models/UserStatus.cs
similarity index 100%
rename from CakeMail.RestClient/Models/UserStatus.cs
rename to Source/CakeMail.RestClient/Models/UserStatus.cs
diff --git a/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..8148e57
--- /dev/null
+++ b/Source/CakeMail.RestClient/Properties/AssemblyInfo.cs
@@ -0,0 +1,29 @@
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("CakeMail.RestClient")]
+[assembly: AssemblyDescription("CakeMail.RestClient is a .NET wrapper for the CakeMail API")]
+[assembly: AssemblyCompany("Jeremie Desautels")]
+[assembly: AssemblyProduct("CakeMail.RestClient")]
+[assembly: AssemblyCopyright("Copyright Jeremie Desautels © 2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Make it easy to distinguish Debug and Release builds;
+#if DEBUG
+[assembly: AssemblyConfiguration("Debug")]
+#else
+[assembly: AssemblyConfiguration("Release")]
+#endif
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("DDCD8C73-3E02-45CC-958F-1E0383D6EB91")]
+
diff --git a/CakeMail.RestClient/Resources/Campaigns.cs b/Source/CakeMail.RestClient/Resources/Campaigns.cs
similarity index 80%
rename from CakeMail.RestClient/Resources/Campaigns.cs
rename to Source/CakeMail.RestClient/Resources/Campaigns.cs
index 03e4987..f5d13a6 100644
--- a/CakeMail.RestClient/Resources/Campaigns.cs
+++ b/Source/CakeMail.RestClient/Resources/Campaigns.cs
@@ -1,6 +1,8 @@
using CakeMail.RestClient.Models;
using CakeMail.RestClient.Utilities;
+using Pathoschild.Http.Client;
using System.Collections.Generic;
+using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
@@ -10,15 +12,19 @@ public class Campaigns
{
#region Fields
- private readonly CakeMailRestClient _cakeMailRestClient;
+ private readonly IClient _client;
#endregion
#region Constructor
- public Campaigns(CakeMailRestClient cakeMailRestClient)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The HTTP client
+ public Campaigns(IClient client)
{
- _cakeMailRestClient = cakeMailRestClient;
+ _client = client;
}
#endregion
@@ -35,8 +41,6 @@ public Campaigns(CakeMailRestClient cakeMailRestClient)
/// ID of the new campaign
public Task CreateAsync(string userKey, string name, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Campaign/Create/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -44,7 +48,11 @@ public Task CreateAsync(string userKey, string name, long? clientId = null
};
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Campaign/Create")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -57,8 +65,6 @@ public Task CreateAsync(string userKey, string name, long? clientId = null
/// True if the campaign is deleted
public Task DeleteAsync(string userKey, long campaignId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Campaign/Delete/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -66,7 +72,11 @@ public Task DeleteAsync(string userKey, long campaignId, long? clientId =
};
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Campaign/Delete")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -79,8 +89,6 @@ public Task DeleteAsync(string userKey, long campaignId, long? clientId =
/// The campaign
public Task GetAsync(string userKey, long campaignId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Campaign/GetInfo/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -88,7 +96,11 @@ public Task GetAsync(string userKey, long campaignId, long? clientId =
};
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Campaign/GetInfo")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -103,11 +115,9 @@ public Task GetAsync(string userKey, long campaignId, long? clientId =
/// Offset the beginning of resulting campaigns.
/// Client ID of the client in which the campaign is located.
/// The cancellation token
- /// Enumeration of campaigns matching the filtering criteria
- public Task> GetListAsync(string userKey, CampaignStatus? status = null, string name = null, CampaignsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
+ /// Array of campaigns matching the filtering criteria
+ public Task GetListAsync(string userKey, CampaignStatus? status = null, string name = null, CampaignsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Campaign/GetList/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -121,7 +131,11 @@ public Task> GetListAsync(string userKey, CampaignStatus?
if (offset > 0) parameters.Add(new KeyValuePair("offset", offset));
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "campaigns", cancellationToken);
+ return _client
+ .PostAsync("Campaign/GetList")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("campaigns");
}
///
@@ -135,7 +149,6 @@ public Task> GetListAsync(string userKey, CampaignStatus?
/// The count of campaigns matching the filtering criteria
public Task GetCountAsync(string userKey, CampaignStatus? status = null, string name = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Campaign/GetList/";
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -145,7 +158,11 @@ public Task GetCountAsync(string userKey, CampaignStatus? status = null, s
if (name != null) parameters.Add(new KeyValuePair("name", name));
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken);
+ return _client
+ .PostAsync("Campaign/GetList")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("count");
}
///
@@ -159,8 +176,6 @@ public Task GetCountAsync(string userKey, CampaignStatus? status = null, s
/// True if the record was updated.
public Task UpdateAsync(string userKey, long campaignId, string name, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Campaign/SetInfo/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -169,7 +184,11 @@ public Task UpdateAsync(string userKey, long campaignId, string name, long
};
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Campaign/SetInfo")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
#endregion
diff --git a/CakeMail.RestClient/Resources/Clients.cs b/Source/CakeMail.RestClient/Resources/Clients.cs
similarity index 92%
rename from CakeMail.RestClient/Resources/Clients.cs
rename to Source/CakeMail.RestClient/Resources/Clients.cs
index bfe84ce..9b36596 100644
--- a/CakeMail.RestClient/Resources/Clients.cs
+++ b/Source/CakeMail.RestClient/Resources/Clients.cs
@@ -1,5 +1,6 @@
using CakeMail.RestClient.Models;
using CakeMail.RestClient.Utilities;
+using Pathoschild.Http.Client;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -11,15 +12,19 @@ public class Clients
{
#region Fields
- private readonly CakeMailRestClient _cakeMailRestClient;
+ private readonly IClient _client;
#endregion
#region Constructor
- public Clients(CakeMailRestClient cakeMailRestClient)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The HTTP client
+ public Clients(IClient client)
{
- _cakeMailRestClient = cakeMailRestClient;
+ _client = client;
}
#endregion
@@ -63,8 +68,6 @@ public Clients(CakeMailRestClient cakeMailRestClient)
/// A confirmation code which must be used subsequently to 'activate' the client
public Task CreateAsync(long parentId, string name, string address1 = null, string address2 = null, string city = null, string provinceId = null, string postalCode = null, string countryId = null, string website = null, string phone = null, string fax = null, string adminEmail = null, string adminFirstName = null, string adminLastName = null, string adminTitle = null, string adminOfficePhone = null, string adminMobilePhone = null, string adminLanguage = null, long? adminTimezoneId = null, string adminPassword = null, bool primaryContactSameAsAdmin = true, string primaryContactEmail = null, string primaryContactFirstName = null, string primaryContactLastName = null, string primaryContactTitle = null, string primaryContactOfficePhone = null, string primaryContactMobilePhone = null, string primaryContactLanguage = null, long? primaryContactTimezoneId = null, string primaryContactPassword = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Client/Create/";
-
var parameters = new List>
{
new KeyValuePair("parent_id", parentId),
@@ -86,16 +89,16 @@ public Task CreateAsync(long parentId, string name, string address1 = nu
if (adminEmail != null) parameters.Add(new KeyValuePair("admin_email", adminEmail));
if (adminFirstName != null) parameters.Add(new KeyValuePair("admin_first_name", adminFirstName));
if (adminLastName != null) parameters.Add(new KeyValuePair("admin_last_name", adminLastName));
- if (adminPassword != null)
- {
- parameters.Add(new KeyValuePair("admin_password", adminPassword));
- parameters.Add(new KeyValuePair("admin_password_confirmation", adminPassword));
- }
if (adminTitle != null) parameters.Add(new KeyValuePair("admin_title", adminTitle));
if (adminOfficePhone != null) parameters.Add(new KeyValuePair("admin_office_phone", adminOfficePhone));
if (adminMobilePhone != null) parameters.Add(new KeyValuePair("admin_mobile_phone", adminMobilePhone));
if (adminLanguage != null) parameters.Add(new KeyValuePair("admin_language", adminLanguage));
if (adminTimezoneId.HasValue) parameters.Add(new KeyValuePair("admin_timezone_id", adminTimezoneId.Value));
+ if (adminPassword != null)
+ {
+ parameters.Add(new KeyValuePair("admin_password", adminPassword));
+ parameters.Add(new KeyValuePair("admin_password_confirmation", adminPassword));
+ }
// Contact
parameters.Add(new KeyValuePair("contact_same_as_admin", primaryContactSameAsAdmin ? "1" : "0"));
@@ -104,19 +107,23 @@ public Task CreateAsync(long parentId, string name, string address1 = nu
if (primaryContactEmail != null) parameters.Add(new KeyValuePair("contact_email", primaryContactEmail));
if (primaryContactFirstName != null) parameters.Add(new KeyValuePair("contact_first_name", primaryContactFirstName));
if (primaryContactLastName != null) parameters.Add(new KeyValuePair("contact_last_name", primaryContactLastName));
- if (primaryContactPassword != null)
- {
- parameters.Add(new KeyValuePair("contact_password", primaryContactPassword));
- parameters.Add(new KeyValuePair("contact_password_confirmation", primaryContactPassword));
- }
if (primaryContactTitle != null) parameters.Add(new KeyValuePair("contact_title", primaryContactTitle));
if (primaryContactLanguage != null) parameters.Add(new KeyValuePair("contact_language", primaryContactLanguage));
if (primaryContactTimezoneId.HasValue) parameters.Add(new KeyValuePair("contact_timezone_id", primaryContactTimezoneId.Value));
if (primaryContactOfficePhone != null) parameters.Add(new KeyValuePair("contact_office_phone", primaryContactOfficePhone));
if (primaryContactMobilePhone != null) parameters.Add(new KeyValuePair("contact_mobile_phone", primaryContactMobilePhone));
+ if (primaryContactPassword != null)
+ {
+ parameters.Add(new KeyValuePair("contact_password", primaryContactPassword));
+ parameters.Add(new KeyValuePair("contact_password_confirmation", primaryContactPassword));
+ }
}
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Client/Create")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -127,14 +134,16 @@ public Task CreateAsync(long parentId, string name, string address1 = nu
/// Information about the activated client
public Task ConfirmAsync(string confirmationCode, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Client/Activate/";
-
var parameters = new List>
{
new KeyValuePair("confirmation", confirmationCode)
};
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Client/Activate")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -148,8 +157,6 @@ public Task ConfirmAsync(string confirmationCode, Cancel
/// The client
public Task GetAsync(string userKey, long clientId, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Client/GetInfo/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -158,7 +165,11 @@ public Task GetAsync(string userKey, long clientId, DateTime? startDate
if (startDate.HasValue) parameters.Add(new KeyValuePair("start_date", startDate.Value.ToCakeMailString()));
if (endDate.HasValue) parameters.Add(new KeyValuePair("end_date", endDate.Value.ToCakeMailString()));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Client/GetInfo")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -171,15 +182,17 @@ public Task GetAsync(string userKey, long clientId, DateTime? startDate
/// Pending clients must be activated before they can start using the CakeMail service.
public Task GetAsync(string userKey, string confirmationCode, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Client/GetInfo/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
new KeyValuePair("confirmation", confirmationCode)
};
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Client/GetInfo")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -195,10 +208,8 @@ public Task GetAsync(string userKey, string confirmationCode,
/// ID of the client.
/// The cancellation token
/// Enumeration of clients matching the filtering criteria
- public Task> GetListAsync(string userKey, ClientStatus? status = null, string name = null, ClientsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
+ public Task GetListAsync(string userKey, ClientStatus? status = null, string name = null, ClientsSortBy? sortBy = null, SortDirection? sortDirection = null, int? limit = 0, int? offset = 0, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Client/GetList/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -212,7 +223,11 @@ public Task> GetListAsync(string userKey, ClientStatus? stat
if (offset > 0) parameters.Add(new KeyValuePair("offset", offset));
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "clients", cancellationToken);
+ return _client
+ .PostAsync("Client/GetList")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("clients");
}
///
@@ -226,7 +241,6 @@ public Task> GetListAsync(string userKey, ClientStatus? stat
/// The number of clients matching the filtering criteria
public Task GetCountAsync(string userKey, ClientStatus? status = null, string name = null, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Client/GetList/";
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -236,7 +250,11 @@ public Task GetCountAsync(string userKey, ClientStatus? status = null, str
if (name != null) parameters.Add(new KeyValuePair("company_name", name));
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteCountRequestAsync(path, parameters, cancellationToken);
+ return _client
+ .PostAsync("Client/GetList")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("count");
}
///
@@ -277,8 +295,6 @@ public Task GetCountAsync(string userKey, ClientStatus? status = null, str
/// True if the record was updated.
public Task UpdateAsync(string userKey, long clientId, string name = null, ClientStatus? status = null, long? parentId = null, string address1 = null, string address2 = null, string city = null, string provinceId = null, string postalCode = null, string countryId = null, string website = null, string phone = null, string fax = null, string authDomain = null, string bounceDomain = null, string dkimDomain = null, string doptinIp = null, string forwardDomain = null, string forwardIp = null, string ipPool = null, string mdDomain = null, bool? isReseller = null, string currency = null, string planType = null, int? mailingLimit = null, int? monthLimit = null, int? contactLimit = null, int? defaultMailingLimit = null, int? defaultMonthLimit = null, int? defaultContactLimit = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/Client/SetInfo/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -314,7 +330,11 @@ public Task UpdateAsync(string userKey, long clientId, string name = null,
if (defaultMonthLimit.HasValue) parameters.Add(new KeyValuePair("default_month_limit", defaultMonthLimit.Value));
if (defaultContactLimit.HasValue) parameters.Add(new KeyValuePair("default_contact_limit", defaultContactLimit.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("Client/SetInfo")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
diff --git a/CakeMail.RestClient/Resources/Countries.cs b/Source/CakeMail.RestClient/Resources/Countries.cs
similarity index 57%
rename from CakeMail.RestClient/Resources/Countries.cs
rename to Source/CakeMail.RestClient/Resources/Countries.cs
index 97b54b1..8b2eef8 100644
--- a/CakeMail.RestClient/Resources/Countries.cs
+++ b/Source/CakeMail.RestClient/Resources/Countries.cs
@@ -1,4 +1,6 @@
using CakeMail.RestClient.Models;
+using CakeMail.RestClient.Utilities;
+using Pathoschild.Http.Client;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@@ -9,15 +11,15 @@ public class Countries
{
#region Fields
- private readonly CakeMailRestClient _cakeMailRestClient;
+ private readonly IClient _client;
#endregion
#region Constructor
- public Countries(CakeMailRestClient cakeMailRestClient)
+ public Countries(IClient client)
{
- _cakeMailRestClient = cakeMailRestClient;
+ _client = client;
}
#endregion
@@ -29,11 +31,12 @@ public Countries(CakeMailRestClient cakeMailRestClient)
///
/// The cancellation token
/// An enumeration of countries
- public Task> GetListAsync(CancellationToken cancellationToken = default(CancellationToken))
+ public Task GetListAsync(CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Country/GetList/";
-
- return _cakeMailRestClient.ExecuteArrayRequestAsync(path, null, "countries", cancellationToken);
+ return _client
+ .PostAsync("Country/GetList")
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("countries");
}
///
@@ -42,16 +45,18 @@ public Task> GetListAsync(CancellationToken cancellationTok
/// ID of the country.
/// The cancellation token
/// An enumeration of privinces
- public Task> GetProvincesAsync(string countryId, CancellationToken cancellationToken = default(CancellationToken))
+ public Task GetProvincesAsync(string countryId, CancellationToken cancellationToken = default(CancellationToken))
{
- var path = "/Country/GetProvinces/";
-
var parameters = new List>
{
new KeyValuePair("country_id", countryId)
};
- return _cakeMailRestClient.ExecuteArrayRequestAsync(path, parameters, "provinces", cancellationToken);
+ return _client
+ .PostAsync("Country/GetProvinces")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject("provinces");
}
#endregion
diff --git a/CakeMail.RestClient/Resources/Lists.cs b/Source/CakeMail.RestClient/Resources/Lists.cs
similarity index 84%
rename from CakeMail.RestClient/Resources/Lists.cs
rename to Source/CakeMail.RestClient/Resources/Lists.cs
index e2ca92b..4584f41 100644
--- a/CakeMail.RestClient/Resources/Lists.cs
+++ b/Source/CakeMail.RestClient/Resources/Lists.cs
@@ -1,5 +1,6 @@
using CakeMail.RestClient.Models;
using CakeMail.RestClient.Utilities;
+using Pathoschild.Http.Client;
using System;
using System.Collections.Generic;
using System.Dynamic;
@@ -13,15 +14,15 @@ public class Lists
{
#region Fields
- private readonly CakeMailRestClient _cakeMailRestClient;
+ private readonly IClient _client;
#endregion
#region Constructor
- public Lists(CakeMailRestClient cakeMailRestClient)
+ public Lists(IClient client)
{
- _cakeMailRestClient = cakeMailRestClient;
+ _client = client;
}
#endregion
@@ -41,8 +42,6 @@ public Lists(CakeMailRestClient cakeMailRestClient)
/// ID of the new list
public Task CreateAsync(string userKey, string name, string defaultSenderName, string defaultSenderEmailAddress, bool spamPolicyAccepted = false, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/List/Create/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -53,7 +52,11 @@ public Task CreateAsync(string userKey, string name, string defaultSenderN
if (spamPolicyAccepted) parameters.Add(new KeyValuePair("list_policy", "accepted"));
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("List/Create")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -66,8 +69,6 @@ public Task CreateAsync(string userKey, string name, string defaultSenderN
/// True if the list is deleted
public Task DeleteAsync(string userKey, long listId, long? clientId = null, CancellationToken cancellationToken = default(CancellationToken))
{
- string path = "/List/Delete/";
-
var parameters = new List>
{
new KeyValuePair("user_key", userKey),
@@ -75,7 +76,11 @@ public Task DeleteAsync(string userKey, long listId, long? clientId = null
};
if (clientId.HasValue) parameters.Add(new KeyValuePair("client_id", clientId.Value));
- return _cakeMailRestClient.ExecuteRequestAsync(path, parameters, null, cancellationToken);
+ return _client
+ .PostAsync("List/Delete")
+ .WithFormUrlEncodedBody(parameters)
+ .WithCancellationToken(cancellationToken)
+ .AsCakeMailObject();
}
///
@@ -90,8 +95,6 @@ public Task DeleteAsync(string userKey, long listId, long? clientId = null
///